Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys As discussed on tech-kern: define a new tty internal sta...
details: https://anonhg.NetBSD.org/src/rev/0940d8dcb95c
branches: trunk
changeset: 357205:0940d8dcb95c
user: martin <martin%NetBSD.org@localhost>
date: Tue Oct 31 10:45:19 2017 +0000
description:
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.
diffstat:
sys/arch/sparc64/dev/sab.c | 11 +++++++++--
sys/dev/ic/com.c | 17 +++++++++++++++--
sys/dev/ic/z8530tty.c | 11 +++++++++--
sys/sys/tty.h | 6 +++++-
4 files changed, 38 insertions(+), 7 deletions(-)
diffs (129 lines):
diff -r f59225cfaabc -r 0940d8dcb95c sys/arch/sparc64/dev/sab.c
--- a/sys/arch/sparc64/dev/sab.c Tue Oct 31 10:39:13 2017 +0000
+++ b/sys/arch/sparc64/dev/sab.c Tue Oct 31 10:45:19 2017 +0000
@@ -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 @@
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);
diff -r f59225cfaabc -r 0940d8dcb95c sys/dev/ic/com.c
--- a/sys/dev/ic/com.c Tue Oct 31 10:39:13 2017 +0000
+++ b/sys/dev/ic/com.c Tue Oct 31 10:45:19 2017 +0000
@@ -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 @@
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 @@
/* 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);
diff -r f59225cfaabc -r 0940d8dcb95c sys/dev/ic/z8530tty.c
--- a/sys/dev/ic/z8530tty.c Tue Oct 31 10:39:13 2017 +0000
+++ b/sys/dev/ic/z8530tty.c Tue Oct 31 10:45:19 2017 +0000
@@ -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 @@
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);
diff -r f59225cfaabc -r 0940d8dcb95c sys/sys/tty.h
--- a/sys/sys/tty.h Tue Oct 31 10:39:13 2017 +0000
+++ b/sys/sys/tty.h Tue Oct 31 10:45:19 2017 +0000
@@ -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 @@
#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
Home |
Main Index |
Thread Index |
Old Index