* [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
@ 2010-05-17 19:54 Oleg Nesterov
2010-05-18 1:25 ` Roland McGrath
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Oleg Nesterov @ 2010-05-17 19:54 UTC (permalink / raw)
To: Andrew Morton
Cc: Andrew Tridgell, David Howells, Eric Paris, Jakub Jelinek,
James Morris, Roland McGrath, Stephen Smalley, linux-kernel
Andrew Tridgell reports that aio_read(SIGEV_SIGNAL) can fail if the
the notification from the helper thread races with setresuid(), see
http://samba.org/~tridge/junkcode/aio_uid.c
This happens because check_kill_permission() doesn't allow to send
a signal to the task with the different cred->xids. But there is no
any security reason to check ->cred's when the task sends a signal
(private or group-wide) to its sub-thread. Whatever we do, any thread
can bypass all security checks and send SIGKILL to all threads, or
it can block a signal SIG and do kill(gettid(), SIG) to deliver this
signal to another sub-thread. Not to mention that CLONE_THREAD implies
CLONE_VM.
Change check_kill_permission() to avoid the credentials check when
the sender and the target are from the same thread group.
Also, move "cred = current_cred()" down to avoid calling get_current()
twice.
Note: David Howells pointed out we could relax this even more, the
CLONE_SIGHAND (without CLONE_THREAD) case probably does not need
these checks too.
Reported-by: Andrew Tridgell <tridge@samba.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- 34-rc1/kernel/signal.c~CKP_CK_STG 2010-05-09 21:09:31.000000000 +0200
+++ 34-rc1/kernel/signal.c 2010-05-17 17:02:09.000000000 +0200
@@ -642,7 +642,7 @@ static inline bool si_fromuser(const str
static int check_kill_permission(int sig, struct siginfo *info,
struct task_struct *t)
{
- const struct cred *cred = current_cred(), *tcred;
+ const struct cred *cred, *tcred;
struct pid *sid;
int error;
@@ -656,8 +656,10 @@ static int check_kill_permission(int sig
if (error)
return error;
+ cred = current_cred();
tcred = __task_cred(t);
- if ((cred->euid ^ tcred->suid) &&
+ if (!same_thread_group(current, t) &&
+ (cred->euid ^ tcred->suid) &&
(cred->euid ^ tcred->uid) &&
(cred->uid ^ tcred->suid) &&
(cred->uid ^ tcred->uid) &&
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-17 19:54 [PATCH] signals: check_kill_permission: don't check creds if same_thread_group() Oleg Nesterov
@ 2010-05-18 1:25 ` Roland McGrath
2010-05-18 8:55 ` David Howells
2010-05-20 19:42 ` Andrew Morton
2 siblings, 0 replies; 8+ messages in thread
From: Roland McGrath @ 2010-05-18 1:25 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Andrew Tridgell, David Howells, Eric Paris,
Jakub Jelinek, James Morris, Stephen Smalley, linux-kernel
Acked-by: Roland McGrath <roland@redhat.com>
I concur that there is no real security benefit from checking uids for any
CLONE_VM case. But there is also no reason to change the old behavior in
this corner for any case but CLONE_THREAD.
Thanks,
Roland
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-17 19:54 [PATCH] signals: check_kill_permission: don't check creds if same_thread_group() Oleg Nesterov
2010-05-18 1:25 ` Roland McGrath
@ 2010-05-18 8:55 ` David Howells
2010-05-18 13:39 ` Oleg Nesterov
2010-05-20 19:42 ` Andrew Morton
2 siblings, 1 reply; 8+ messages in thread
From: David Howells @ 2010-05-18 8:55 UTC (permalink / raw)
To: Oleg Nesterov
Cc: dhowells, Andrew Morton, Andrew Tridgell, Eric Paris,
Jakub Jelinek, James Morris, Roland McGrath, Stephen Smalley,
linux-kernel
Oleg Nesterov <oleg@redhat.com> wrote:
> Also, move "cred = current_cred()" down to avoid calling get_current()
> twice.
I don't see what you mean by this. same_thread_group() doesn't call
current_cred(), so why this change?
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-18 8:55 ` David Howells
@ 2010-05-18 13:39 ` Oleg Nesterov
2010-05-18 13:50 ` David Howells
0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2010-05-18 13:39 UTC (permalink / raw)
To: David Howells
Cc: Andrew Morton, Andrew Tridgell, Eric Paris, Jakub Jelinek,
James Morris, Roland McGrath, Stephen Smalley, linux-kernel
On 05/18, David Howells wrote:
>
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > Also, move "cred = current_cred()" down to avoid calling get_current()
> > twice.
>
> I don't see what you mean by this. same_thread_group() doesn't call
> current_cred(), so why this change?
Yes, but both current_cred() and same_thread_group(current, t) call
get_current(), and gcc doesn't cache the result because we call
audit_signal_info() in between.
In fact, initially I was going to send the patch below, but then
decided to make a more simple change.
Oleg.
--- x/kernel/signal.c
+++ x/kernel/signal.c
@@ -642,8 +642,6 @@ static inline bool si_fromuser(const str
static int check_kill_permission(int sig, struct siginfo *info,
struct task_struct *t)
{
- const struct cred *cred = current_cred(), *tcred;
- struct pid *sid;
int error;
if (!valid_signal(sig))
@@ -656,23 +654,29 @@ static int check_kill_permission(int sig
if (error)
return error;
- tcred = __task_cred(t);
- if ((cred->euid ^ tcred->suid) &&
- (cred->euid ^ tcred->uid) &&
- (cred->uid ^ tcred->suid) &&
- (cred->uid ^ tcred->uid) &&
- !capable(CAP_KILL)) {
- switch (sig) {
- case SIGCONT:
- sid = task_session(t);
- /*
- * We don't return the error if sid == NULL. The
- * task was unhashed, the caller must notice this.
- */
- if (!sid || sid == task_session(current))
- break;
- default:
- return -EPERM;
+ if (!same_thread_group(current, t)) {
+ const struct cred *cred = current_cred();
+ const struct cred *tcred = __task_cred(t);
+ struct pid *sid;
+
+ if ((cred->euid ^ tcred->suid) &&
+ (cred->euid ^ tcred->uid) &&
+ (cred->uid ^ tcred->suid) &&
+ (cred->uid ^ tcred->uid) &&
+ !capable(CAP_KILL)) {
+ switch (sig) {
+ case SIGCONT:
+ sid = task_session(t);
+ /*
+ * We don't return the error if sid == NULL.
+ * The task was unhashed, the caller must
+ * notice this.
+ */
+ if (!sid || sid == task_session(current))
+ break;
+ default:
+ return -EPERM;
+ }
}
}
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-18 13:39 ` Oleg Nesterov
@ 2010-05-18 13:50 ` David Howells
2010-05-18 14:08 ` Oleg Nesterov
0 siblings, 1 reply; 8+ messages in thread
From: David Howells @ 2010-05-18 13:50 UTC (permalink / raw)
To: Oleg Nesterov
Cc: dhowells, Andrew Morton, Andrew Tridgell, Eric Paris,
Jakub Jelinek, James Morris, Roland McGrath, Stephen Smalley,
linux-kernel
Oleg Nesterov <oleg@redhat.com> wrote:
> Yes, but both current_cred() and same_thread_group(current, t) call
> get_current(), and gcc doesn't cache the result because we call
> audit_signal_info() in between.
Sorry, yes. I was reading get_current() as current_cred() for some reason.
However, you are _still_ calling get_current() twice... So that bit of your
changelog isn't really correct.
In fact, get_current() should be __attribute_const__ since it can't change
whilst you're looking at it, except within switch_to(), probably in a piece of
assembly code, so gcc should be free to cache it as long as it likes.
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-18 13:50 ` David Howells
@ 2010-05-18 14:08 ` Oleg Nesterov
0 siblings, 0 replies; 8+ messages in thread
From: Oleg Nesterov @ 2010-05-18 14:08 UTC (permalink / raw)
To: David Howells
Cc: Andrew Morton, Andrew Tridgell, Eric Paris, Jakub Jelinek,
James Morris, Roland McGrath, Stephen Smalley, linux-kernel
On 05/18, David Howells wrote:
>
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > Yes, but both current_cred() and same_thread_group(current, t) call
> > get_current(), and gcc doesn't cache the result because we call
> > audit_signal_info() in between.
>
> Sorry, yes. I was reading get_current() as current_cred() for some reason.
>
> However, you are _still_ calling get_current() twice... So that bit of your
> changelog isn't really correct.
If I read kernel/signal.s correctly - no.
Well, yes, get_current() is still called twice inside check_kill_permission().
But this is because we have audit_signal_info()->audit_dummy_context() which
uses current too.
But "cred = current_cred()" and same_thread_group(current, t) read
gs:current_task only once, so this change really helps (although the
optimization is very minor, of course).
> In fact, get_current() should be __attribute_const__ since it can't change
> whilst you're looking at it, except within switch_to(), probably in a piece of
> assembly code, so gcc should be free to cache it as long as it likes.
Agreed! I thought about this many times.
Oleg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-17 19:54 [PATCH] signals: check_kill_permission: don't check creds if same_thread_group() Oleg Nesterov
2010-05-18 1:25 ` Roland McGrath
2010-05-18 8:55 ` David Howells
@ 2010-05-20 19:42 ` Andrew Morton
2010-05-20 20:02 ` Roland McGrath
2 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2010-05-20 19:42 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Tridgell, David Howells, Eric Paris, Jakub Jelinek,
James Morris, Roland McGrath, Stephen Smalley, linux-kernel
On Mon, 17 May 2010 21:54:14 +0200
Oleg Nesterov <oleg@redhat.com> wrote:
> Andrew Tridgell reports that aio_read(SIGEV_SIGNAL) can fail if the
> the notification from the helper thread races with setresuid(), see
> http://samba.org/~tridge/junkcode/aio_uid.c
>
> This happens because check_kill_permission() doesn't allow to send
> a signal to the task with the different cred->xids. But there is no
> any security reason to check ->cred's when the task sends a signal
> (private or group-wide) to its sub-thread. Whatever we do, any thread
> can bypass all security checks and send SIGKILL to all threads, or
> it can block a signal SIG and do kill(gettid(), SIG) to deliver this
> signal to another sub-thread. Not to mention that CLONE_THREAD implies
> CLONE_VM.
>
> Change check_kill_permission() to avoid the credentials check when
> the sender and the target are from the same thread group.
>
> Also, move "cred = current_cred()" down to avoid calling get_current()
> twice.
>
> Note: David Howells pointed out we could relax this even more, the
> CLONE_SIGHAND (without CLONE_THREAD) case probably does not need
> these checks too.
So... which kernel(s) do we think this fix should be merged into?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] signals: check_kill_permission: don't check creds if same_thread_group()
2010-05-20 19:42 ` Andrew Morton
@ 2010-05-20 20:02 ` Roland McGrath
0 siblings, 0 replies; 8+ messages in thread
From: Roland McGrath @ 2010-05-20 20:02 UTC (permalink / raw)
To: Andrew Morton
Cc: Oleg Nesterov, Andrew Tridgell, David Howells, Eric Paris,
Jakub Jelinek, James Morris, Stephen Smalley, linux-kernel
> So... which kernel(s) do we think this fix should be merged into?
I'd say all. The glibc (libpthread) that does set*id across threads has
been in use for a while (2.3.4?), probably in distro's using kernels as old
or older than any active -stable streams. In the race in question, this
kernel bug is breaking valid POSIX application expectations.
Thanks,
Roland
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-05-20 20:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-17 19:54 [PATCH] signals: check_kill_permission: don't check creds if same_thread_group() Oleg Nesterov
2010-05-18 1:25 ` Roland McGrath
2010-05-18 8:55 ` David Howells
2010-05-18 13:39 ` Oleg Nesterov
2010-05-18 13:50 ` David Howells
2010-05-18 14:08 ` Oleg Nesterov
2010-05-20 19:42 ` Andrew Morton
2010-05-20 20:02 ` Roland McGrath
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox