From 61e759e5041d973ec4e814e204458ec7cfe5b987 Mon Sep 17 00:00:00 2001 From: riastradh Date: Sat, 12 Jun 2021 12:11:59 +0000 Subject: [PATCH] drvctl(4): Take the kernel lock around entry into autoconf(9). Can make this finer-grained once the rest of autoconf(9) is in good enough shape to support it. --- sys/kern/kern_drvctl.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_drvctl.c b/sys/kern/kern_drvctl.c index 96c66732305a..42a24fecd356 100644 --- a/sys/kern/kern_drvctl.c +++ b/sys/kern/kern_drvctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_drvctl.c,v 1.45 2020/06/11 02:28:01 thorpej Exp $ */ +/* $NetBSD: kern_drvctl.c,v 1.46 2021/06/12 12:11:59 riastradh Exp $ */ /* * Copyright (c) 2004 @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.45 2020/06/11 02:28:01 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.46 2021/06/12 12:11:59 riastradh Exp $"); #include #include @@ -336,6 +336,7 @@ drvctl_ioctl(struct file *fp, u_long cmd, void *data) int *locs; size_t locs_sz = 0; /* XXXgcc */ + KERNEL_LOCK(1, NULL); switch (cmd) { case DRVSUSPENDDEV: case DRVRESUMEDEV: @@ -363,14 +364,16 @@ drvctl_ioctl(struct file *fp, u_long cmd, void *data) ifattr = 0; if (d->numlocators) { - if (d->numlocators > MAXLOCATORS) - return EINVAL; + if (d->numlocators > MAXLOCATORS) { + res = EINVAL; + goto out; + } locs_sz = d->numlocators * sizeof(int); locs = kmem_alloc(locs_sz, KM_SLEEP); res = copyin(d->locators, locs, locs_sz); if (res) { kmem_free(locs, locs_sz); - return res; + goto out; } } else locs = NULL; @@ -388,8 +391,10 @@ drvctl_ioctl(struct file *fp, u_long cmd, void *data) fp->f_flag); break; default: - return EPASSTHROUGH; + res = EPASSTHROUGH; + break; } +out: KERNEL_UNLOCK_ONE(NULL); return res; }