* Re: [PATCH] more SAK stuff
@ 2001-07-02 12:49 Andries.Brouwer
0 siblings, 0 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-07-02 12:49 UTC (permalink / raw)
To: Andries.Brouwer, alan; +Cc: andrewm, linux-kernel, torvalds, tytso
>> (a) It does less, namely will not kill processes with uid 0.
>> Ted, any objections?
Alan:
> That breaks the security guarantee. Suppose I use a setuid app to confuse
> you into doing something ?
You confuse me? Unlikely :-)
Indeed, discussion is possible. I think my version is more secure
and more useful, but if you disagree, delete the lines
/* do not kill root processes */
if (p->uid == 0)
continue;
Andries
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
@ 2001-07-02 13:03 Andries.Brouwer
0 siblings, 0 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-07-02 13:03 UTC (permalink / raw)
To: Andries.Brouwer, alan; +Cc: andrewm, linux-kernel, torvalds, tytso
>> (a) It does less, namely will not kill processes with uid 0.
>> Ted, any objections?
Alan:
> That breaks the security guarantee. Suppose I use a setuid app to confuse
> you into doing something ?
On second thoughts I agree. Here is the patch without test for p->uid.
Andries
diff -u --recursive --new-file ../linux-2.4.6-pre8/linux/drivers/char/keyboard.c ./linux/drivers/char/keyboard.c
--- ../linux-2.4.6-pre8/linux/drivers/char/keyboard.c Mon Oct 16 21:58:51 2000
+++ ./linux/drivers/char/keyboard.c Mon Jul 2 13:28:09 2001
@@ -506,6 +506,8 @@
* them properly.
*/
+ if (!tty && ttytab && ttytab[0] && ttytab[0]->driver_data)
+ tty = ttytab[0];
do_SAK(tty);
reset_vc(fg_console);
#if 0
diff -u --recursive --new-file ../linux-2.4.6-pre8/linux/drivers/char/tty_io.c ./linux/drivers/char/tty_io.c
--- ../linux-2.4.6-pre8/linux/drivers/char/tty_io.c Sun Jul 1 15:19:26 2001
+++ ./linux/drivers/char/tty_io.c Mon Jul 2 14:53:52 2001
@@ -1818,20 +1818,29 @@
*
* Nasty bug: do_SAK is being called in interrupt context. This can
* deadlock. We punt it up to process context. AKPM - 16Mar2001
+ *
+ * Treat all VTs as a single tty for the purposes of SAK. A process with an
+ * open fd for one VT can do interesting things to all. aeb, 2001-07-02
*/
-static void __do_SAK(void *arg)
+#ifdef CONFIG_VT
+static inline int tty_is_vt(struct tty_struct *tty)
{
-#ifdef TTY_SOFT_SAK
- tty_hangup(tty);
+ return tty ? (tty->driver.type == TTY_DRIVER_TYPE_CONSOLE) : 0;
+}
#else
- struct tty_struct *tty = arg;
+static inline int tty_is_vt(struct tty_struct *tty)
+{
+ return 0;
+}
+#endif
+
+static inline void tty_hard_SAK(struct tty_struct *tty)
+{
struct task_struct *p;
int session;
- int i;
- struct file *filp;
-
- if (!tty)
- return;
+ int i;
+ struct file *filp;
+
session = tty->session;
if (tty->ldisc.flush_buffer)
tty->ldisc.flush_buffer(tty);
@@ -1839,7 +1848,9 @@
tty->driver.flush_buffer(tty);
read_lock(&tasklist_lock);
for_each_task(p) {
+ /* all VTs are considered a single tty here */
if ((p->tty == tty) ||
+ (tty_is_vt(tty) && tty_is_vt(p->tty)) ||
((session > 0) && (p->session == session))) {
send_sig(SIGKILL, p, 1);
continue;
@@ -1850,7 +1861,9 @@
for (i=0; i < p->files->max_fds; i++) {
filp = fcheck_files(p->files, i);
if (filp && (filp->f_op == &tty_fops) &&
- (filp->private_data == tty)) {
+ (filp->private_data == tty ||
+ (tty_is_vt(tty) &&
+ tty_is_vt(filp->private_data)))) {
send_sig(SIGKILL, p, 1);
break;
}
@@ -1860,6 +1873,17 @@
task_unlock(p);
}
read_unlock(&tasklist_lock);
+}
+
+static void __do_SAK(void *arg)
+{
+ struct tty_struct *tty = arg;
+ if (!tty) /* impossible */
+ return;
+#ifdef TTY_SOFT_SAK
+ tty_hangup(tty);
+#else
+ tty_hard_SAK(tty);
#endif
}
@@ -1872,6 +1896,8 @@
*/
void do_SAK(struct tty_struct *tty)
{
+ if (!tty)
+ return;
PREPARE_TQUEUE(&tty->SAK_tq, __do_SAK, tty);
schedule_task(&tty->SAK_tq);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] more SAK stuff
@ 2001-07-02 12:16 Andries.Brouwer
2001-07-02 12:33 ` Alan Cox
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Andries.Brouwer @ 2001-07-02 12:16 UTC (permalink / raw)
To: alan, andrewm, torvalds, tytso; +Cc: linux-kernel
Dear Linus, Alan, Ted, Andrew, all:
(i) Andrew - why don't you add yourself to the CREDITS file?
(then I'll find your email address at the first instead of the second attempt)
(ii) Yesterday I complained about the fact that pressing SAK twice
crashes the kernel (because the close from the first time will set
tty->driver_data = 0;
and then on the next press kbd has tty==0 and do_SAK() kills the system).
There is more bad stuff in this 2.4.3 patch:
-void do_SAK( struct tty_struct *tty)
+static void __do_SAK(void *arg)
{
#ifdef TTY_SOFT_SAK
tty_hangup(tty);
#else
+ struct tty_struct *tty = arg;
Clearly, if TTY_SOFT_SAK is defined this will not compile
(or, worse, will pick up some global variable tty).
The patch below has yesterdays fix of do_SAK(), and fixes this
compilation problem. I invented a separate inline routine here -
I do not like very long stretches of code inside #ifdef.
More interestingly, it changes the operation of SAK in two ways:
(a) It does less, namely will not kill processes with uid 0.
Ted, any objections?
For example, when syslog has several output streams, and one is
to /dev/tty10, then a SAK typed at /dev/tty10 should not kill syslog,
that is bad for security.
(b) It does more, namely will for the purposes of SAK consider all
VTs equivalent, so that a SAK typed on /dev/tty1 also kills processes
that have an open file descriptor on /dev/tty2.
That is good for security, since many keyboard or console ioctls just
require an open fd for some VT, and this process on tty2 can for example
change the keymap on tty1.
One of the motivations of this patch was that SAK should be able
to kill a "while [ 1 ]; do chvt 21; done", that is the reason
for the keyboard.c fragment.
Ted, please complain if anything is wrong with the way
filp->private_data is used.
Andries
diff -u --recursive --new-file ../linux-2.4.6-pre8/linux/drivers/char/keyboard.c ./linux/drivers/char/keyboard.c
--- ../linux-2.4.6-pre8/linux/drivers/char/keyboard.c Mon Oct 16 21:58:51 2000
+++ ./linux/drivers/char/keyboard.c Mon Jul 2 13:28:09 2001
@@ -506,6 +506,8 @@
* them properly.
*/
+ if (!tty && ttytab && ttytab[0] && ttytab[0]->driver_data)
+ tty = ttytab[0];
do_SAK(tty);
reset_vc(fg_console);
#if 0
diff -u --recursive --new-file ../linux-2.4.6-pre8/linux/drivers/char/tty_io.c ./linux/drivers/char/tty_io.c
--- ../linux-2.4.6-pre8/linux/drivers/char/tty_io.c Sun Jul 1 15:19:26 2001
+++ ./linux/drivers/char/tty_io.c Mon Jul 2 13:27:19 2001
@@ -1818,20 +1818,29 @@
*
* Nasty bug: do_SAK is being called in interrupt context. This can
* deadlock. We punt it up to process context. AKPM - 16Mar2001
+ *
+ * Treat all VTs as a single tty for the purposes of SAK. A process with an
+ * open fd for one VT can do interesting things to all. aeb, 2001-07-02
*/
-static void __do_SAK(void *arg)
+#ifdef CONFIG_VT
+static inline int tty_is_vt(struct tty_struct *tty)
{
-#ifdef TTY_SOFT_SAK
- tty_hangup(tty);
+ return tty ? (tty->driver.type == TTY_DRIVER_TYPE_CONSOLE) : 0;
+}
#else
- struct tty_struct *tty = arg;
+static inline int tty_is_vt(struct tty_struct *tty)
+{
+ return 0;
+}
+#endif
+
+static inline void tty_hard_SAK(struct tty_struct *tty)
+{
struct task_struct *p;
int session;
- int i;
- struct file *filp;
-
- if (!tty)
- return;
+ int i;
+ struct file *filp;
+
session = tty->session;
if (tty->ldisc.flush_buffer)
tty->ldisc.flush_buffer(tty);
@@ -1839,7 +1848,12 @@
tty->driver.flush_buffer(tty);
read_lock(&tasklist_lock);
for_each_task(p) {
+ /* do not kill root processes */
+ if (p->uid == 0)
+ continue;
+ /* all VTs are considered a single tty here */
if ((p->tty == tty) ||
+ (tty_is_vt(tty) && tty_is_vt(p->tty)) ||
((session > 0) && (p->session == session))) {
send_sig(SIGKILL, p, 1);
continue;
@@ -1850,7 +1864,9 @@
for (i=0; i < p->files->max_fds; i++) {
filp = fcheck_files(p->files, i);
if (filp && (filp->f_op == &tty_fops) &&
- (filp->private_data == tty)) {
+ (filp->private_data == tty ||
+ (tty_is_vt(tty) &&
+ tty_is_vt(filp->private_data)))) {
send_sig(SIGKILL, p, 1);
break;
}
@@ -1860,6 +1876,17 @@
task_unlock(p);
}
read_unlock(&tasklist_lock);
+}
+
+static void __do_SAK(void *arg)
+{
+ struct tty_struct *tty = arg;
+ if (!tty) /* impossible */
+ return;
+#ifdef TTY_SOFT_SAK
+ tty_hangup(tty);
+#else
+ tty_hard_SAK(tty);
#endif
}
@@ -1872,6 +1899,8 @@
*/
void do_SAK(struct tty_struct *tty)
{
+ if (!tty)
+ return;
PREPARE_TQUEUE(&tty->SAK_tq, __do_SAK, tty);
schedule_task(&tty->SAK_tq);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-02 12:16 Andries.Brouwer
@ 2001-07-02 12:33 ` Alan Cox
2001-07-02 19:10 ` Hua Zhong
2001-07-02 18:57 ` Kain
2001-07-06 22:02 ` David Wagner
2 siblings, 1 reply; 9+ messages in thread
From: Alan Cox @ 2001-07-02 12:33 UTC (permalink / raw)
To: Andries.Brouwer; +Cc: alan, andrewm, torvalds, tytso, linux-kernel
> (a) It does less, namely will not kill processes with uid 0.
> Ted, any objections?
That breaks the security guarantee. Suppose I use a setuid app to confuse
you into doing something ?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-02 12:33 ` Alan Cox
@ 2001-07-02 19:10 ` Hua Zhong
2001-07-03 22:00 ` Rob Landley
0 siblings, 1 reply; 9+ messages in thread
From: Hua Zhong @ 2001-07-02 19:10 UTC (permalink / raw)
To: Alan Cox; +Cc: Andries.Brouwer, andrewm, torvalds, tytso, linux-kernel
-> From Alan Cox <alan@lxorguk.ukuu.org.uk> :
> > (a) It does less, namely will not kill processes with uid 0.
> > Ted, any objections?
>
> That breaks the security guarantee. Suppose I use a setuid app to confuse
> you into doing something ?
a setuid app only changes euid, doesn't it?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-02 19:10 ` Hua Zhong
@ 2001-07-03 22:00 ` Rob Landley
2001-07-06 1:45 ` Albert D. Cahalan
0 siblings, 1 reply; 9+ messages in thread
From: Rob Landley @ 2001-07-03 22:00 UTC (permalink / raw)
To: Hua Zhong, Alan Cox
Cc: Andries.Brouwer, andrewm, torvalds, tytso, linux-kernel
On Monday 02 July 2001 15:10, Hua Zhong wrote:
> -> From Alan Cox <alan@lxorguk.ukuu.org.uk> :
> > > (a) It does less, namely will not kill processes with uid 0.
> > > Ted, any objections?
> >
> > That breaks the security guarantee. Suppose I use a setuid app to confuse
> > you into doing something ?
>
> a setuid app only changes euid, doesn't it?
Yup. And you'd be amazed how many fun little user mode things were either
never tested with the suid bit or obstinately refuse to run for no good
reason. (Okay, I made something like a sudo script. It's in a directory
that non-root users can't access and I'm being as careful as I know how to
be, but I've got a cgi that needs root access to query/set system and network
configuration.)
Off the top of my head, fun things you can't do suid root:
The samba adduser command. (But I CAN edit the smb.passwd file directly,
which got me around this.)
su without password (understandable, implementation detail. It's always
suid, being run by somebody other than root is how it knows when it NEEDS to
ask for a password. But when I want to DROP root privelidges... Wound up
making "suid-to" to do it.)
ps (What the...? Worked in Red Hat 7, but not in suse 7.1. Huh? "suid-to
apache ps ax" works fine, though...)
dhcpcd (I patched it and yelled at the maintainer of this months ago, should
be fixed now. But a clear case of checking uid when he meant euid, which is
outright PERVASIVE...).
I keep bumping into more of these all the time. Often it's fun little
warnings "you shouldn't have the suid bit on this executable", which is
frustrating 'cause I haven't GOT the suid bit on that executable, it
inherited it from its parent process, which DOES explicitly set the $PATH and
blank most of the environment variables and other fun stuff...)
By the way, anybody who knows why samba goes postal if you change the
hostname of the box while it's running, please explain it to me. It's happy
once HUPed, then again it execs itself. (Not nmbd. smbd. Why does it CARE?
And sshd has the most amazing timeouts if it can't do a reverse dns lookup
on the incoming IP, even if I tell it not to log!)
Apache has a similar problem, and HUP-ing it interrupts in-progress
transfers, which could be very large files, 'cause it execs itself. I made
that happy by telling it its host name was a dot notation IP address,
although that does mean that logging into a password protected web page using
the host name forces you to log in twice (again when it switches you to
http://1.2.3.4/blah...)
Fun, isn't it? :)
Alan's right. We DO need a rant tag.
Rob
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-03 22:00 ` Rob Landley
@ 2001-07-06 1:45 ` Albert D. Cahalan
0 siblings, 0 replies; 9+ messages in thread
From: Albert D. Cahalan @ 2001-07-06 1:45 UTC (permalink / raw)
To: landley; +Cc: linux-kernel
Rob Landley writes:
> Off the top of my head, fun things you can't do suid root:
...
> ps (What the...? Worked in Red Hat 7, but not in suse 7.1.
> Huh? "suid-to apache ps ax" works fine, though...)
The ps command used to require setuid root. People would set the
bit by habit.
> I keep bumping into more of these all the time. Often it's fun
> little warnings "you shouldn't have the suid bit on this
> executable", which is frustrating 'cause I haven't GOT the suid bit
> on that executable, it inherited it from its parent process, which
> DOES explicitly set the $PATH and blank most of the environment
> variables and other fun stuff...)
Oh, cry me a river. You can set the RUID, EUID, SUID, and FUID
in that same parent process or after you fork().
Since you didn't set all the UID values, I have to wonder what
else you forgot to do. Maybe you shouldn't be messing with
setuid programming.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-02 12:16 Andries.Brouwer
2001-07-02 12:33 ` Alan Cox
@ 2001-07-02 18:57 ` Kain
2001-07-06 22:02 ` David Wagner
2 siblings, 0 replies; 9+ messages in thread
From: Kain @ 2001-07-02 18:57 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 419 bytes --]
On Mon, Jul 02, 2001 at 02:16:36PM +0200, Andries.Brouwer@cwi.nl wrote:
> (a) It does less, namely will not kill processes with uid 0.
> Ted, any objections?
What if you have a process running wild as uid 0 (i.e. X server gone bad) that you need to die *right now*?
--
"Don't dwell on reality; it will only keep you from greatness."
-- Randall McBride, Jr.
**
Evil Genius
Bryon Roche, Kain <kain@kain.org>
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] more SAK stuff
2001-07-02 12:16 Andries.Brouwer
2001-07-02 12:33 ` Alan Cox
2001-07-02 18:57 ` Kain
@ 2001-07-06 22:02 ` David Wagner
2 siblings, 0 replies; 9+ messages in thread
From: David Wagner @ 2001-07-06 22:02 UTC (permalink / raw)
To: linux-kernel
>More interestingly, it changes the operation of SAK in two ways:
>(a) It does less, namely will not kill processes with uid 0.
I think this is bad for security.
(I assume you meant euid 0, not ruid 0. Using the real uid
for access control decisions is a very odd thing to do.)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2001-07-06 22:05 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-02 12:49 [PATCH] more SAK stuff Andries.Brouwer
-- strict thread matches above, loose matches on Subject: below --
2001-07-02 13:03 Andries.Brouwer
2001-07-02 12:16 Andries.Brouwer
2001-07-02 12:33 ` Alan Cox
2001-07-02 19:10 ` Hua Zhong
2001-07-03 22:00 ` Rob Landley
2001-07-06 1:45 ` Albert D. Cahalan
2001-07-02 18:57 ` Kain
2001-07-06 22:02 ` David Wagner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).