Source-Changes-HG archive

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

[src/netbsd-8]: src/sys Pull up following revision(s) (requested by martin in...



details:   https://anonhg.NetBSD.org/src/rev/ac4f13b4ee8f
branches:  netbsd-8
changeset: 434379:ac4f13b4ee8f
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Nov 06 10:29:06 2017 +0000

description:
Pull up following revision(s) (requested by martin in ticket #338):
        sys/arch/sparc64/dev/sab.c: revision 1.55
        sys/dev/ic/com.c: revision 1.345
        sys/dev/ic/z8530tty.c: revision 1.132
        sys/dev/sun/sunkbd.c: revision 1.30
        sys/dev/sun/sunms.c: revision 1.33
        sys/sys/tty.h: revision 1.94
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.
--
PR port-sparc64/52622: mark the parent device as TS_KERN_ONLY,
so userland will not touch it (and change serial params w/o our
control).

diffstat:

 sys/arch/sparc64/dev/sab.c |  11 +++++++++--
 sys/dev/ic/com.c           |  17 +++++++++++++++--
 sys/dev/ic/z8530tty.c      |  11 +++++++++--
 sys/dev/sun/sunkbd.c       |   7 +++++--
 sys/dev/sun/sunms.c        |   7 +++++--
 sys/sys/tty.h              |   6 +++++-
 6 files changed, 48 insertions(+), 11 deletions(-)

diffs (213 lines):

diff -r ccabdd1bc655 -r ac4f13b4ee8f sys/arch/sparc64/dev/sab.c
--- a/sys/arch/sparc64/dev/sab.c        Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/arch/sparc64/dev/sab.c        Mon Nov 06 10:29:06 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.54.12.1 2017/11/06 10:29:06 snj 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.54.12.1 2017/11/06 10:29:06 snj 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 ccabdd1bc655 -r ac4f13b4ee8f sys/dev/ic/com.c
--- a/sys/dev/ic/com.c  Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/dev/ic/com.c  Mon Nov 06 10:29:06 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.339 2016/05/27 20:01:49 bouyer Exp $ */
+/* $NetBSD: com.c,v 1.339.10.1 2017/11/06 10:29:06 snj 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.339 2016/05/27 20:01:49 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.339.10.1 2017/11/06 10:29:06 snj Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -871,6 +871,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);
 
@@ -1009,6 +1016,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 ccabdd1bc655 -r ac4f13b4ee8f sys/dev/ic/z8530tty.c
--- a/sys/dev/ic/z8530tty.c     Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/dev/ic/z8530tty.c     Mon Nov 06 10:29:06 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.131.12.1 2017/11/06 10:29:06 snj 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.131.12.1 2017/11/06 10:29:06 snj 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 ccabdd1bc655 -r ac4f13b4ee8f sys/dev/sun/sunkbd.c
--- a/sys/dev/sun/sunkbd.c      Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/dev/sun/sunkbd.c      Mon Nov 06 10:29:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sunkbd.c,v 1.29 2013/09/15 14:10:04 martin Exp $       */
+/*     $NetBSD: sunkbd.c,v 1.29.22.1 2017/11/06 10:29:06 snj Exp $     */
 
 /*
  * Copyright (c) 1992, 1993
@@ -51,7 +51,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunkbd.c,v 1.29 2013/09/15 14:10:04 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunkbd.c,v 1.29.22.1 2017/11/06 10:29:06 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,6 +145,7 @@
        KASSERT(tp->t_linesw == &sunkbd_disc);
        tp->t_oflag &= ~OPOST;
        tp->t_dev = args->kmta_dev;
+       SET(tp->t_state, TS_KERN_ONLY);
 
        /* link the structures together. */
        k->k_priv = tp;
@@ -218,6 +219,7 @@
        int error;
 
        /* Open the lower device */
+       CLR(tp->t_state, TS_KERN_ONLY);
        if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags,
                                     0/* ignored? */, l)) != 0)
                return (error);
@@ -228,6 +230,7 @@
        t.c_ospeed = sunkbd_bps;
        t.c_cflag =  CLOCAL|CS8;
        (*tp->t_param)(tp, &t);
+       SET(tp->t_state, TS_KERN_ONLY);
 
        return (0);
 }
diff -r ccabdd1bc655 -r ac4f13b4ee8f sys/dev/sun/sunms.c
--- a/sys/dev/sun/sunms.c       Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/dev/sun/sunms.c       Mon Nov 06 10:29:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sunms.c,v 1.32 2013/09/15 14:13:19 martin Exp $        */
+/*     $NetBSD: sunms.c,v 1.32.22.1 2017/11/06 10:29:06 snj Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.32 2013/09/15 14:13:19 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.32.22.1 2017/11/06 10:29:06 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -162,6 +162,7 @@
        tp->t_linesw = ttyldisc_lookup(sunms_disc.l_name);
        KASSERT(tp->t_linesw == &sunms_disc);
        tp->t_oflag &= ~OPOST;
+       SET(tp->t_state, TS_KERN_ONLY);
 
        /* Initialize translator. */
        ms->ms_byteno = -1;
@@ -192,6 +193,7 @@
        int error;
 
        /* Open the lower device */
+       CLR(tp->t_state, TS_KERN_ONLY);
        if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags,
                                     0/* ignored? */, l)) != 0)
                return (error);
@@ -202,6 +204,7 @@
        t.c_ospeed = sunms_bps;
        t.c_cflag =  CLOCAL|CS8;
        (*tp->t_param)(tp, &t);
+       SET(tp->t_state, TS_KERN_ONLY);
 
        return (0);
 }
diff -r ccabdd1bc655 -r ac4f13b4ee8f sys/sys/tty.h
--- a/sys/sys/tty.h     Mon Nov 06 09:59:01 2017 +0000
+++ b/sys/sys/tty.h     Mon Nov 06 10:29:06 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.93.12.1 2017/11/06 10:29:06 snj 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