Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Fix locking after opendisk(), VOP_IOCTL() needs an ...



details:   https://anonhg.NetBSD.org/src/rev/4beaa13a3b4c
branches:  trunk
changeset: 364369:4beaa13a3b4c
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sat Mar 19 13:51:35 2022 +0000

description:
Fix locking after opendisk(), VOP_IOCTL() needs an unlocked vnode,
vn_rdwr() needs flag IO_NODELOCKED.

diffstat:

 sys/arch/evbarm/fdt/fdt_machdep.c |   6 +++---
 sys/arch/x86/x86/x86_autoconf.c   |  10 ++++++----
 sys/arch/zaurus/zaurus/autoconf.c |   6 ++++--
 sys/kern/init_main.c              |   6 ++++--
 sys/kern/kern_subr.c              |   6 ++++--
 5 files changed, 21 insertions(+), 13 deletions(-)

diffs (157 lines):

diff -r ab1309dad3b5 -r 4beaa13a3b4c sys/arch/evbarm/fdt/fdt_machdep.c
--- a/sys/arch/evbarm/fdt/fdt_machdep.c Sat Mar 19 13:50:02 2022 +0000
+++ b/sys/arch/evbarm/fdt/fdt_machdep.c Sat Mar 19 13:51:35 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.89 2022/03/19 09:55:30 skrll Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.90 2022/03/19 13:51:35 hannken Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.89 2022/03/19 09:55:30 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.90 2022/03/19 13:51:35 hannken Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bootconfig.h"
@@ -774,7 +774,7 @@
                if (!vp)
                        return;
                error = vn_rdwr(UIO_READ, vp, buf, sizeof(buf), 0, UIO_SYSSPACE,
-                   0, NOCRED, &resid, NULL);
+                   IO_NODELOCKED, NOCRED, &resid, NULL);
                VOP_CLOSE(vp, FREAD, NOCRED);
                vput(vp);
 
diff -r ab1309dad3b5 -r 4beaa13a3b4c sys/arch/x86/x86/x86_autoconf.c
--- a/sys/arch/x86/x86/x86_autoconf.c   Sat Mar 19 13:50:02 2022 +0000
+++ b/sys/arch/x86/x86/x86_autoconf.c   Sat Mar 19 13:51:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_autoconf.c,v 1.86 2022/02/12 03:24:35 riastradh Exp $      */
+/*     $NetBSD: x86_autoconf.c,v 1.87 2022/03/19 13:51:35 hannken Exp $        */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.86 2022/02/12 03:24:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.87 2022/03/19 13:51:35 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -178,7 +178,7 @@
                }
 
                error = vn_rdwr(UIO_READ, tv, mbr, DEV_BSIZE, 0, UIO_SYSSPACE,
-                   0, NOCRED, NULL, NULL);
+                   IO_NODELOCKED, NOCRED, NULL, NULL);
                VOP_CLOSE(tv, FREAD, NOCRED);
                vput(tv);
                if (error) {
@@ -243,7 +243,7 @@
             nblks != 0; nblks--, blk++) {
                error = vn_rdwr(UIO_READ, tmpvn, (void *) bf,
                    sizeof(bf), blk * DEV_BSIZE, UIO_SYSSPACE,
-                   0, NOCRED, NULL, NULL);
+                   IO_NODELOCKED, NOCRED, NULL, NULL);
                if (error) {
                        if (error != EINVAL) {
                                aprint_error("%s: unable to read block %"
@@ -298,7 +298,9 @@
                return 0;
        }
 
+       VOP_UNLOCK(tmpvn);
        error = VOP_IOCTL(tmpvn, DIOCGDINFO, &label, FREAD, NOCRED);
+       vn_lock(tmpvn, LK_EXCLUSIVE | LK_RETRY);
        if (error) {
                /*
                 * XXX Can't happen -- open() would have errored out
diff -r ab1309dad3b5 -r 4beaa13a3b4c sys/arch/zaurus/zaurus/autoconf.c
--- a/sys/arch/zaurus/zaurus/autoconf.c Sat Mar 19 13:50:02 2022 +0000
+++ b/sys/arch/zaurus/zaurus/autoconf.c Sat Mar 19 13:51:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.15 2022/02/12 03:24:35 riastradh Exp $  */
+/*     $NetBSD: autoconf.c,v 1.16 2022/03/19 13:51:35 hannken Exp $    */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.15 2022/02/12 03:24:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.16 2022/03/19 13:51:35 hannken Exp $");
 
 #include "opt_md.h"
 
@@ -109,7 +109,9 @@
        if ((tmpvn = opendisk(dv)) == NULL)
                return 0;
 
+       VOP_UNLOCK(tmpvn);
        error = VOP_IOCTL(tmpvn, DIOCGDINFO, &label, FREAD, NOCRED);
+       vn_lock(tmpvn, LK_EXCLUSIVE | LK_RETRY);
        if (error) {
                /*
                 * XXX Can't happen -- open() would have errored out
diff -r ab1309dad3b5 -r 4beaa13a3b4c sys/kern/init_main.c
--- a/sys/kern/init_main.c      Sat Mar 19 13:50:02 2022 +0000
+++ b/sys/kern/init_main.c      Sat Mar 19 13:51:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.537 2022/03/18 23:37:06 riastradh Exp $        */
+/*     $NetBSD: init_main.c,v 1.538 2022/03/19 13:51:35 hannken Exp $  */
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.537 2022/03/18 23:37:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.538 2022/03/19 13:51:35 hannken Exp $");
 
 #include "opt_cnmagic.h"
 #include "opt_ddb.h"
@@ -890,7 +890,9 @@
                if (vp == NULL)
                        return;
 
+               VOP_UNLOCK(vp);
                error = VOP_IOCTL(vp, DIOCGDINFO, &label, FREAD, NOCRED);
+               vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
                VOP_CLOSE(vp, FREAD, NOCRED);
                vput(vp);
                if (error)
diff -r ab1309dad3b5 -r 4beaa13a3b4c sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c      Sat Mar 19 13:50:02 2022 +0000
+++ b/sys/kern/kern_subr.c      Sat Mar 19 13:51:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_subr.c,v 1.229 2020/11/21 08:10:27 mlelstv Exp $  */
+/*     $NetBSD: kern_subr.c,v 1.230 2022/03/19 13:51:35 hannken Exp $  */
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.229 2020/11/21 08:10:27 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.230 2022/03/19 13:51:35 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_md.h"
@@ -137,7 +137,9 @@
        if ((vn = opendisk(dv)) == NULL)
                return 0;
 
+       VOP_UNLOCK(vn);
        error = VOP_IOCTL(vn, DIOCGWEDGEINFO, &wi, FREAD, NOCRED);
+       vn_lock(vn, LK_EXCLUSIVE | LK_RETRY);
        VOP_CLOSE(vn, FREAD, NOCRED);
        vput(vn);
        if (error) {



Home | Main Index | Thread Index | Old Index