Skip to contentSkip to conversation

signal: avoid shared siginfo namespace rewrites

PATCH Superseded Bradley Morgan 5 participants 21 messages Jun 22 – Jul 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 signal: avoid shared siginfo namespace rewrites

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
---
 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +4 -0
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · Bradley Morgan

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Hmm... I'll re-read this change tomorrow after sleep, but I am almost sure you are you are right anyway...

I am wondering if we can conditionalize the "swap(rewritten, info)" logic with your patch, most probably this makes no sense...

May I suggest another change on top of your fix? Make the "kernel_siginfo *info" arg of send_signal_locked() "const". To make it more clear. Yes, the signature of has_si_pid_and_uid() should be changed too. Up to you.

Thanks,

Oleg.

Quoted 34 lines

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
---
 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +4 -1
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
--

2.53.0

#2 lore raw
Quoted 8 lines · Oleg Nesterov
Quoted 4 lines · Bradley Morgan

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Hmm... I'll re-read this change tomorrow after sleep, but I am almost sure you are you are right anyway...

Sure! Feel free to take ur time!

Quoted 8 lines

I am wondering if we can conditionalize the "swap(rewritten, info)" logic with your patch, most probably this makes no sense...

May I suggest another change on top of your fix? Make the "kernel_siginfo *info"
arg of send_signal_locked() "const". To make it more clear. Yes, the signature
of has_si_pid_and_uid() should be changed too. Up to you.

I'll do it. I don't mind.

Quoted 32 lines

Thanks,

Oleg.

Quoted 3 lines

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and

si_uid")

kernel/signal.c static inline bool has_si_pid_and_uid(struct

Quoted 11 lines
---
 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +0 -0
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct

kernel_siginfo *info)

kernel/signal.c int send_signal_locked(int sig, struct

Quoted 8 lines
kernel/signal.c +1 -0
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct

kernel_siginfo *info,

Quoted 3 lines
kernel/signal.c +0 -0
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
Quoted 11 lines
Quoted 9 lines
kernel/signal.c +3 -1
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
--

2.53.0

Thanks!

#3 lore raw

PATCH v2 1/2 signal: avoid shared siginfo namespace rewrites

In reply to Bradley Morgan

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")

---
Changes since v1:
- No code changes in this patch.
- Add patch 2 for Oleg's const suggestion.
- Link to v1:
https://lore.kernel.org/all/[email protected]/T/#m89955d13f10807c316d34cc76680d690a2d95b31

 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +4 -0
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
Signature · 1 line
2.53.0
Acked-by on v2 1/2
#4 lore raw

Add Eric.

OK, I agree, it seems we need a simple fix.

-------------------------------------------------------------------------
But let me add some "offtopic" notes... Why do we actually need this fix?

kill_something_info(). But at first glance sys_kill/kill_something_info can simply use SEND_SIG_NOINFO? If yes, this makes sense anyway, I will re-check...

do_pidfd_send_signal(PIDFD_SIGNAL_PROCESS_GROUP) allows to call kill_pgrp_info() if si_code < 0... Not that I think this would be better, but we could move this "rewrite" logic into __kill_pgrp_info()...

Anything else needs this change? Most probably yes, but after the quick grep I don't see other group senders with !is_si_special(info).

Eric, what do you think?

Oleg.

Quoted 45 lines · Bradley Morgan

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")

---
Changes since v1:
- No code changes in this patch.
- Add patch 2 for Oleg's const suggestion.
- Link to v1:
https://lore.kernel.org/all/[email protected]/T/#m89955d13f10807c316d34cc76680d690a2d95b31

 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +4 -1
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
--

2.53.0

#5 lore raw
Quoted 13 lines · Oleg Nesterov

Add Eric.

OK, I agree, it seems we need a simple fix.

-------------------------------------------------------------------------
But let me add some "offtopic" notes... Why do we actually need this fix?

kill_something_info(). But at first glance sys_kill/kill_something_info can simply use SEND_SIG_NOINFO? If yes, this makes sense anyway, I will re-check...

Quoted 8 lines

do_pidfd_send_signal(PIDFD_SIGNAL_PROCESS_GROUP) allows to call kill_pgrp_info() if si_code < 0... Not that I think this would be better, but we could move this "rewrite" logic into __kill_pgrp_info()...

Anything else needs this change? Most probably yes, but after the quick grep I don't see other group senders with !is_si_special(info).

Eric, what do you think?

So I think tracing the basic kill syscall is interesting.

It uses an explicit siginfo. It does that so it can choose between setting si_code to SI_TKILL and SI_USER.

If the signal number is -1 it sends to every process in the system (or at least the pid namespace).

That will require translation.

So either we need to add another special siginfo value to handle SI_TKILL, or we need to fix this the way that was suggested.

I suspect just fixing send_signal_locked looks the easiest, especially if you make the siginfo parameter const.

It would likely help to have a self test that detects the problem before this is fixed and passes afterwards so we have some chance of detecting if someone makes a similar mistake in the future.

Eric

#6 lore raw
Quoted 15 lines · Eric W. Biederman
Quoted 12 lines · Oleg Nesterov

Add Eric.

OK, I agree, it seems we need a simple fix.

-------------------------------------------------------------------------
But let me add some "offtopic" notes... Why do we actually need this fix?

kill_something_info(). But at first glance sys_kill/kill_something_info can simply use SEND_SIG_NOINFO? If yes, this makes sense anyway, I will re-check...

....

Quoted 9 lines

So I think tracing the basic kill syscall is interesting.

It uses an explicit siginfo. It does that so it can choose between setting si_code to SI_TKILL and SI_USER.

If the signal number is -1 it sends to every process in the system (or at least the pid namespace).

That will require translation.

Most probably I was wrong, I didn't try to re-check yet.

But at first glance kill_something_info() never use SI_TKILL, and __send_signal_locked(SEND_SIG_NOINFO) will do the necessary translation, in this case si_pid/si_uid are the current task's pid/uid.

But again, I am not sure. Didn't have to to actually look at this code.

Quoted 2 lines

I suspect just fixing send_signal_locked looks the easiest, especially if you make the siginfo parameter const.

Yes, agreed, and I have already acked this patch.

I think we can improve this unconditional rewrite later, on top of this fix.

Oleg.

#7 lore raw
Quoted 44 lines · Oleg Nesterov
Quoted 10 lines · Eric W. Biederman
Quoted 7 lines · Oleg Nesterov

Add Eric.

OK, I agree, it seems we need a simple fix.

-------------------------------------------------------------------------

Quoted 1 line
Quoted 1 line

But let me add some "offtopic" notes... Why do we actually need this

fix?

Quoted 2 lines
Quoted 2 lines

kill_something_info(). But at first glance

sys_kill/kill_something_info

Quoted 1 line
Quoted 1 line

can simply use SEND_SIG_NOINFO? If yes, this makes sense anyway, I

will

Quoted 1 line
Quoted 1 line

re-check...

....

Quoted 9 lines

So I think tracing the basic kill syscall is interesting.

It uses an explicit siginfo. It does that so it can choose between setting si_code to SI_TKILL and SI_USER.

If the signal number is -1 it sends to every process in the system (or at least the pid namespace).

That will require translation.

Most probably I was wrong, I didn't try to re-check yet.

But at first glance kill_something_info() never use SI_TKILL, and __send_signal_locked(SEND_SIG_NOINFO) will do the necessary translation, in this case si_pid/si_uid are the current task's pid/uid.

But again, I am not sure. Didn't have to to actually look at this code.

Quoted 2 lines

I suspect just fixing send_signal_locked looks the easiest, especially if you make the siginfo parameter const.

Quoted 8 lines

Yes, agreed, and I have already acked this patch.

I think we can improve this unconditional rewrite later, on top of this fix.

Oleg.

Hey you two, sorry to impede in your conversation, but could we write your "conflicting" patch over my Patch 2?

It's fine if you don't want to, it kind of kills two birds with one stone.

Thanks!

#8 lore raw
Quoted 5 lines · Bradley Morgan

Hey you two, sorry to impede in your conversation, but could we write your "conflicting" patch over my Patch 2?

It's fine if you don't want to, it kind of kills two birds with one stone.

No, sorry, I don't ;) at least right now. Because I don't really like the changes it adds into send_signal_locked(). But perhaps I didn't read it carefully.

Can we return to it later? There is another reason... Currently I am very busy but I am thinking about another change on top of your 1/2. Something like below. Not sure it makes a lot of sense though.

Eric, do you think this optimization on top of 1/2 makes sense?

Oleg.

int send_signal_locked(int sig, struct kernel_siginfo *info,
struct task_struct *t, enum pid_type type)

{
	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
	struct kernel_siginfo __info;
	bool force = false;

	if (info == SEND_SIG_NOINFO) {
		/* Force if sent from an ancestor pid namespace */
		force = !task_pid_nr_ns(current, task_active_pid_ns(t));
	} else if (info == SEND_SIG_PRIV) {
		/* Don't ignore kernel generated signals */
		force = true;
	} else if (has_si_pid_and_uid(info)) {
		/* SIGKILL and SIGSTOP is special or has ids */
		struct user_namespace *t_user_ns;
#ifdef CONFIG_USER_NS
		rcu_read_lock();
		t_user_ns = task_cred_xxx(t, user_ns);
		if (current_user_ns() != t_user_ns) {
			__info = *info;
			info = &__info;
			kuid_t uid = make_kuid(current_user_ns(), info->si_uid);
			info->si_uid = from_kuid_munged(t_user_ns, uid);
		}
		rcu_read_unlock();
#endif
		/* A kernel generated signal? */
		force = (info->si_code == SI_KERNEL);
#ifdef CONFIG_PID_NS
		/* From an ancestor pid namespace? */
		if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
			if (info != &__info) {
				__info = *info;
				info = &__info;
			}
			info->si_pid = 0;
			force = true;
		}
#endif
	}
	return __send_signal_locked(sig, info, t, type, force);
}
#9 lore raw
In reply to Bradley Morgan
Quoted 5 lines · On Mon, 22 Jun 2026 20:25:08 +0000 Bradley Morgan <[email protected]> wrote:

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Thanks, I'll queue this for 7.3-rc1. I don't see a need to fast-track it into mainline, as 7a0cf094944e is from 2019.

Can someone please send along a paragraph which describes the userspace-visible effects of the bug? I think this is important when proposing a backportable fix. Important for all fixes, really.

I understand that I'm to take no action with "[PATCH v2 2/2] signal:
make send_signal_locked() take const siginfo".

Reviewed-by on v2 1/2
#10 lore raw
In reply to Bradley Morgan
Quoted 9 lines

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
Signature · 1 line
Christian Brauner <[email protected]>
#11 lore raw

PATCH v2 2/2 signal: make send_signal_locked() take const siginfo

In reply to Bradley Morgan

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

---
Changes since v1:
- New patch from Oleg's suggestion.
- Link to Oleg's suggestion:
https://lore.kernel.org/all/[email protected]/T/#m5f8a2d54928efff41de539969b68149e1ec5fca4

 include/linux/signal.h        |  2 +-
 include/trace/events/signal.h |  4 ++--
 kernel/signal.c               | 20 +++++++++++---------
 3 files changed, 14 insertions(+), 12 deletions(-)
include/linux/signal.h +1 -1
index f19816832f05..a1ba8c5973c6 100644
@@ -283,7 +283,7 @@ extern int do_send_sig_info(int sig, struct kernel_siginfo *info,
 				struct task_struct *p, enum pid_type type);
 extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
 			       struct task_struct *p, enum pid_type type);
-extern int send_signal_locked(int sig, struct kernel_siginfo *info,
+extern int send_signal_locked(int sig, const struct kernel_siginfo *info,
 			      struct task_struct *p, enum pid_type type);
 extern int sigprocmask(int, sigset_t *, sigset_t *);
 extern void set_current_blocked(sigset_t *);
include/trace/events/signal.h +2 -2
index 1db7e4b07c01..05a46135ee34 100644
@@ -49,8 +49,8 @@ enum {
  */
 TRACE_EVENT(signal_generate,
 
-	TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task,
-			int group, int result),
+	TP_PROTO(int sig, const struct kernel_siginfo *info,
+		 struct task_struct *task, int group, int result),
 
 	TP_ARGS(sig, info, task, group, result),
 
kernel/signal.c +11 -9
index d72d9be3a992..26e8b8e1d03c 100644
@@ -1037,7 +1037,7 @@ static inline bool legacy_queue(struct sigpending *signals, int sig)
 	return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
 }
 
-static int __send_signal_locked(int sig, struct kernel_siginfo *info,
+static int __send_signal_locked(int sig, const struct kernel_siginfo *info,
 				struct task_struct *t, enum pid_type type, bool force)
 {
 	struct sigpending *pending;
@@ -1154,7 +1154,7 @@ static int __send_signal_locked(int sig, struct kernel_siginfo *info,
 	return ret;
 }
 
-static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
+static inline bool has_si_pid_and_uid(const struct kernel_siginfo *info)
 {
 	bool ret = false;
 	switch (siginfo_layout(info->si_signo, info->si_code)) {
@@ -1178,10 +1178,11 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 	return ret;
 }
 
-int send_signal_locked(int sig, struct kernel_siginfo *info,
+int send_signal_locked(int sig, const struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
 	struct kernel_siginfo rewritten;
+	const struct kernel_siginfo *send_info = info;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1196,26 +1197,27 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		struct user_namespace *t_user_ns;
 
 		rewritten = *info;
-		info = &rewritten;
+		send_info = &rewritten;
 
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
-			kuid_t uid = make_kuid(current_user_ns(), info->si_uid);
-			info->si_uid = from_kuid_munged(t_user_ns, uid);
+			kuid_t uid = make_kuid(current_user_ns(), rewritten.si_uid);
+
+			rewritten.si_uid = from_kuid_munged(t_user_ns, uid);
 		}
 		rcu_read_unlock();
 
 		/* A kernel generated signal? */
-		force = (info->si_code == SI_KERNEL);
+		force = (rewritten.si_code == SI_KERNEL);
 
 		/* From an ancestor pid namespace? */
 		if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
-			info->si_pid = 0;
+			rewritten.si_pid = 0;
 			force = true;
 		}
 	}
-	return __send_signal_locked(sig, info, t, type, force);
+	return __send_signal_locked(sig, send_info, t, type, force);
 }
 
 static void print_fatal_signal(int signr)
Signature · 1 line
2.53.0
#12 lore raw

Re: [PATCH v2 2/2] signal: make send_signal_locked() take const siginfo

Quoted 5 lines · Bradley Morgan

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

Ah, sorry... I only suggested to change the signature of send_signal_locked() and thus has_si_pid_and_uid(). Perhaps a broader change makes sense too, but this conflicts with another (under discussion) series:

PATCH v2 3/3] signal: fix evasion of SA_IMMUTABLE signals
https://lore.kernel.org/all/[email protected]/

Now let me take another look at 1/2 ...

Oleg.

Quoted 112 lines

---
Changes since v1:
- New patch from Oleg's suggestion.
- Link to Oleg's suggestion:
https://lore.kernel.org/all/[email protected]/T/#m5f8a2d54928efff41de539969b68149e1ec5fca4

 include/linux/signal.h        |  2 +-
 include/trace/events/signal.h |  4 ++--
 kernel/signal.c               | 20 +++++++++++---------
 3 files changed, 14 insertions(+), 12 deletions(-)
include/linux/signal.h +1 -1
index f19816832f05..a1ba8c5973c6 100644
@@ -283,7 +283,7 @@ extern int do_send_sig_info(int sig, struct kernel_siginfo *info,
 				struct task_struct *p, enum pid_type type);
 extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
 			       struct task_struct *p, enum pid_type type);
-extern int send_signal_locked(int sig, struct kernel_siginfo *info,
+extern int send_signal_locked(int sig, const struct kernel_siginfo *info,
 			      struct task_struct *p, enum pid_type type);
 extern int sigprocmask(int, sigset_t *, sigset_t *);
 extern void set_current_blocked(sigset_t *);
include/trace/events/signal.h +2 -2
index 1db7e4b07c01..05a46135ee34 100644
@@ -49,8 +49,8 @@ enum {
  */
 TRACE_EVENT(signal_generate,
 
-	TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task,
-			int group, int result),
+	TP_PROTO(int sig, const struct kernel_siginfo *info,
+		 struct task_struct *task, int group, int result),
 
 	TP_ARGS(sig, info, task, group, result),
 
kernel/signal.c +11 -9
index d72d9be3a992..26e8b8e1d03c 100644
@@ -1037,7 +1037,7 @@ static inline bool legacy_queue(struct sigpending *signals, int sig)
 	return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
 }
 
-static int __send_signal_locked(int sig, struct kernel_siginfo *info,
+static int __send_signal_locked(int sig, const struct kernel_siginfo *info,
 				struct task_struct *t, enum pid_type type, bool force)
 {
 	struct sigpending *pending;
@@ -1154,7 +1154,7 @@ static int __send_signal_locked(int sig, struct kernel_siginfo *info,
 	return ret;
 }
 
-static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
+static inline bool has_si_pid_and_uid(const struct kernel_siginfo *info)
 {
 	bool ret = false;
 	switch (siginfo_layout(info->si_signo, info->si_code)) {
@@ -1178,10 +1178,11 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 	return ret;
 }
 
-int send_signal_locked(int sig, struct kernel_siginfo *info,
+int send_signal_locked(int sig, const struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
 	struct kernel_siginfo rewritten;
+	const struct kernel_siginfo *send_info = info;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1196,26 +1197,27 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		struct user_namespace *t_user_ns;
 
 		rewritten = *info;
-		info = &rewritten;
+		send_info = &rewritten;
 
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
-			kuid_t uid = make_kuid(current_user_ns(), info->si_uid);
-			info->si_uid = from_kuid_munged(t_user_ns, uid);
+			kuid_t uid = make_kuid(current_user_ns(), rewritten.si_uid);
+
+			rewritten.si_uid = from_kuid_munged(t_user_ns, uid);
 		}
 		rcu_read_unlock();
 
 		/* A kernel generated signal? */
-		force = (info->si_code == SI_KERNEL);
+		force = (rewritten.si_code == SI_KERNEL);
 
 		/* From an ancestor pid namespace? */
 		if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
-			info->si_pid = 0;
+			rewritten.si_pid = 0;
 			force = true;
 		}
 	}
-	return __send_signal_locked(sig, info, t, type, force);
+	return __send_signal_locked(sig, send_info, t, type, force);
 }
 
 static void print_fatal_signal(int signr)
Signature · 1 line
2.53.0
#13 lore raw

Re: [PATCH v2 2/2] signal: make send_signal_locked() take const siginfo

Quoted 13 lines · Oleg Nesterov
Quoted 5 lines · Bradley Morgan

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

Ah, sorry... I only suggested to change the signature of send_signal_locked()
and thus has_si_pid_and_uid(). Perhaps a broader change makes sense too, but
this conflicts with another (under discussion) series:

Quoted 6 lines

PATCH v2 3/3] signal: fix evasion of SA_IMMUTABLE signals
https://lore.kernel.org/all/[email protected]/

Now let me take another look at 1/2 ...

Oleg.

Aww. My bad.

You may keep this shelved in case :)

Quoted 118 lines
Quoted 6 lines

---
Changes since v1:
- New patch from Oleg's suggestion.
- Link to Oleg's suggestion:

https://lore.kernel.org/all/[email protected]/T/#m5f8a2d54928efff41de539969b68149e1ec5fca4

include/linux/signal.h extern int do_send_sig_info(int sig, struct

Quoted 11 lines
 include/linux/signal.h        |  2 +-
 include/trace/events/signal.h |  4 ++--
 kernel/signal.c               | 20 +++++++++++---------
 3 files changed, 14 insertions(+), 12 deletions(-)
include/linux/signal.h +0 -0
index f19816832f05..a1ba8c5973c6 100644
@@ -283,7 +283,7 @@ extern int do_send_sig_info(int sig, struct

kernel_siginfo *info,

include/linux/signal.h extern int do_send_sig_info(int sig, struct kernel_siginfo *info,

Quoted 5 lines
include/linux/signal.h +1 -1
 				struct task_struct *p, enum pid_type type);
 extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
 			       struct task_struct *p, enum pid_type type);
-extern int send_signal_locked(int sig, struct kernel_siginfo *info,
+extern int send_signal_locked(int sig, const struct kernel_siginfo

*info,

Review

Quoted 4 lines
include/linux/signal.h +0 -0
 			      struct task_struct *p, enum pid_type type);
 extern int sigprocmask(int, sigset_t *, sigset_t *);
 extern void set_current_blocked(sigset_t *);
(quoted diff) +0 -0

b/include/trace/events/signal.h

kernel/signal.c static inline bool legacy_queue(struct sigpending

Quoted 19 lines

index 1db7e4b07c01..05a46135ee34 100644

include/trace/events/signal.h +2 -2
@@ -49,8 +49,8 @@ enum {
  */
 TRACE_EVENT(signal_generate,
 
-	TP_PROTO(int sig, struct kernel_siginfo *info, struct task_struct *task,
-			int group, int result),
+	TP_PROTO(int sig, const struct kernel_siginfo *info,
+		 struct task_struct *task, int group, int result),
 
 	TP_ARGS(sig, info, task, group, result),
 
kernel/signal.c +0 -0
index d72d9be3a992..26e8b8e1d03c 100644
@@ -1037,7 +1037,7 @@ static inline bool legacy_queue(struct sigpending

*signals, int sig)

kernel/signal.c static inline bool legacy_queue(struct sigpending *signals, int sig)

Quoted 5 lines
kernel/signal.c +1 -1
 	return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
 }
 
-static int __send_signal_locked(int sig, struct kernel_siginfo *info,
+static int __send_signal_locked(int sig, const struct kernel_siginfo

*info,

kernel/signal.c static int __send_signal_locked(int sig, struct

Quoted 4 lines
kernel/signal.c +0 -0
 				struct task_struct *t, enum pid_type type, bool force)
 {
 	struct sigpending *pending;
@@ -1154,7 +1154,7 @@ static int __send_signal_locked(int sig, struct

kernel_siginfo *info,

kernel/signal.c static int __send_signal_locked(int sig, struct kernel_siginfo *info,

Quoted 5 lines
kernel/signal.c +1 -1
 	return ret;
 }
 
-static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
+static inline bool has_si_pid_and_uid(const struct kernel_siginfo

*info)

kernel/signal.c static inline bool has_si_pid_and_uid(struct

Quoted 4 lines
kernel/signal.c +0 -0
 {
 	bool ret = false;
 	switch (siginfo_layout(info->si_signo, info->si_code)) {
@@ -1178,10 +1178,11 @@ static inline bool has_si_pid_and_uid(struct

kernel_siginfo *info)

kernel/signal.c int send_signal_locked(int sig, struct

Quoted 13 lines
kernel/signal.c +2 -1
 	return ret;
 }
 
-int send_signal_locked(int sig, struct kernel_siginfo *info,
+int send_signal_locked(int sig, const struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
 	struct kernel_siginfo rewritten;
+	const struct kernel_siginfo *send_info = info;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1196,26 +1197,27 @@ int send_signal_locked(int sig, struct

kernel_siginfo *info,

Quoted 32 lines
kernel/signal.c +7 -6
 		struct user_namespace *t_user_ns;
 
 		rewritten = *info;
-		info = &rewritten;
+		send_info = &rewritten;
 
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
-			kuid_t uid = make_kuid(current_user_ns(), info->si_uid);
-			info->si_uid = from_kuid_munged(t_user_ns, uid);
+			kuid_t uid = make_kuid(current_user_ns(), rewritten.si_uid);
+
+			rewritten.si_uid = from_kuid_munged(t_user_ns, uid);
 		}
 		rcu_read_unlock();
 
 		/* A kernel generated signal? */
-		force = (info->si_code == SI_KERNEL);
+		force = (rewritten.si_code == SI_KERNEL);
 
 		/* From an ancestor pid namespace? */
 		if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
-			info->si_pid = 0;
+			rewritten.si_pid = 0;
 			force = true;
 		}
 	}
-	return __send_signal_locked(sig, info, t, type, force);
+	return __send_signal_locked(sig, send_info, t, type, force);
 }
 
Quoted 6 lines
Quoted 4 lines
kernel/signal.c +0 -0
 static void print_fatal_signal(int signr)
Signature · 1 line
2.53.0

Thanks!

Reviewed-by on v2 2/2
#14 lore raw

Re: [PATCH v2 2/2] signal: make send_signal_locked() take const siginfo

In reply to Bradley Morgan
Quoted 5 lines

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

Signature · 1 line
Christian Brauner <[email protected]>
#15 lore raw

Re: [PATCH v2 2/2] signal: make send_signal_locked() take const siginfo

Just in case, I can't read the code until Wednesday, but...

Quoted 8 lines · Christian Brauner
Quoted 6 lines

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

Agreed, but IIRC this change should be rebased on top of -mm tree (I sent the patch which changes send_signal_locked(), and thanks for your review btw!)

And, again iirc, with that patch "make siginfo const" become really trivial, we only need to add "const" to every "kernel_siginfo *info" in the send_signal_locked()'s callchain.

Oleg.

#16 lore raw

Re: [PATCH v2 2/2] signal: make send_signal_locked() take const siginfo

Quoted 16 lines · Oleg Nesterov

Just in case, I can't read the code until Wednesday, but...

Quoted 8 lines · Christian Brauner
Quoted 6 lines

send_signal_locked() should not change the caller's siginfo. Make that part of the type and keep the local rewrite on its copy.

Agreed, but IIRC this change should be rebased on top of -mm tree (I sent the patch which changes send_signal_locked(), and thanks for your review btw!)

Quoted 8 lines

And, again iirc, with that patch "make siginfo const" become really trivial,
we only need to add "const" to every "kernel_siginfo *info" in the send_signal_locked()'s callchain.

Oleg.

Makes sense, thanks a lot.

Thanks!

Acked-by on v1 1/1
#17 lore raw
In reply to Bradley Morgan

To avoid the confusion, let me reply to V1 again.

IIUC Eric is fine with this change too.

Andrew, can you take this fix please? We will send more changes on top of it.

Quoted 39 lines · Bradley Morgan

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
---
 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +4 -0
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct kernel_siginfo *info,
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
Signature · 1 line
2.53.0
#18 lore raw
Quoted 8 lines · Oleg Nesterov

To avoid the confusion, let me reply to V1 again.

IIUC Eric is fine with this change too.

Andrew, can you take this fix please? We will send more changes on top of it.

Thanks again oleg.

Andrew did reply to V2.

Quoted 34 lines · Bradley Morgan
Quoted 8 lines

send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.

Copy the siginfo before changing it.

Fixes 7a0cf094944e ("signal: Correct namespace fixups of si_pid and

si_uid")

kernel/signal.c static inline bool has_si_pid_and_uid(struct

Quoted 11 lines
---
 kernel/signal.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/signal.c +0 -0
index b9fc7be1a169..d72d9be3a992 100644
@@ -1181,6 +1181,7 @@ static inline bool has_si_pid_and_uid(struct

kernel_siginfo *info)

kernel/signal.c int send_signal_locked(int sig, struct

Quoted 8 lines
kernel/signal.c +1 -0
 int send_signal_locked(int sig, struct kernel_siginfo *info,
 		       struct task_struct *t, enum pid_type type)
 {
+	struct kernel_siginfo rewritten;
 	/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
 	bool force = false;
 
@@ -1194,6 +1195,9 @@ int send_signal_locked(int sig, struct

kernel_siginfo *info,

Quoted 3 lines
kernel/signal.c +0 -0
 		/* SIGKILL and SIGSTOP is special or has ids */
 		struct user_namespace *t_user_ns;
 
Quoted 11 lines
Quoted 9 lines
kernel/signal.c +3 -0
+		rewritten = *info;
+		info = &rewritten;
+
 		rcu_read_lock();
 		t_user_ns = task_cred_xxx(t, user_ns);
 		if (current_user_ns() != t_user_ns) {
Signature · 1 line
2.53.0

Thanks!

#19 lore raw
Quoted 7 lines · Bradley Morgan
Quoted 4 lines · Oleg Nesterov

To avoid the confusion, let me reply to V1 again.

Quoted 8 lines
Quoted 4 lines

IIUC Eric is fine with this change too.

Andrew, can you take this fix please? We will send more changes on top of it.

Thanks again oleg.

Andrew did reply to V2.

OOPS... where? I didn't get any email from him in this thread...

Oleg.

#20 lore raw
Quoted 13 lines · Oleg Nesterov
Quoted 12 lines · Bradley Morgan
Quoted 8 lines · Oleg Nesterov

To avoid the confusion, let me reply to V1 again.

IIUC Eric is fine with this change too.

Andrew, can you take this fix please? We will send more changes on top of it.

Quoted 9 lines
Quoted 3 lines

Thanks again oleg.

Andrew did reply to V2.

OOPS... where? I didn't get any email from him in this thread...

Oleg.

Ahh, it was a off list email, apologies..

I don't read much to the To: field.

My bad.

Thanks!