mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH] fix xconsole.
Date: Wed, 17 Dec 2008 01:06:30 -0800	[thread overview]
Message-ID: <m1wsdz892h.fsf@frodo.ebiederm.org> (raw)


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.

>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.

> 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?
>     
>     Otherwise I would suggest to restrict access to root (CAP_SYS_ADMIN), e.g.
>     with this patch.
>     
>     Signed-off-by: Andrew Morton <akpm@osdl.org>
>     Signed-off-by: Linus Torvalds <torvalds@osdl.org>
>     
>     BKrev: 41752bc4MrRxTUxDRjvfWObhWFXPyA

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

---
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 1412a8d..44794a9 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -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;

             reply	other threads:[~2008-12-17  9:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-17  9:06 Eric W. Biederman [this message]
2008-12-17 10:31 ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1wsdz892h.fsf@frodo.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®