HomeFreeBSD

unix: Set O_RESOLVE_BENEATH on fds transferred between jails

Description

unix: Set O_RESOLVE_BENEATH on fds transferred between jails

If a pair of jails with different filesystem roots is able to exchange
SCM_RIGHTS messages (e.g., using a unix socket in a shared nullfs
mount), a process in one jail can open a directory outside of the root
of the second jail and then pass the fd to that second jail, allowing
the receiving process to escape the jail chroot.

Address this using the new FD_RESOLVE_BENEATH flag. When externalizing
an SCM_RIGHTS message into the receiving process, automatically set this
flag on all new fds where a jail boundary is crossed. This ensures that
the receiver cannot do more than access files underneath the directory;
in particular, the received fd cannot be used to access vnodes not
accessible by the sender.

Approved by: so
PR: 262179
Reviewed by: kib
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D50371

(cherry picked from commit 350ba9672a7f4f16e30534a603df577dfd083b3f)
(cherry picked from commit 73530e4c2ea92564e393e0497f13dfac251a41b7)

Details

Provenance
markjAuthored on Jun 24 2025, 8:05 PM
Reviewer
kib
Differential Revision
D50371: unix: Restrict dirfds exchanged between jails with a different root
Parents
rG82cee749b523: file: Add a fd flag with O_RESOLVE_BENEATH semantics
Branches
Unknown
Tags
Unknown