Just a patch to motivate discussion.
Sibling jails which can exchange fds over a unix socket can escape the
jail chroot by passing a directory fd that points to a vnode outside of
the receiver's root. Try to restrict this by treating dirfds as
capabilities when exchanged between two jails with different root
directories.
First, add a new per-fd flag which causes name lookups relative to that
fd to behave as though O_RESOLVE_BENEATH was specified. When
transferring fds, set that flag in the case described above. This
requires modifying some fget* interfaces to return the fd flags.
Second, disallow fchdir (and fchroot) to a directory received in the
case described above. I think this is maybe too heavy-handed, but I
don't have a better solution at the moment.
PR: 262179