7

man 7 unix on Linux states:

In the Linux implementation, sockets which are visible in the file system honor the permissions of the directory they are in. Their owner, group and their permissions can be changed. Creation of a new socket will fail if the process does not have write and search (execute) permission on the directory the socket is created in. Connecting to the socket object requires read/write permission. This behavior differs from many BSD-derived systems which ignore permissions for UNIX domain sockets. Portable programs should not rely on this feature for security.

Which systems ignore permissions for UNIX domain sockets?

2 Answers 2

5

HP-UX for example ignores permissions on the socket file.

Note that the docs are talking about permissions on the socket file. All implementations respect permissions on the parent directories - a portable program must make sockets in a private directory, rather than rely on making sockets with restrictive permissions (via umask) in a public directory.

1

Not sure what they mean given that

  • sockets originated in BSDs and in 4.3BSD, the documentation clearly specifies that write permission is required for a connect().
  • On Linux as well, read permission is not required, only write.

POSIX doesn't seem to require the connect() to fail if the socket file is not writeable, but explicitly allows it (connect may fail [...] if the named socket is not writeable). That "may" suggests there may be indeed systems that don't honour the permissions, but I doubt they would be BSD derived.

4
  • 2
    I notice that the POSIX specification has it under "may fail", not "shall fail", which suggests that the intent was to allow the implementation to go either way. Weirdly, the "search permission on directory" part is there too, and I can't imagine those permissions not being checked, ever.
    – user41515
    Jul 15, 2013 at 10:49
  • @WumpusQ.Wumbley, you're right, answer edited accordingly. Jul 15, 2013 at 11:15
  • 4
    Also, after looking through some old code at minnie.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/… it looks like 4.2BSD had a connect without permission check. Compare to the 4.3BSD code which does an access(ip, IWRITE) in unp_connect. So maybe "many BSD-derived systems" actually means "the few unlucky 4.2BSD survivors". Even in 4.2BSD, the directory permissions would of course be checked by the namei.
    – user41515
    Jul 15, 2013 at 11:16
  • @WumpusQ.Wumbley, good finding which makes my answer probably irrelevant/incorrect since a few systems branched off BSD before 4.3 Jul 15, 2013 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .