Skip to contentSkip to conversation

__legitimize_mnt(): check for MNT_SYNC_UMOUNT should be under mount_lock

RFC PATCH In review Al Viro 2 participants 2 messages Apr 27, 2025 – Apr 28, 2025 VFS

lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

RFC PATCH 1/1 __legitimize_mnt(): check for MNT_SYNC_UMOUNT should be under mount_lock

[another catch from struct mount audit]
... or we risk stealing final mntput from sync umount - raising mnt_count after umount(2) has verified that victim is not busy, but before it has set MNT_SYNC_UMOUNT; in that case __legitimize_mnt() doesn't see that it's safe to quietly undo mnt_count increment and leaves dropping the reference to caller, where it'll be a full-blown mntput().

Check under mount_lock is needed; leaving the current one done before taking that makes no sense - it's nowhere near common enough to bother with.

---

fs/namespace.c +1 -5
index 98a5cd756e9a..eba4748388b1 100644
@@ -790,12 +790,8 @@ int __legitimize_mnt(struct vfsmount *bastard, unsigned seq)
 	smp_mb();			// see mntput_no_expire()
 	if (likely(!read_seqretry(&mount_lock, seq)))
 		return 0;
-	if (bastard->mnt_flags & MNT_SYNC_UMOUNT) {
-		mnt_add_count(mnt, -1);
-		return 1;
-	}
 	lock_mount_hash();
-	if (unlikely(bastard->mnt_flags & MNT_DOOMED)) {
+	if (unlikely(bastard->mnt_flags & (MNT_SYNC_UMOUNT | MNT_DOOMED))) {
 		mnt_add_count(mnt, -1);
 		unlock_mount_hash();
 		return 1;
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Al Viro

[another catch from struct mount audit]
... or we risk stealing final mntput from sync umount - raising mnt_count after umount(2) has verified that victim is not busy, but before it has set MNT_SYNC_UMOUNT; in that case __legitimize_mnt() doesn't see that it's safe to quietly undo mnt_count increment and leaves dropping the reference to caller, where it'll be a full-blown mntput().

Quoted 6 lines

Check under mount_lock is needed; leaving the current one done before taking that makes no sense - it's nowhere near common enough to bother with.

---