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?


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.


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.

  • 1
    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. – Wumpus Q. Wumbley Jul 15 '13 at 10:49
  • @WumpusQ.Wumbley, you're right, answer edited accordingly. – Stéphane Chazelas Jul 15 '13 at 11:15
  • 3
    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. – Wumpus Q. Wumbley Jul 15 '13 at 11:16
  • @WumpusQ.Wumbley, good finding which makes my answer probably irrelevant/incorrect since a few systems branched off BSD before 4.3 – Stéphane Chazelas Jul 15 '13 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.