user namespace: make signal.c respect user namespaces (v5)
ipc/mqueue.c: for __SI_MESQ, convert the uid being sent to recipient's user namespace. (new, thanks Oleg)
__send_signal: convert current's uid to the recipient's user namespace for any siginfo which is not SI_FROMKERNEL (patch from Oleg, thanks again :)
do_notify_parent and do_notify_parent_cldstop: map task's uid to parent's user namespace
ptrace_signal maps parent's uid into current's user namespace before including in signal to current. IIUC Oleg has argued that this shouldn't matter as the debugger will play with it, but it seems like not converting the value currently being set is misleading.
Changelog:
Sep 20: Inspired by Oleg's suggestion, define map_cred_ns() helper to
simplify callers and help make clear what we are translating (which uid into which namespace). Passing the target task would make callers even easier to read, but we pass in user_ns because current_user_ns() != task_cred_xxx(current, user_ns).
Sep 20: As recommended by Oleg, also put task_pid_vnr() under rcu_read_lock
in ptrace_signal().
Sep 23: In send_signal(), detect when (user) signal is coming from an
ancestor or unrelated user namespace. Pass that on to __send_signal, which sets si_uid to 0 or overflowuid if needed.
Oct 12: Base on Oleg's fixup_uid() patch. On top of that, handle all
SI_FROMKERNEL cases at callers, because we can't assume sender is current in those cases.
Nov 10: (mhelsley) rename fixup_uid to more meaningful usern_fixup_signal_uid Nov 10: (akpm) make the !CONFIG_USER_NS case clearer
--- ipc/mqueue.c | 7 ++++++- kernel/signal.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-)
ipc/mqueue.c +6 -1
@@ -32,6 +32,7 @@#include <linux/nsproxy.h> #include <linux/pid.h> #include <linux/ipc_namespace.h> +#include <linux/user_namespace.h> #include <linux/slab.h> #include <net/sock.h>
@@ -543,9 +544,13 @@ static void __do_notify(struct mqueue_inode_info *info) sig_i.si_errno =0 ; sig_i.si_code =SI_MESGQ ; sig_i.si_value = info->notify.sigev_value; +/* map current pid/uid into info->owner's namespaces */ +rcu_read_lock (); sig_i.si_pid =task_tgid_nr_ns (current,ns_of_pid (info->notify_owner)); - sig_i.si_uid =current_uid (); + sig_i.si_uid =user_ns_map_uid (info->user->user_ns, +current_cred (),current_uid ()); +rcu_read_lock ();kill_pid_info (info->notify.sigev_signo, &sig_i, info->notify_owner);
kernel/signal.c +40 -3
80 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 34 lines · Serge E. Hallyn
ipc/mqueue.c: for__SI_MESQ, convert the uid being sent to recipient's user namespace. (new, thanks Oleg)
__send_signal: convert current's uid to the recipient's user namespace for any siginfo which is notSI_FROMKERNEL(patch from Oleg, thanks again :)
do_notify_parentanddo_notify_parent_cldstop: map task's uid to parent's user namespace
ptrace_signalmaps parent's uid into current's user namespace before including in signal to current. IIUC Oleg has argued that this shouldn't matter as the debugger will play with it, but it seems like not converting the value currently being set is misleading.Changelog:
Sep 20: Inspired by Oleg's suggestion, definemap_cred_ns()helper to
simplify callers and help make clear what we are translating (which uid into which namespace). Passing the target task would make callers even easier to read, but we pass inuser_nsbecausecurrent_user_ns()!=task_cred_xxx(current, user_ns).
Sep 20: As recommended by Oleg, also puttask_pid_vnr()underrcu_read_lock
inptrace_signal().
Sep 23: Insend_signal(), detect when (user) signal is coming from an
ancestor or unrelated user namespace. Pass that on to__send_signal, which setssi_uidto 0 or overflowuid if needed.
Oct 12: Base on Oleg'sfixup_uid()patch. On top of that, handle all
SI_FROMKERNELcases at callers, because we can't assume sender is current in those cases.
Nov 10: (mhelsley) renamefixup_uidto more meaningfulusern_fixup_signal_uidNov 10: (akpm) make the !CONFIG_USER_NS case clearer
kernel/signal.c static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, · line 1121
Quoted 5 lines
kernel/signal.c +2
-0@@ -1088,6 +1117,9 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, q->info.si_pid =0 ;break ; } + +userns_fixup_signal_uid (info, t);
There is a small bug here. You want to fixup q->info, not info. Otherwise you might try dereferencing one of the special signals and get a NULL pointer dereference.
Eric
Quoted 4 lines
kernel/signal.c +1
-0+ }else if (!is_si_special (info)) {if (sig >=SIGRTMIN && info->si_code !=SI_USER ) {/*
Quoted 35 lines · Eric W. Biederman
Quoted 32 lines · Serge E. Hallyn
ipc/mqueue.c: for__SI_MESQ, convert the uid being sent to recipient's user namespace. (new, thanks Oleg)
__send_signal: convert current's uid to the recipient's user namespace for any siginfo which is notSI_FROMKERNEL(patch from Oleg, thanks again :)
do_notify_parentanddo_notify_parent_cldstop: map task's uid to parent's user namespace
ptrace_signalmaps parent's uid into current's user namespace before including in signal to current. IIUC Oleg has argued that this shouldn't matter as the debugger will play with it, but it seems like not converting the value currently being set is misleading.Changelog:
Sep 20: Inspired by Oleg's suggestion, definemap_cred_ns()helper to
simplify callers and help make clear what we are translating (which uid into which namespace). Passing the target task would make callers even easier to read, but we pass inuser_nsbecausecurrent_user_ns()!=task_cred_xxx(current, user_ns).
Sep 20: As recommended by Oleg, also puttask_pid_vnr()underrcu_read_lock
inptrace_signal().
Sep 23: Insend_signal(), detect when (user) signal is coming from an
ancestor or unrelated user namespace. Pass that on to__send_signal, which setssi_uidto 0 or overflowuid if needed.
Oct 12: Base on Oleg'sfixup_uid()patch. On top of that, handle all
SI_FROMKERNELcases at callers, because we can't assume sender is current in those cases.
Nov 10: (mhelsley) renamefixup_uidto more meaningfulusern_fixup_signal_uidNov 10: (akpm) make the !CONFIG_USER_NS case clearer
Quoted 10 lines
kernel/signal.c static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, · line 1121
Quoted 6 lines
kernel/signal.c +2
-0@@ -1088,6 +1117,9 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, q->info.si_pid =0 ;break ; } + +userns_fixup_signal_uid (info, t);There is a small bug here. You want to fixup
q->info, not info. Otherwise you might try dereferencing one of the special signals and get a NULL pointer dereference.
Thanks, Eric. Oddly I've not seen this happen in quite a bit of testing with the kernel, but you certainly must be right. I sent out a new patch to fix that.
thanks,
-serge
Quoted 8 lines · Serge E. Hallyn
Quoted 3 lines · Eric W. Biederman
There is a small bug here. You want to fixup
q->info, not info. Otherwise you might try dereferencing one of the special signals and get a NULL pointer dereference.Thanks, Eric. Oddly I've not seen this happen in quite a bit of testing with the kernel, but you certainly must be right. I sent out a new patch to fix that.
You clearly have a different test case than I do.
I managed to trigger the oops within about 5 minutes of just fooling around.
You want to say &q->info not q->info in your updated patch.
Thanks,
Eric
Quoted 7 lines · Eric W. Biederman
Quoted 5 lines · Serge E. Hallyn
Quoted 3 lines · Eric W. Biederman
There is a small bug here. You want to fixup
q->info, not info. Otherwise you might try dereferencing one of the special signals and get a NULL pointer dereference.
Quoted 5 lines
Quoted 3 lines
Thanks, Eric. Oddly I've not seen this happen in quite a bit of testing with the kernel, but you certainly must be right. I sent out a new patch to fix that.
You clearly have a different test case than I do.
I ran a good chunk of ltp... and it passed. I can't explain it.
Quoted 4 lines
I managed to trigger the oops within about 5 minutes of just fooling around.
You want to say
&q->infonotq->infoin your updated patch.
Oh, yes, thanks. Sorry, I shouldn't have sent that one as I wasn't able to compile and test until tonight.
-serge
Quoted 8 lines · Serge Hallyn
Quoted 7 lines · Eric W. Biederman
Quoted 5 lines · Serge E. Hallyn
Quoted 3 lines · Eric W. Biederman
There is a small bug here. You want to fixup
q->info, not info. Otherwise you might try dereferencing one of the special signals and get a NULL pointer dereference.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Thanks, Eric. Oddly I've not seen this happen in quite a bit of testing with the kernel, but you certainly must be right. I sent out a new patch to fix that.
You clearly have a different test case than I do.
I ran a good chunk of ltp... and it passed. I can't explain it.
I guess my test case as mostly dinking around and hitting ctrl-c because something wasn't behaving as I would like.
Still I a tad surprised that ltp doesn't seem to test that one.
Quoted 7 lines
Quoted 4 lines
I managed to trigger the oops within about 5 minutes of just fooling around.
You want to say
&q->infonotq->infoin your updated patch.Oh, yes, thanks. Sorry, I shouldn't have sent that one as I wasn't able to compile and test until tonight.
No problem.
Eric