diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-06-04 19:56:36 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-06-13 00:58:34 +0000 |
| commit | f8fc6a086e559855243ef3d2ffda35e1ae0e7d71 (patch) | |
| tree | d6089ad86467f05af206b1fe77b9847b7af68066 | |
| parent | f9a216c4fcc1766798e93e376bc4e23ea99e9ddf (diff) | |
rename(2): do not allow to rename root vnode of the mounted filesystem
PR: 295826
(cherry picked from commit d53633bfcf24a3eb3711e24b597aa8301f92b958)
| -rw-r--r-- | sys/kern/vfs_lookup.c | 2 | ||||
| -rw-r--r-- | sys/kern/vfs_syscalls.c | 9 | ||||
| -rw-r--r-- | sys/sys/vnode.h | 1 |
3 files changed, 11 insertions, 1 deletions
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index fb3e6a7a2534..addabb45e271 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -113,7 +113,7 @@ SDT_PROBE_DEFINE4(vfs, namei, lookup, return, "int", "struct vnode *", "bool", uma_zone_t namei_zone; /* Placeholder vnode for mp traversal. */ -static struct vnode *vp_crossmp; +struct vnode *vp_crossmp; static int crossmp_vop_islocked(struct vop_islocked_args *ap) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 2516155cc1a3..ef3f7b3e8184 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -3823,6 +3823,15 @@ again: } tdvp = tond.ni_dvp; tvp = tond.ni_vp; + if (tdvp == vp_crossmp) { + /* + * Rename of the root vnode of the mounted + * filesystem. It is possible to get there with the + * nullfs mount over the regular file. + */ + error = EBUSY; + goto out; + } if (tvp != NULL && (flags & AT_RENAME_NOREPLACE) != 0) { /* * Often filesystems need to relock the vnodes in diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index bb1d3faf567e..0975b65799d6 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -470,6 +470,7 @@ extern struct mount *rootdevmp; /* "/dev" mount */ extern u_long desiredvnodes; /* number of vnodes desired */ extern struct uma_zone *namei_zone; extern struct vattr va_null; /* predefined null vattr structure */ +extern struct vnode *vp_crossmp; extern u_int vn_lock_pair_pause_max; |
