2011-03-24 09:57:16

by Petr Písař

[permalink] [raw]
Subject: [PATCH] Clean console safely

Traditional \E[2J sequence erases console display but scroll-back
buffer and underlying device (frame) buffer keep data that can be
accessed by scrolling console back.

This patch introduce new \E[J parameter 3 that allows to scramble
scroll-back buffer explicitly. Session locking programs (screen,
vlock) can use it to prevent attacker to browse locked console
history.
---
drivers/tty/vt/vt.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 147ede3..c31bf2a 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1198,6 +1198,12 @@ static void csi_J(struct vc_data *vc, int vpar)
vc->vc_x + 1);
}
break;
+ case 3: /* erase scroll-back buffer (and whole display) */
+ scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
+ vc->vc_screenbuf_size >> 1);
+ set_origin(vc);
+ if (CON_IS_VISIBLE(vc))
+ update_screen(vc);
case 2: /* erase whole display */
count = vc->vc_cols * vc->vc_rows;
start = (unsigned short *)vc->vc_origin;
--
1.7.4


2011-03-24 10:24:13

by Alan

[permalink] [raw]
Subject: Re: [PATCH] Clean console safely

On Thu, 24 Mar 2011 10:56:51 +0100
Petr Písař <[email protected]> wrote:

> Traditional \E[2J sequence erases console display but scroll-back
> buffer and underlying device (frame) buffer keep data that can be
> accessed by scrolling console back.
>
> This patch introduce new \E[J parameter 3 that allows to scramble
> scroll-back buffer explicitly. Session locking programs (screen,
> vlock) can use it to prevent attacker to browse locked console
> history.
> ---
> drivers/tty/vt/vt.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)

Looks sensible enough

There are a set of official codes that are probably more relevant, and
also deal with the timing of events

See DECSR/DECSRC on a later VT terminal, also DECSTR which

DECSR = secure reset, return to power up state, \E[n+p where n is an
optional value from 1-16383 which if provided is replied back from the tty
as a DECSRC response (hence 'secure'). It's defined to clear off
screen memory, and also other weirdness a user may have set up so could
reasonably also be extended a bit if there is other stuff founbd in
future that such a reset really ought to clean up - eg for mingetty.

http://www.vt100.net/docs/vt520-rm/ek-vt520-rm.pdf (page 299)

ED 3J looks fine but is a new "made up" extension.

2011-03-24 14:16:08

by Petr Písař

[permalink] [raw]
Subject: Re: [PATCH] Clean console safely

On Thu, Mar 24, 2011 at 10:24:31AM +0000, Alan Cox wrote:
> On Thu, 24 Mar 2011 10:56:51 +0100
> Petr Písař <[email protected]> wrote:
>
> > Traditional \E[2J sequence erases console display but scroll-back
> > buffer and underlying device (frame) buffer keep data that can be
> > accessed by scrolling console back.
> >
> > This patch introduce new \E[J parameter 3 that allows to scramble
> > scroll-back buffer explicitly. Session locking programs (screen,
> > vlock) can use it to prevent attacker to browse locked console
> > history.
> > ---
> > drivers/tty/vt/vt.c | 6 ++++++
> > 1 files changed, 6 insertions(+), 0 deletions(-)
>
> Looks sensible enough
>
> There are a set of official codes that are probably more relevant, and
> also deal with the timing of events
>
> See DECSR/DECSRC on a later VT terminal, also DECSTR which
>
> DECSR = secure reset, return to power up state, \E[n+p where n is an
> optional value from 1-16383 which if provided is replied back from the tty
> as a DECSRC response (hence 'secure'). It's defined to clear off
> screen memory, and also other weirdness a user may have set up so could
> reasonably also be extended a bit if there is other stuff founbd in
> future that such a reset really ought to clean up - eg for mingetty.
>
> http://www.vt100.net/docs/vt520-rm/ek-vt520-rm.pdf (page 299)
>
> ED 3J looks fine but is a new "made up" extension.
>
The problem with DECSRC as well as DECSTR or RIS is they reset terminal font,
keyboard layout, unicode mode and other configuration. That's the reason why
I rejected enhancing RIS implemented in Linux VT already. In other words,
I'm searching for a clear display feature which preserves configuration.
I read console_codes(4), console_ioctl(4), and now the VT520 documentation and
I did not find any existing control code. The most close seems ED J for me.

-- Petr

2011-03-24 14:51:37

by Alan

[permalink] [raw]
Subject: Re: [PATCH] Clean console safely

> I'm searching for a clear display feature which preserves configuration.
> I read console_codes(4), console_ioctl(4), and now the VT520 documentation and
> I did not find any existing control code. The most close seems ED J for me.

Seems reasonable to me on that basis.


>
> -- Petr


--
--
"Alan, I'm getting a bit worried about you."
-- Linus Torvalds