Bug #1056


ksocket doesn't support AF_UNIX

Added by Stepan Zastupov about 11 years ago. Updated almost 11 years ago.

Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


ksocket_socket() doesn't accept AF_UNIX and AF_NCA domains. I removed the check for AF_UNIX and wrote a simple echo client which speaks with user space server. It seems to work fine so I wonder, why AF_UNIX wasn't supported? Is there a known problem or just lack of testing?


ksocket.patch (782 Bytes) ksocket.patch Stepan Zastupov, 2011-06-10 05:19 PM
echo_server.c (1.69 KB) echo_server.c Stepan Zastupov, 2011-06-10 05:19 PM
ksocket_unix.patch (5.25 KB) ksocket_unix.patch Stepan Zastupov, 2011-09-30 01:58 PM
Actions #1

Updated by Gordon Ross about 11 years ago

I'm pretty sure this was just paranoia, given that there were
no current consumers using the AF_UNIX code paths.

We need it to work now, to support another project we have
underway, but don't want to go public with just yet.

Actions #2

Updated by Stepan Zastupov about 11 years ago

I attached the patch and a user-space echo server for testing. I have no kernel example but it works fine from my experience.

Actions #3

Updated by Rich Lowe about 11 years ago

Perhaps Dan has some memory of why this is?

Does a change such as this require any extra protection in the face of zones? (to prevent someone in the context of zone A communicating with a socket in zone B?). A wild guess based on the choice of disallowed sockets.

Actions #4

Updated by Stepan Zastupov almost 11 years ago

After some time spent working with ksocket I realized that AF_UNIX wasn't supported by reason.
AF_UNIX support is implemented in socktpi.c of sockfs module and socktpi has some issues:
  • socktpi doesn't use much of sockfs infrastructure like upcalls/downcalls which are capable of calling ksocket callbacks. Therefore, ksocket callbacks won't be ever called with AF_UNIX.
  • socktpi can work in different modes (SOV_STREAM, SOV_SOCKSTREAM, SOV_SOCKBSD, etc...). Syscalls use SOV_SOCKBSD while ksocket uses SOV_DEFAULT (which is basically SOV_STREAM). So when socktpi works in SOV_STREAM mode it passes most of the calls directly to STREAMS. STREAMS assumes that the upper layer takes care of some ioctls (like FIONBIO). The problem is that socktpi doesn't handle FIONBIO for SOV_STREAM either. So basically, you can't turn socktpi ksocket to non-blocking mode.
  • Message headers (of sendmsg()) are ignored for SOV_STREAM.

Probably the best solution would be to rewrite AF_UNIX using sockfs infrastructure but it's quite a lot of work. So the patch only removes check for AF_UNIX and adds workaround for the lack of the support for ksocket callbacks. ksocket_spoll() uses poll() infrastructure which is quite hairy, it allocates poll data structures on every call and it's overall ugly but it solves the problem. Feel free to propose a better solution without rewriting socktpi :)

Actions #5

Updated by Gordon Ross almost 11 years ago

  • Status changed from Feedback to Resolved
changeset:   13477:3d8bcfed4059
tag:         tip
user:        Stepan Zastupov <>
date:        Sun Oct 02 23:44:03 2011 +0400
    1056 ksocket doesn't support AF_UNIX
    Reviewed by: Gordon Ross <>
    Reviewed by: Garrett D'Amore <>
    Approved by: Eric Schrock <>

Also available in: Atom PDF