Skip to contentSkip to conversation

fix xconsole.

RFC PATCH In review Eric W. Biederman 2 participants 2 messages Dec 17, 2008 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 fix xconsole.

Long ago xconsole broke (a regression) and it has been a mystery to me. One of my coworkers mentioned it again and I happened to been looking at code in the vicinity and I finally figured out what happened.

Quoted 1 line

From the tty_ioctl manpage TIOCCONS is documented as:

Redirecting console output
TIOCCONS void
Redirect output that would have gone to /dev/console or /dev/tty0 to the given tty. If that was a pty master, send it to the slave. Anybody can do this as long as the output was not redirected yet. If it was redirected already EBUSY is returned, but root may stop redirection by using this ioctl with fd pointing at /dev/console or /dev/tty0.

And it used to match the implementation. But then we had what appears to be an overzealous security fix.

The console messages may only be redirected once, and root may perform that initial redirection. So I don't see why it is a security issue.

Do we have a better way to see console messages when we are in X? I haven't seen it.

Perhaps if we had a working xconsole we would have less random spew to the console.

Quoted 20 lines

commit adc281202e9c8824c3d1688a109bc5f19b6184d1

Author: od <od>
Date:   Tue Oct 19 14:59:16 2004 +0000

[PATCH] TIOCCONS security

The ioctl TIOCCONS allows any user to redirect console output to another tty. This allows anyone to suppress messages to the console at will.

AFAIK nowadays not many programs write to /dev/console, except for start scripts and the kernel (printk() above console log level).

Still, I believe that administrators and operators would not like any user to be able to hijack messages that were written to the console.

The only user of TIOCCONS that I am aware of is bootlogd/blogd, which runs as root. Please comment if there are other users.

Is there any reason why normal users should be able to use TIOCCONS?

Quoted 7 lines

Otherwise I would suggest to restrict access to root (CAP_SYS_ADMIN), e.g. with this patch.

BKrev: 41752bc4MrRxTUxDRjvfWObhWFXPyA

---

drivers/char/tty_io.c +2 -2
index 1412a8d..44794a9 100644
@@ -2128,10 +2128,10 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
 
 static int tioccons(struct file *file)
 {
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	if (file->f_op->write == redirected_tty_write) {
 		struct file *f;
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
 		spin_lock(&redirect_lock);
 		f = redirect;
 		redirect = NULL;
#1 lore raw
Quoted 2 lines

The console messages may only be redirected once, and root may perform that initial redirection. So I don't see why it is a security issue.

I see nothing after your change that stops random users redirecting the console providing they are "first". Random users should not be able to hijack the system console stream.

The ancient behaviour is an icky hack for xconsole in a world where security didn't use to matter.

Alan