Source-Changes-HG archive

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

[src/trunk]: src/sys/sys ioctl(DIOCRMWEDGES): Delete only idle wedges.



details:   https://anonhg.NetBSD.org/src/rev/0201d8a0d3b9
branches:  trunk
changeset: 374649:0201d8a0d3b9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue May 09 12:04:04 2023 +0000

description:
ioctl(DIOCRMWEDGES): Delete only idle wedges.

Don't forcibly delete busy wedges.

Reported-by: syzbot+e46f31fe56e04f567d88%syzkaller.appspotmail.com@localhost
https://syzkaller.appspot.com/bug?id=8a00fd7f2e7459748d7a274098180a4708ff0f61

Fixes accidental destruction of the busy wedge that the root file
system is mounted on, triggered by syzbot's ioctl(DIOCRMWEDGES).

diffstat:

 sys/dev/dkwedge/dk.c |  25 +++++++++++++++++++------
 sys/kern/subr_disk.c |   6 +++---
 sys/sys/disk.h       |   3 ++-
 3 files changed, 24 insertions(+), 10 deletions(-)

diffs (102 lines):

diff -r 21360d29d748 -r 0201d8a0d3b9 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Tue May 09 12:03:55 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Tue May 09 12:04:04 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.153 2023/05/09 12:03:55 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.154 2023/05/09 12:04:04 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.153 2023/05/09 12:03:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.154 2023/05/09 12:04:04 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -774,14 +774,27 @@ dkwedge_detach(device_t self, int flags)
 /*
  * dkwedge_delall:     [exported function]
  *
- *     Delete all of the wedges on the specified disk.  Used when
- *     a disk is being detached.
+ *     Forcibly delete all of the wedges on the specified disk.  Used
+ *     when a disk is being detached.
  */
 void
 dkwedge_delall(struct disk *pdk)
 {
 
-       dkwedge_delall1(pdk, false);
+       dkwedge_delall1(pdk, /*idleonly*/false);
+}
+
+/*
+ * dkwedge_delidle:    [exported function]
+ *
+ *     Delete all of the wedges on the specified disk if idle.  Used
+ *     by ioctl(DIOCRMWEDGES).
+ */
+void
+dkwedge_delidle(struct disk *pdk)
+{
+
+       dkwedge_delall1(pdk, /*idleonly*/true);
 }
 
 static void
@@ -1065,7 +1078,7 @@ dkwedge_discover(struct disk *pdk)
        /*
         * Remove unused wedges
         */
-       dkwedge_delall1(pdk, true);
+       dkwedge_delidle(pdk);
 
        /*
         * For each supported partition map type, look to see if
diff -r 21360d29d748 -r 0201d8a0d3b9 sys/kern/subr_disk.c
--- a/sys/kern/subr_disk.c      Tue May 09 12:03:55 2023 +0000
+++ b/sys/kern/subr_disk.c      Tue May 09 12:04:04 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_disk.c,v 1.136 2023/04/22 11:58:01 riastradh Exp $        */
+/*     $NetBSD: subr_disk.c,v 1.137 2023/05/09 12:04:04 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.136 2023/04/22 11:58:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.137 2023/05/09 12:04:04 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -655,7 +655,7 @@ disk_ioctl(struct disk *dk, dev_t dev, u
                if ((flag & FWRITE) == 0)
                        return EBADF;
 
-               dkwedge_delall(dk);
+               dkwedge_delidle(dk);
                return 0;
 
        default:
diff -r 21360d29d748 -r 0201d8a0d3b9 sys/sys/disk.h
--- a/sys/sys/disk.h    Tue May 09 12:03:55 2023 +0000
+++ b/sys/sys/disk.h    Tue May 09 12:04:04 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disk.h,v 1.77 2021/07/24 21:31:39 andvar Exp $ */
+/*     $NetBSD: disk.h,v 1.78 2023/05/09 12:04:04 riastradh Exp $      */
 
 /*-
  * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
@@ -552,6 +552,7 @@ void        dkwedge_init(void);
 int    dkwedge_add(struct dkwedge_info *);
 int    dkwedge_del(struct dkwedge_info *);
 void   dkwedge_delall(struct disk *);
+void   dkwedge_delidle(struct disk *);
 int    dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *);
 void   dkwedge_discover(struct disk *);
 int    dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t);



Home | Main Index | Thread Index | Old Index