8

By my experience unprivileged user can not access unix socket he/she does not own without x bit set. What does this bit do exactly? Thanks

  • Is it the permission on the sockets or on the directory? – Rui F Ribeiro Jun 28 '18 at 11:48
  • On a socket. Directory has mode 0755, so user can observe content. Socket has mode 0644, so logically user (which belongs to "others" because he/she does not own socket a belongs to group owning socket) should be able to write to the socket. But user gets permission deny message unless mode 0777 is applied to the socket. – Владимир Тюхтин Jun 29 '18 at 14:03
  • 2
    @ВладимирТюхтин, 0644 means just read permission for the group members and "others", so only the owner would be able to access the socket (since the write permission controls it). 0666, or just 0222 as read permission is not needed, would be enough to give access to everyone. But, rather than give permissions to everyone, I'd look into using groups to allow access. – ilkkachu Jul 4 '18 at 10:57
8

Nothing, as I can see.

The Linux man page unix(7) says that the permissions of the directory containing a socket apply normally (i.e. you need +x on /foo to connect to /foo/sock, and +w on /foo to create /foo/sock) and that write permission controls connecting to the socket itself:

On Linux, connecting to a stream socket object requires write permission on that socket; sending a datagram to a datagram socket likewise requires write permission on that socket.

Apparently some other systems behave differently:

POSIX does not make any statement about the effect of the permissions on a socket file, and on some systems (e.g., older BSDs), the socket permissions are ignored. Portable programs should not rely on this feature for security.

unix(4) on FreeBSD describes similar requirements. The Linux man page didn't say if socket access on some systems ignores the directory permissions too.

Removing the x bit from the socket seems to have the effect of giving a different error for trying execute the socket, but that's not much of a practical difference:

$ ls -l test.sock
srwxr-xr-x 1 user user 0 Jun 28 16:24 test.sock=
$ nc -U ./test.sock
Hello
$ ./test.sock
bash: ./test.sock: No such device or address
$ chmod a-x test.sock
$ nc -U ./test.sock
Hello
$ ./test.sock
bash: ./test.sock: Permission denied

(I did also test that indeed only the w bit seems to matter for accessing the socket on Debian's Linux 4.9.0.)

Perhaps the sockets you meant had all permission bits removed from the user, or you meant the x bit on the directory?

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.