opnsense-src/sys/fs/nullfs
Mark Johnston 3d1e822916 namei: Make stackable filesystems check harder for jail roots
Suppose a process has its cwd pointing to a nullfs directory, where the
lower directory is also visible in the jail's filesystem namespace.
Suppose that the lower directory vnode is moved out from under the
nullfs mount.  The nullfs vnode still shadows the lower vnode, and
dotdot lookups relative to that directory will instantiate new nullfs
vnodes outside of the nullfs mountpoint, effectively shadowing the lower
filesystem.

This phenomenon can be abused to escape a chroot, since the nullfs
vnodes instantiated by these dotdot lookups defeat the root vnode check
in vfs_lookup(), which uses vnode pointer equality to test for the
process root.

Fix this by extending nullfs and unionfs to perform the same check,
exploiting the fact that the passed componentname is embedded in a
nameidata structure to avoid changing the VOP_LOOKUP interface.  That
is, add a flag to indicate that containerof can be used to get the full
nameidata structure, and perform the root vnode check on the lower vnode
when performing a dotdot lookup.

Approved by:	so
Security:	FreeBSD-SA-26:02.jail
Security:	CVE-2025-15547
PR:		262180
Reviewed by:	olce, kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D50418

(cherry picked from commit 7587f6d484)
(cherry picked from commit 3feafab4a34c95209cd4fc3e6224c324efc056f3)
2026-01-28 07:36:26 +01:00
..
null.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
null_subr.c sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
null_vfsops.c nullfs: stop lying about mount flags in statfs(2) 2024-12-27 08:24:55 +02:00
null_vnops.c namei: Make stackable filesystems check harder for jail roots 2026-01-28 07:36:26 +01:00