Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dkwedge dk(4): Fix racy access to sc->sc_dk.dk_openm...



details:   https://anonhg.NetBSD.org/src/rev/701a33884c75
branches:  trunk
changeset: 374410:701a33884c75
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Apr 22 12:33:46 2023 +0000

description:
dk(4): Fix racy access to sc->sc_dk.dk_openmask in dkwedge_delall1.

Need sc->sc_parent->dk_rawlock for this, as used in dkopen/dkclose.

diffstat:

 sys/dev/dkwedge/dk.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (41 lines):

diff -r 01d19943efe8 -r 701a33884c75 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Sat Apr 22 11:58:01 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Sat Apr 22 12:33:46 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.148 2023/04/21 18:54:09 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.149 2023/04/22 12:33:46 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.148 2023/04/21 18:54:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.149 2023/04/22 12:33:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -796,6 +796,7 @@ dkwedge_delall1(struct disk *pdk, bool i
                flags |= DETACH_FORCE;
 
        for (;;) {
+               mutex_enter(&pdk->dk_rawlock); /* for sc->sc_dk.dk_openmask */
                mutex_enter(&pdk->dk_openlock);
                LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) {
                        if (!idleonly || sc->sc_dk.dk_openmask == 0)
@@ -804,12 +805,14 @@ dkwedge_delall1(struct disk *pdk, bool i
                if (sc == NULL) {
                        KASSERT(idleonly || pdk->dk_nwedges == 0);
                        mutex_exit(&pdk->dk_openlock);
+                       mutex_exit(&pdk->dk_rawlock);
                        return;
                }
                strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent));
                strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
                    sizeof(dkw.dkw_devname));
                mutex_exit(&pdk->dk_openlock);
+               mutex_exit(&pdk->dk_rawlock);
                (void) dkwedge_del1(&dkw, flags);
        }
 }



Home | Main Index | Thread Index | Old Index