Skip to content

Commit 921cf9f

Browse files
Sukadev Bhattiprolutorvalds
Sukadev Bhattiprolu
authored andcommitted
signals: protect cinit from unblocked SIG_DFL signals
Drop early any SIG_DFL or SIG_IGN signals to container-init from within the same container. But queue SIGSTOP and SIGKILL to the container-init if they are from an ancestor container. Blocked, fatal signals (i.e when SIG_DFL is to terminate) from within the container can still terminate the container-init. That will be addressed in the next patch. Note: To be bisect-safe, SIGNAL_UNKILLABLE will be set for container-inits in a follow-on patch. Until then, this patch is just a preparatory step. Signed-off-by: Sukadev Bhattiprolu <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Roland McGrath <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Cc: Daniel Lezcano <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7978b56 commit 921cf9f

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

kernel/signal.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,21 @@ static int sig_handler_ignored(void __user *handler, int sig)
5555
(handler == SIG_DFL && sig_kernel_ignore(sig));
5656
}
5757

58-
static int sig_task_ignored(struct task_struct *t, int sig)
58+
static int sig_task_ignored(struct task_struct *t, int sig,
59+
int from_ancestor_ns)
5960
{
6061
void __user *handler;
6162

6263
handler = sig_handler(t, sig);
6364

6465
if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) &&
65-
handler == SIG_DFL)
66+
handler == SIG_DFL && !from_ancestor_ns)
6667
return 1;
6768

6869
return sig_handler_ignored(handler, sig);
6970
}
7071

71-
static int sig_ignored(struct task_struct *t, int sig)
72+
static int sig_ignored(struct task_struct *t, int sig, int from_ancestor_ns)
7273
{
7374
/*
7475
* Blocked signals are never ignored, since the
@@ -78,7 +79,7 @@ static int sig_ignored(struct task_struct *t, int sig)
7879
if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
7980
return 0;
8081

81-
if (!sig_task_ignored(t, sig))
82+
if (!sig_task_ignored(t, sig, from_ancestor_ns))
8283
return 0;
8384

8485
/*
@@ -634,7 +635,7 @@ static int check_kill_permission(int sig, struct siginfo *info,
634635
* Returns true if the signal should be actually delivered, otherwise
635636
* it should be dropped.
636637
*/
637-
static int prepare_signal(int sig, struct task_struct *p)
638+
static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns)
638639
{
639640
struct signal_struct *signal = p->signal;
640641
struct task_struct *t;
@@ -718,7 +719,7 @@ static int prepare_signal(int sig, struct task_struct *p)
718719
}
719720
}
720721

721-
return !sig_ignored(p, sig);
722+
return !sig_ignored(p, sig, from_ancestor_ns);
722723
}
723724

724725
/*
@@ -832,7 +833,8 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t,
832833
trace_sched_signal_send(sig, t);
833834

834835
assert_spin_locked(&t->sighand->siglock);
835-
if (!prepare_signal(sig, t))
836+
837+
if (!prepare_signal(sig, t, from_ancestor_ns))
836838
return 0;
837839

838840
pending = group ? &t->signal->shared_pending : &t->pending;
@@ -902,7 +904,15 @@ static int __send_signal(int sig, struct siginfo *info, struct task_struct *t,
902904
static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
903905
int group)
904906
{
905-
return __send_signal(sig, info, t, group, 0);
907+
int from_ancestor_ns = 0;
908+
909+
#ifdef CONFIG_PID_NS
910+
if (!is_si_special(info) && SI_FROMUSER(info) &&
911+
task_pid_nr_ns(current, task_active_pid_ns(t)) <= 0)
912+
from_ancestor_ns = 1;
913+
#endif
914+
915+
return __send_signal(sig, info, t, group, from_ancestor_ns);
906916
}
907917

908918
int print_fatal_signals;
@@ -1336,7 +1346,7 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
13361346
goto ret;
13371347

13381348
ret = 1; /* the signal is ignored */
1339-
if (!prepare_signal(sig, t))
1349+
if (!prepare_signal(sig, t, 0))
13401350
goto out;
13411351

13421352
ret = 0;

0 commit comments

Comments
 (0)