Project

General

Profile

Bug #1056

ksocket doesn't support AF_UNIX

Added by Stepan Zastupov over 8 years ago. Updated almost 8 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
kernel
Start date:
2011-05-20
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

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?


Files

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

History

#1

Updated by Gordon Ross over 8 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.

#2

Updated by Stepan Zastupov over 8 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.

#3

Updated by Rich Lowe over 8 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.

#4

Updated by Stepan Zastupov almost 8 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 :)

#5

Updated by Gordon Ross almost 8 years ago

  • Status changed from Feedback to Resolved
changeset:   13477:3d8bcfed4059
tag:         tip
user:        Stepan Zastupov <stepan.zastupov@gmail.com>
date:        Sun Oct 02 23:44:03 2011 +0400
description:
    1056 ksocket doesn't support AF_UNIX
    Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
    Reviewed by: Garrett D'Amore <garrett.damore@gmail.com>
    Approved by: Eric Schrock <eric.schrock@delphix.com>

Also available in: Atom PDF