summaryrefslogtreecommitdiff
path: root/sys/dev/cons.c
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-10-03 19:13:08 +0000
committerriastradh <riastradh@NetBSD.org>2022-10-03 19:13:08 +0000
commit05a501857ead923469dff548852de42e7a6355e8 (patch)
tree680ede8b116735ba04aed8eaf555654ba3477f3f /sys/dev/cons.c
parent8f525d5e71b82323d2d592147ec17658c2968066 (diff)
cons(9): Check the unit number on close too.
Races between multiple opens, some of which fail, might lead to closing a bad unit number -- not clear there's a good way to prevent this.
Diffstat (limited to 'sys/dev/cons.c')
-rw-r--r--sys/dev/cons.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/sys/dev/cons.c b/sys/dev/cons.c
index 76714504c70..a450a62b2af 100644
--- a/sys/dev/cons.c
+++ b/sys/dev/cons.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cons.c,v 1.81 2022/10/03 19:12:51 riastradh Exp $ */
+/* $NetBSD: cons.c,v 1.82 2022/10/03 19:13:08 riastradh Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.81 2022/10/03 19:12:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.82 2022/10/03 19:13:08 riastradh Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -175,6 +175,8 @@ cnclose(dev_t dev, int flag, int mode, struct lwp *l)
int unit, error;
unit = minor(dev);
+ if (unit > 1)
+ return ENODEV;
mutex_enter(&cn_lock);