Module Name:    src
Committed By:   martin
Date:           Tue Oct 31 10:45:19 UTC 2017

Modified Files:
        src/sys/arch/sparc64/dev: sab.c
        src/sys/dev/ic: com.c z8530tty.c
        src/sys/sys: tty.h

Log Message:
As discussed on tech-kern: define a new tty internal state flag: TS_KERN_ONLY

Implement it in a few tty drivers. If this flag is set, the underlying
hardware is used by another driver and userland has no right to open
it. A few uses will appear soon in sys/dev/sun/sun{kbd,ms}.c.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/sparc64/dev/sab.c
cvs rdiff -u -r1.344 -r1.345 src/sys/dev/ic/com.c
cvs rdiff -u -r1.131 -r1.132 src/sys/dev/ic/z8530tty.c
cvs rdiff -u -r1.93 -r1.94 src/sys/sys/tty.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc64/dev/sab.c
diff -u src/sys/arch/sparc64/dev/sab.c:1.54 src/sys/arch/sparc64/dev/sab.c:1.55
--- src/sys/arch/sparc64/dev/sab.c:1.54	Sat Nov 15 19:20:02 2014
+++ src/sys/arch/sparc64/dev/sab.c	Tue Oct 31 10:45:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: sab.c,v 1.54 2014/11/15 19:20:02 christos Exp $	*/
+/*	$NetBSD: sab.c,v 1.55 2017/10/31 10:45:19 martin Exp $	*/
 /*	$OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $	*/
 
 /*
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sab.c,v 1.54 2014/11/15 19:20:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sab.c,v 1.55 2017/10/31 10:45:19 martin Exp $");
 
 #include "opt_kgdb.h"
 #include <sys/types.h>
@@ -681,6 +681,13 @@ sabopen(dev_t dev, int flags, int mode, 
 	tp = sc->sc_tty;
 	tp->t_dev = dev;
 
+	/*
+	 * If the device is exclusively for kernel use, deny userland
+	 * open.
+	 */
+	if (ISSET(tp->t_state, TS_KERN_ONLY))
+		return (EBUSY);
+
 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
 		return (EBUSY);
 

Index: src/sys/dev/ic/com.c
diff -u src/sys/dev/ic/com.c:1.344 src/sys/dev/ic/com.c:1.345
--- src/sys/dev/ic/com.c:1.344	Sun Oct 29 14:06:08 2017
+++ src/sys/dev/ic/com.c	Tue Oct 31 10:45:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.344 2017/10/29 14:06:08 jmcneill Exp $ */
+/* $NetBSD: com.c,v 1.345 2017/10/31 10:45:19 martin Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.344 2017/10/29 14:06:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.345 2017/10/31 10:45:19 martin Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -879,6 +879,13 @@ comopen(dev_t dev, int flag, int mode, s
 
 	tp = sc->sc_tty;
 
+	/*
+	 * If the device is exclusively for kernel use, deny userland
+	 * open.
+	 */
+	if (ISSET(tp->t_state, TS_KERN_ONLY))
+		return (EBUSY);
+
 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
 		return (EBUSY);
 
@@ -1017,6 +1024,12 @@ comclose(dev_t dev, int flag, int mode, 
 	/* XXX This is for cons.c. */
 	if (!ISSET(tp->t_state, TS_ISOPEN))
 		return (0);
+	/*
+	 * If the device is exclusively for kernel use, deny userland
+	 * close.
+	 */
+	if (ISSET(tp->t_state, TS_KERN_ONLY))
+		return (0);
 
 	(*tp->t_linesw->l_close)(tp, flag);
 	ttyclose(tp);

Index: src/sys/dev/ic/z8530tty.c
diff -u src/sys/dev/ic/z8530tty.c:1.131 src/sys/dev/ic/z8530tty.c:1.132
--- src/sys/dev/ic/z8530tty.c:1.131	Sat Nov 15 19:18:18 2014
+++ src/sys/dev/ic/z8530tty.c	Tue Oct 31 10:45:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: z8530tty.c,v 1.131 2014/11/15 19:18:18 christos Exp $	*/
+/*	$NetBSD: z8530tty.c,v 1.132 2017/10/31 10:45:19 martin Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999
@@ -137,7 +137,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.131 2014/11/15 19:18:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.132 2017/10/31 10:45:19 martin Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_ntp.h"
@@ -560,6 +560,13 @@ zsopen(dev_t dev, int flags, int mode, s
 	if (tp == NULL)
 		return (EBUSY);
 
+	/*
+	 * If the device is exclusively for kernel use, deny userland
+	 * open.
+	 */
+	if (ISSET(tp->t_state, TS_KERN_ONLY))
+		return (EBUSY);
+
 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
 		return (EBUSY);
 

Index: src/sys/sys/tty.h
diff -u src/sys/sys/tty.h:1.93 src/sys/sys/tty.h:1.94
--- src/sys/sys/tty.h:1.93	Sat Nov 15 19:17:05 2014
+++ src/sys/sys/tty.h	Tue Oct 31 10:45:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.h,v 1.93 2014/11/15 19:17:05 christos Exp $	*/
+/*	$NetBSD: tty.h,v 1.94 2017/10/31 10:45:19 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -203,6 +203,10 @@ struct tty {
 #define	TS_TYPEN	0x08000		/* Retyping suspended input (PENDIN). */
 #define	TS_LOCAL	(TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
 
+/* for special line disciplines, like dev/sun/sunkbd.c */
+#define	TS_KERN_ONLY	0x10000		/* Device is accessible by kernel
+					 * only, deny all userland access */
+
 /* Character type information. */
 #define	ORDINARY	0
 #define	CONTROL		1

Reply via email to