Skip to contentSkip to conversation

signal: don't silently convert SI_USER signals to non-current pidfd

PATCH In review Jann Horn 3 participants 8 messages Mar 30, 2019 – Apr 17, 2019

lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 signal: don't silently convert SI_USER signals to non-current pidfd

The current sys_pidfd_send_signal() silently turns signals with explicit SI_USER context that are sent to non-current tasks into signals with kernel-generated siginfo.
This is unlike do_rt_sigqueueinfo(), which returns -EPERM in this case. If a user actually wants to send a signal with kernel-provided siginfo, they can do that with pidfd_send_signal(pidfd, sig, NULL, 0); so allowing this case is unnecessary.

Instead of silently replacing the siginfo, just bail out with an error; this is consistent with other interfaces and avoids special-casing behavior based on security checks.

Fixes 3eb39f47934f ("signal: add pidfd_send_signal() syscall")
---
 kernel/signal.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
kernel/signal.c +4 -9
index b7953934aa99..f98448cf2def 100644
@@ -3605,16 +3605,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
 		if (unlikely(sig != kinfo.si_signo))
 			goto err;
 
+		/* Only allow sending arbitrary signals to yourself. */
+		ret = -EPERM;
 		if ((task_pid(current) != pid) &&
-		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {
-			/* Only allow sending arbitrary signals to yourself. */
-			ret = -EPERM;
-			if (kinfo.si_code != SI_USER)
-				goto err;
-
-			/* Turn this into a regular kill signal. */
-			prepare_kill_siginfo(sig, &kinfo);
-		}
+		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
+			goto err;
 	} else {
 		prepare_kill_siginfo(sig, &kinfo);
 	}
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jann Horn

The current sys_pidfd_send_signal() silently turns signals with explicit SI_USER context that are sent to non-current tasks into signals with kernel-generated siginfo.
This is unlike do_rt_sigqueueinfo(), which returns -EPERM in this case. If a user actually wants to send a signal with kernel-provided siginfo, they can do that with pidfd_send_signal(pidfd, sig, NULL, 0); so allowing this case is unnecessary.

Quoted 6 lines

Instead of silently replacing the siginfo, just bail out with an error; this is consistent with other interfaces and avoids special-casing behavior based on security checks.

Fixes 3eb39f47934f ("signal: add pidfd_send_signal() syscall")

As discussed in
https://lore.kernel.org/lkml/[email protected]
targeting this for a 5.1 rc.

Quoted 32 lines
---
 kernel/signal.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
kernel/signal.c +4 -9
index b7953934aa99..f98448cf2def 100644
@@ -3605,16 +3605,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
 		if (unlikely(sig != kinfo.si_signo))
 			goto err;
 
+		/* Only allow sending arbitrary signals to yourself. */
+		ret = -EPERM;
 		if ((task_pid(current) != pid) &&
-		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {
-			/* Only allow sending arbitrary signals to yourself. */
-			ret = -EPERM;
-			if (kinfo.si_code != SI_USER)
-				goto err;
-
-			/* Turn this into a regular kill signal. */
-			prepare_kill_siginfo(sig, &kinfo);
-		}
+		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
+			goto err;
 	} else {
 		prepare_kill_siginfo(sig, &kinfo);
 	}
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
#2 lore raw
In reply to Jann Horn
Quoted 11 lines · Jann Horn
kernel/signal.c +2 -1
@@ -3605,16 +3605,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
 		if (unlikely(sig != kinfo.si_signo))
 			goto err;
 
+		/* Only allow sending arbitrary signals to yourself. */
+		ret = -EPERM;
 		if ((task_pid(current) != pid) &&
-		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {

kernel/signal.c SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · line 3612

Quoted 10 lines
kernel/signal.c +2 -8
-			/* Only allow sending arbitrary signals to yourself. */
-			ret = -EPERM;
-			if (kinfo.si_code != SI_USER)
-				goto err;
-
-			/* Turn this into a regular kill signal. */
-			prepare_kill_siginfo(sig, &kinfo);
-		}
+		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
+			goto err;

ACK.

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Oleg.

#3 lore raw
Quoted 8 lines · Oleg Nesterov
Quoted 7 lines · Jann Horn
kernel/signal.c +0 -0
@@ -3605,16 +3605,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
 		if (unlikely(sig != kinfo.si_signo))
 			goto err;
 
Quoted 17 lines
Quoted 4 lines
kernel/signal.c +2 -1
+		/* Only allow sending arbitrary signals to yourself. */
+		ret = -EPERM;
 		if ((task_pid(current) != pid) &&
-		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {

kernel/signal.c SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · line 3612

Quoted 10 lines
kernel/signal.c +2 -8
-			/* Only allow sending arbitrary signals to yourself. */
-			ret = -EPERM;
-			if (kinfo.si_code != SI_USER)
-				goto err;
-
-			/* Turn this into a regular kill signal. */
-			prepare_kill_siginfo(sig, &kinfo);
-		}
+		    (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL))
+			goto err;

ACK.

Sorry Oleg. I missed that message somehow.

Quoted 5 lines

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Yes, that's why this was added. I would leave it in exactly because of checkpoint/restart. I have sympathies for "this [...] project by various mad Russians" [1] and it doesn't really hurt us. :)

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=099469502f62fbe0d7e4f0b83a2f22538367f734

Christian

#4 lore raw
Quoted 10 lines · Christian Brauner
Quoted 5 lines · Oleg Nesterov

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Yes, that's why this was added. I would leave it in exactly because of checkpoint/restart.

I don't understand...

c/r doesn't need this "feature" in pidfd_send_signal(), so it can be removed. But,

Quoted 2 lines

I have sympathies for "this [...] project by various mad Russians" [1] and it doesn't really hurt us. :)

I won't argue, I agree it doesn't hurt and looks consistent with sys_rt_sigqueueinfo.

Oleg.

#5 lore raw
Quoted 9 lines · Oleg Nesterov
Quoted 8 lines · Christian Brauner
Quoted 5 lines · Oleg Nesterov

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Quoted 7 lines
Quoted 2 lines

Yes, that's why this was added. I would leave it in exactly because of checkpoint/restart.

I don't understand...

c/r doesn't need this "feature" in pidfd_send_signal(), so it can be removed. But,

Just out of curiosity: in what sense? They don't need it since they have other ways of doing this or they *can't* use it for some other reason I'm not seeing?

Christian

#6 lore raw
Quoted 14 lines · Christian Brauner
Quoted 12 lines · Oleg Nesterov
Quoted 10 lines · Christian Brauner
Quoted 5 lines · Oleg Nesterov

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Yes, that's why this was added. I would leave it in exactly because of checkpoint/restart.

Quoted 7 lines
Quoted 4 lines

I don't understand...

c/r doesn't need this "feature" in pidfd_send_signal(), so it can be removed. But,

Just out of curiosity: in what sense? They don't need it since they have other ways of doing this

Yes. The restarting process needs to "restore" the pending signals, including the signals with si_code >= 0. It does this using tgsigqueueinfo() and that is why we allow this if the signal sent to itself.

So criu simply doesn't need pidfd_send_signal() to do this. And at the same time,

Quoted 1 line

or they *can't* use it for some other reason

Yes again. pidfd_send_signal() does kill_pid_info(), so it can't be used to restore the "per-thread" task->pending signals.

Oleg.

#7 lore raw
Quoted 27 lines · Oleg Nesterov
Quoted 14 lines · Christian Brauner
Quoted 12 lines · Oleg Nesterov
Quoted 10 lines · Christian Brauner
Quoted 5 lines · Oleg Nesterov

but perhaps it should always fail, even if task_pid(current) == pid.

sys_rt_sigqueueinfo() allows to send any siginfo to yourself, but this is only needed for checkpoint/restart.

Yes, that's why this was added. I would leave it in exactly because of checkpoint/restart.

Quoted 7 lines
Quoted 4 lines

I don't understand...

c/r doesn't need this "feature" in pidfd_send_signal(), so it can be removed. But,

Just out of curiosity: in what sense? They don't need it since they have other ways of doing this

Yes. The restarting process needs to "restore" the pending signals, including the signals with si_code >= 0. It does this using tgsigqueueinfo() and that is why we allow this if the signal sent to itself.

Quoted 6 lines

So criu simply doesn't need pidfd_send_signal() to do this. And at the same time,

Quoted 1 line

or they *can't* use it for some other reason

Yes again. pidfd_send_signal() does kill_pid_info(), so it can't be used to restore the "per-thread" task->pending signals.

In the future pidfd_send_signal() will gain the flag PIDFD_SIGNAL_THREAD. Jann and I already have a patch for this but we're holding off until the need arises.

Christian