Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm swap: disallow user opens of swap block device



details:   https://anonhg.NetBSD.org/src/rev/dd8f8b956306
branches:  trunk
changeset: 372697:dd8f8b956306
user:      chs <chs%NetBSD.org@localhost>
date:      Wed Dec 21 02:28:06 2022 +0000

description:
swap: disallow user opens of swap block device

the swap/drum block device was never intended to allow user opens,
but when the internal VOP_OPEN() in uvm_swap_init() was added
back in rev 1.135, the d_open method was changed from always-fail
to always-succeed in order to allow the new initial internal open.
this had the side effect of incorrectly allowing user opens too.
fix this by replacing the swap_bdevsw d_open with one that succeeds
for the first call but fails for all subsequent calls.

Reported-by: syzbot+90a23d2f19e5a0a302b3%syzkaller.appspotmail.com@localhost

diffstat:

 sys/uvm/uvm_swap.c |  24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diffs (52 lines):

diff -r ab2a16b36cce -r dd8f8b956306 sys/uvm/uvm_swap.c
--- a/sys/uvm/uvm_swap.c        Tue Dec 20 23:08:51 2022 +0000
+++ b/sys/uvm/uvm_swap.c        Wed Dec 21 02:28:06 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_swap.c,v 1.206 2021/08/23 13:08:18 hannken Exp $   */
+/*     $NetBSD: uvm_swap.c,v 1.207 2022/12/21 02:28:06 chs Exp $       */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.206 2021/08/23 13:08:18 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.207 2022/12/21 02:28:06 chs Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -1190,6 +1190,22 @@
  */
 
 /*
+ * swopen: allow the initial open from uvm_swap_init() and reject all others.
+ */
+
+static int
+swopen(dev_t dev, int flag, int mode, struct lwp *l)
+{
+       static bool inited = false;
+
+       if (!inited) {
+               inited = true;
+               return 0;
+       }
+       return ENODEV;
+}
+
+/*
  * swstrategy: perform I/O on the drum
  *
  * => we must map the i/o request from the drum to the correct swapdev.
@@ -1308,8 +1324,8 @@
 }
 
 const struct bdevsw swap_bdevsw = {
-       .d_open = nullopen,
-       .d_close = nullclose,
+       .d_open = swopen,
+       .d_close = noclose,
        .d_strategy = swstrategy,
        .d_ioctl = noioctl,
        .d_dump = nodump,



Home | Main Index | Thread Index | Old Index