opnsense-src/sys/fs
Mark Johnston f77dc4d27a file: Add a fd flag with O_RESOLVE_BENEATH semantics
The O_RESOLVE_BENEATH openat(2) flag restricts name lookups such that
they remain under the directory referenced by the dirfd.  This commit
introduces an implicit version of the flag, FD_RESOLVE_BENEATH, stored
in the file descriptor entry.  When the flag is set, any lookup relative
to that fd automatically has O_RESOLVE_BENEATH semantics.  Furthermore,
the flag is sticky, meaning that it cannot be cleared, and it is copied
by dup() and openat().

File descriptors with FD_RESOLVE_BENEATH set may not be passed to
fchdir(2) or fchroot(2).  Various fd lookup routines are modified to
return fd flags to the caller.

This flag will be used to address a case where jails with different root
directories and the ability to pass SCM_RIGHTS messages across the jail
boundary can transfer directory fds in such as way as to allow a
filesystem escape.

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

(cherry picked from commit f35525ff20)
(cherry picked from commit 10b3f2138573da952b4db29f88f6d67cfc3300cd)
2026-02-24 19:22:09 +01:00
..
autofs sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
cd9660 cd9660: Apply the file and directory mode masks bits to all 12 access bits 2024-12-27 10:50:56 -05:00
cuse cuse: Use NULL for SYSUNINIT's last arg, which is a pointer type 2024-12-15 10:20:53 +08:00
deadfs sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
devfs sysctl(9): Ease exporting struct sizes; Discourage doing that 2025-05-13 14:41:33 +02:00
ext2fs ext2fs: 'struct ufid': Re-order fields and unpack 2025-01-17 14:51:54 +01:00
fdescfs file: Add a fd flag with O_RESOLVE_BENEATH semantics 2026-02-24 19:22:09 +01:00
fifofs sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
fuse kern: adopt the cr_gid macro for cr_groups[0] more widely 2026-01-20 08:27:09 +01:00
mntfs sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
msdosfs fs: Add static asserts for the size of fid structures 2024-12-20 14:07:12 -08:00
nfs kern: adopt the cr_gid macro for cr_groups[0] more widely 2026-01-20 08:27:09 +01:00
nfsclient kern: adopt the cr_gid macro for cr_groups[0] more widely 2026-01-20 08:27:09 +01:00
nfsserver Internal scheduling priorities: Always use symbolic ones 2025-07-31 12:42:21 +02:00
nullfs namei: Make stackable filesystems check harder for jail roots 2026-01-28 07:36:26 +01:00
p9fs p9fs: Use proper prototype for SYSINIT functions 2026-02-18 13:04:52 +01:00
procfs uio: Use switch statements when handling UIO_READ vs UIO_WRITE 2024-11-30 08:55:57 -05:00
pseudofs pseudofs: fix off by one in hash iteration in pfs_purge 2023-11-24 17:22:15 +00:00
smbfs Internal scheduling priorities: Always use symbolic ones 2025-07-31 12:42:21 +02:00
tarfs tarfs: 'struct tarfs_fid': Switch 'gen' to 'u_int', avoid packing 2025-01-17 14:51:32 +01:00
tmpfs tmpfs: allow recurse as that does happen when using unionfs 2025-07-09 10:05:47 +02:00
udf fs: Add static asserts for the size of fid structures 2024-12-20 14:07:12 -08:00
unionfs namei: Make stackable filesystems check harder for jail roots 2026-01-28 07:36:26 +01:00