Linux – What does x (execute) permission do on unix sockets

linuxpermissionsunix-sockets

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

Best Answer

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?

Related Question