tech-kern archive

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

New line discipline flag to prevent userland open/close of the device



While analyzing PR port-sparc64/52622 I ran into the following issue.

On some sun hardware, the com0 device is used to connect an old style keyboard,
and com1 is used for mouse. On other sparc64 machines, com0/com1 are regular
serial ports and keyboard/mouse is USB attached.

For the former, we push a special line discipline on the serial driver
and handle everything special in that line discipline:

sab0 at ebus0 addr 400000-40007f ipl 2b: rev 3.2
sabtty0 at sab0 port 0
sabtty1 at sab0 port 1
com0 at ebus0 addr 3083f8-3083ff ipl 29: ns16550a, working fifo
com0: console
kbd0 at com0 (console input)
com1 at ebus0 addr 3062f8-3062ff ipl 2a: ns16550a, working fifo
ms0 at com1
wsmouse0 at ms0 mux 0

Now for those devices we definitively do not want userland access to the com
device. This would be pretty easy if we add another flag to the tty
line disciplines t_state member, like TS_NO_USER_OPEN. Then we could
modify comclose like:

int
comclose(dev_t dev, int flag, int mode, struct lwp *l)
{
        struct com_softc *sc =
            device_lookup_private(&com_cd, COMUNIT(dev));
        struct tty *tp = sc->sc_tty;

        if (ISSET(tp->t_state, TS_NO_USER_OPEN))
                return (0);

        /* XXX This is for cons.c. */
        if (!ISSET(tp->t_state, TS_ISOPEN))
                return (0);

        (*tp->t_linesw->l_close)(tp, flag);
        ttyclose(tp);


and comopen like:


        tp = sc->sc_tty;
        
        if (ISSET(tp->t_state, TS_NO_USER_OPEN))
                return (EBUSY);
        
        if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
                return (EBUSY);
        
        s = spltty();


and after attaching the line discipline set that bit in
sys/dev/sun/sun{kbd,ms}.c.

Does that sound good? Other suggestions?

Martin


Home | Main Index | Thread Index | Old Index