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.
This commit is contained in:
parent
5905ff7f42
commit
6e7b93fc42
|
@ -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, struct lwp *l)
|
|||
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);
|
||||
|
||||
|
|
|
@ -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, struct lwp *l)
|
|||
|
||||
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, struct lwp *l)
|
|||
/* 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);
|
||||
|
|
|
@ -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, struct lwp *l)
|
|||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue