unix domain socket - securing receiver

sockets, unix

Solution

The general thought on Linux is that security is enforced by the file permissions on the UNIX socket "file" in the filesystem. A process must have read/write access to the socket special file.

The `unix(7)` man page indicates:

In the Linux implementation, sockets which are visible in the filesystem honor the permissions of the directory they are in. Their owner, group, and 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.

It seems that directory-searching permissions are honored everywhere, though. So your socket can only be `connect()`ed to by users that have execute access on the entire path to your socket special file - this is true on all OSes.

Related:

- Can UNIX Domain Sockets be locked by user ID?

- Which systems do not honor socket read/write permissions?

Problem

I am studying a tutorial on unix domain socket. I have a question on the receiver part. If a process is using listen() and waiting for incoming requests: what options does it have to make itself secure ? Does it have a way to identify who sent the request ? Can it apply some restriction on who can send it a request ? Is the situation that there is there no security option and if a process uses listen() its completely open to any request ?

Original source