From owner-p4-projects@FreeBSD.ORG Tue Aug 19 21:08:53 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DF071106568F; Tue, 19 Aug 2008 21:08:52 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A25C41065678 for ; Tue, 19 Aug 2008 21:08:52 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 91D5B8FC36 for ; Tue, 19 Aug 2008 21:08:52 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7JL8q9q006576 for ; Tue, 19 Aug 2008 21:08:52 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7JL8qU7006574 for perforce@freebsd.org; Tue, 19 Aug 2008 21:08:52 GMT (envelope-from ed@FreeBSD.org) Date: Tue, 19 Aug 2008 21:08:52 GMT Message-Id: <200808192108.m7JL8qU7006574@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ed@FreeBSD.org using -f From: Ed Schouten To: Perforce Change Reviews Cc: Subject: PERFORCE change 147836 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Aug 2008 21:08:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=147836 Change 147836 by ed@ed_dull on 2008/08/19 21:08:04 Add an unused example of how we could implement a safer TTY flushing routine for the input path, which would be very useful for utilities like passwd to call, because it guarantees we internally zeroise all buffers. I've not hooked it up to anything yet, but let's hope someone (me?) picks this up after the MPSAFE TTY import. While there, fix some small style(9) issues in tty_*q.c, as I didn't know we had the single line of whitespace rule when I wrote the code in question. Requested by: csjp Affected files ... .. //depot/projects/mpsafetty/sys/kern/tty_inq.c#4 edit .. //depot/projects/mpsafetty/sys/kern/tty_outq.c#4 edit Differences ... ==== //depot/projects/mpsafetty/sys/kern/tty_inq.c#4 (text+ko) ==== @@ -145,6 +145,7 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio, size_t rlen, size_t flen) { + MPASS(rlen <= uio->uio_resid); while (rlen > 0) { @@ -261,6 +262,7 @@ ttyinq_set_quotes(struct ttyinq_block *tib, size_t offset, size_t length, int value) { + if (value) { /* Set the bits. */ for (; length > 0; length--, offset++) @@ -336,6 +338,7 @@ void ttyinq_canonicalize(struct ttyinq *ti) { + ti->ti_linestart = ti->ti_reprint = ti->ti_end; ti->ti_startblock = ti->ti_reprintblock = ti->ti_lastblock; } @@ -369,12 +372,29 @@ void ttyinq_flush(struct ttyinq *ti) { + ti->ti_begin = 0; ti->ti_linestart = 0; ti->ti_reprint = 0; ti->ti_end = 0; } +#if 0 +void +ttyinq_flush_safe(struct ttyinq *ti) +{ + struct ttyinq_block *tib; + + ttyinq_flush(ti); + + /* Zero all data in the input queue to make it more safe */ + TAILQ_FOREACH(tib, &ti->ti_list, tib_list) { + bzero(&tib->tib_quotes, sizeof tib->tib_quotes); + bzero(&tib->tib_data, sizeof tib->tib_data); + } +} +#endif + int ttyinq_peekchar(struct ttyinq *ti, char *c, int *quote) { @@ -396,6 +416,7 @@ void ttyinq_unputchar(struct ttyinq *ti) { + MPASS(ti->ti_linestart < ti->ti_end); if (--ti->ti_end % TTYINQ_DATASIZE == 0) { @@ -413,6 +434,7 @@ void ttyinq_reprintpos_set(struct ttyinq *ti) { + ti->ti_reprint = ti->ti_end; ti->ti_reprintblock = ti->ti_lastblock; } @@ -420,6 +442,7 @@ void ttyinq_reprintpos_reset(struct ttyinq *ti) { + ti->ti_reprint = ti->ti_linestart; ti->ti_reprintblock = ti->ti_startblock; } @@ -454,6 +477,7 @@ ttyinq_line_iterate_from_linestart(struct ttyinq *ti, ttyinq_line_iterator_t *iterator, void *data) { + ttyinq_line_iterate(ti, iterator, data, ti->ti_linestart, ti->ti_startblock); } @@ -462,6 +486,7 @@ ttyinq_line_iterate_from_reprintpos(struct ttyinq *ti, ttyinq_line_iterator_t *iterator, void *data) { + ttyinq_line_iterate(ti, iterator, data, ti->ti_reprint, ti->ti_reprintblock); } @@ -469,6 +494,7 @@ static void ttyinq_startup(void *dummy) { + ttyinq_zone = uma_zcreate("ttyinq", sizeof(struct ttyinq_block), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); } ==== //depot/projects/mpsafetty/sys/kern/tty_outq.c#4 (text+ko) ==== @@ -70,6 +70,7 @@ void ttyoutq_flush(struct ttyoutq *to) { + to->to_begin = 0; to->to_end = 0; } @@ -197,6 +198,7 @@ int ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio) { + while (uio->uio_resid > 0) { int error; struct ttyoutq_block *tob; @@ -355,6 +357,7 @@ static void ttyoutq_startup(void *dummy) { + ttyoutq_zone = uma_zcreate("ttyoutq", sizeof(struct ttyoutq_block), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); }