Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Harden layered file systems usage of field "mnt_lower" a...



details:   https://anonhg.NetBSD.org/src/rev/30ecfd3cba6c
branches:  trunk
changeset: 372571:30ecfd3cba6c
user:      hannken <hannken%NetBSD.org@localhost>
date:      Fri Dec 09 10:33:18 2022 +0000

description:
Harden layered file systems usage of field "mnt_lower" against
forced unmounts of the lower layer.

- Dont allow "dead_rootmount" as lower layer.

- Take file system busy before a vfs operation walks down the stack.

Reported-by: syzbot+27b35e5675b1753cec03%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+99071492e3de2eff49e9%syzkaller.appspotmail.com@localhost

diffstat:

 sys/kern/vfs_mount.c            |   7 +++++--
 sys/miscfs/genfs/layer_vfsops.c |  31 +++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 8 deletions(-)

diffs (109 lines):

diff -r 7b9d45fc5fab -r 30ecfd3cba6c sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c      Fri Dec 09 02:19:07 2022 +0000
+++ b/sys/kern/vfs_mount.c      Fri Dec 09 10:33:18 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_mount.c,v 1.100 2022/11/10 10:55:00 hannken Exp $  */
+/*     $NetBSD: vfs_mount.c,v 1.101 2022/12/09 10:33:18 hannken Exp $  */
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.100 2022/11/10 10:55:00 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.101 2022/12/09 10:33:18 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -91,6 +91,7 @@
 #include <sys/vfs_syscalls.h>
 #include <sys/vnode_impl.h>
 
+#include <miscfs/deadfs/deadfs.h>
 #include <miscfs/genfs/genfs.h>
 #include <miscfs/specfs/specdev.h>
 
@@ -418,6 +419,8 @@
 #endif
 
        if (lowermp) {
+               if (lowermp == dead_rootmount)
+                       return ENOENT;
                error = vfs_busy(lowermp);
                if (error)
                        return error;
diff -r 7b9d45fc5fab -r 30ecfd3cba6c sys/miscfs/genfs/layer_vfsops.c
--- a/sys/miscfs/genfs/layer_vfsops.c   Fri Dec 09 02:19:07 2022 +0000
+++ b/sys/miscfs/genfs/layer_vfsops.c   Fri Dec 09 10:33:18 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: layer_vfsops.c,v 1.55 2022/07/18 04:30:30 thorpej Exp $        */
+/*     $NetBSD: layer_vfsops.c,v 1.56 2022/12/09 10:33:18 hannken Exp $        */
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.55 2022/07/18 04:30:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.56 2022/12/09 10:33:18 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -146,8 +146,15 @@
 int
 layerfs_quotactl(struct mount *mp, struct quotactl_args *args)
 {
+       int error;
 
-       return VFS_QUOTACTL(mp->mnt_lower, args);
+       error = vfs_busy(mp);
+       if (error == 0) {
+               error = VFS_QUOTACTL(mp->mnt_lower, args);
+               vfs_unbusy(mp);
+       }
+
+       return error;
 }
 
 int
@@ -157,7 +164,11 @@
        int error;
 
        sbuf = kmem_zalloc(sizeof(*sbuf), KM_SLEEP);
-       error = VFS_STATVFS(mp->mnt_lower, sbuf);
+       error = vfs_busy(mp);
+       if (error == 0) {
+               error = VFS_STATVFS(mp->mnt_lower, sbuf);
+               vfs_unbusy(mp);
+       }
        if (error) {
                goto done;
        }
@@ -234,7 +245,11 @@
        struct vnode *vp;
        int error;
 
-       error = VFS_VGET(mp->mnt_lower, ino, lktype, &vp);
+       error = vfs_busy(mp);
+       if (error == 0) {
+               error = VFS_VGET(mp->mnt_lower, ino, lktype, &vp);
+               vfs_unbusy(mp);
+       }
        if (error) {
                *vpp = NULL;
                return error;
@@ -262,7 +277,11 @@
        struct vnode *vp;
        int error;
 
-       error = VFS_FHTOVP(mp->mnt_lower, fidp, lktype, &vp);
+       error = vfs_busy(mp);
+       if (error == 0) {
+               error = VFS_FHTOVP(mp->mnt_lower, fidp, lktype, &vp);
+               vfs_unbusy(mp);
+       }
        if (error) {
                *vpp = NULL;
                return error;



Home | Main Index | Thread Index | Old Index