Accept an empty sun_path when fd is not AT_FDCWD: the descriptor
then names the peer unix socket directly, instead of being the starting
directory for a pathname lookup. The held file reference keeps the peer
PCB stable, playing the role unp_vp_mtxpool plays in the pathname
path.
The descriptor must carry CAP_CONNECTAT and refer to an AF_UNIX
socket (EPROTOTYPE otherwise, ENOTSOCK for non-sockets). As with a
pathname, a stream/seqpacket peer must be listening. No filesystem
permission or MAC vnode check applies on this path: possession of the
descriptor is the authorization, as with descriptor passing.
Note this makes it possible to connect a datagram socket to an unbound
peer, which no pathname could previously name.
connect(2) and the implicit-connect send path pass AT_FDCWD and
still reject an empty path with EINVAL.
The unp_sun_path() call is hoisted out of unp_connectat() because the
early exit conditions for the two system calls (connect(2) and
connectat(2)) are slightly different.
Additionally, support /dev/fd/<N>. In a world with connectat(2),
this is largely overkill, but this also allows me to add support for
direct peer connections with plain connect(2). I think that is a wise
choice because this will allow me to propose this functionality for
Linux too without a new system call (saving that conversation for
later). Ultimately, I want to see multiple operating systems support
this to foster broader userland adoption, which should benefit everyone
including FreeBSD --- it's nicer if more 3rd party in addition to 1st
party software uses the new kernel functionality. Therefore, I hope this
additional feature is also acceptable.
That said, I am a little confused by fdescfs's myriad modes, and when it
is the responsibility of the system call vs namei to handle O_PATH /
vnode descriptors. So I think I will need some advice on this part of
the implementation.
Signed-off-by: John Ericson <John.Ericson@Obsidian.Systems>
Assisted-by: Claude Code (Claude Opus 4.8 and Fable 5)