Skip to contentSkip to conversation

Removal of most do_exit calls

PATCH Applied Eric W. Biederman 22 participants 193 messages Dec 8, 2021 – Mar 29, 2022 2 messages not in the archive Page 2 of 2

Subsystems (62)
lore
Share & tools
lore
#160 lore raw

PATCH 1/8 signal: Make SIGKILL during coredumps an explicit special case

In reply to Eric W. Biederman

Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking it by dumb luck.

Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up.

After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task.

Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress.

Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken.

Sort all of this out by making the coredump special case more special, and perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it.

In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending.

Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal.

Update wait_for_dump_helpers to perform a wait_event_killable wait so that if signal_pending gets set spuriously the wait will not be interrupted unless fatal_signal_pending is true.

I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working.

---
 fs/coredump.c   |  4 ++--
 kernel/signal.c | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/coredump.c +2 -2
index a6b3c196cdef..7b91fb32dbb8 100644
@@ -448,7 +448,7 @@ static void coredump_finish(bool core_dumped)
 static bool dump_interrupted(void)
 {
 	/*
-	 * SIGKILL or freezing() interrupt the coredumping. Perhaps we
+	 * SIGKILL or freezing() interrupted the coredumping. Perhaps we
 	 * can do try_to_freeze() and check __fatal_signal_pending(),
 	 * but then we need to teach dump_write() to restart and clear
 	 * TIF_SIGPENDING.
@@ -471,7 +471,7 @@ static void wait_for_dump_helpers(struct file *file)
 	 * We actually want wait_event_freezable() but then we need
 	 * to clear TIF_SIGPENDING and improve dump_interrupted().
 	 */
-	wait_event_interruptible(pipe->rd_wait, pipe->readers == 1);
+	wait_event_killable(pipe->rd_wait, pipe->readers == 1);
 
 	pipe_lock(pipe);
 	pipe->readers--;
kernel/signal.c +9 -2
index 8272cac5f429..7e305a8ec7c2 100644
@@ -907,8 +907,15 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	sigset_t flush;
 
 	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
-			return sig == SIGKILL;
+		struct core_state *core_state = signal->core_state;
+		if (core_state) {
+			if (sig == SIGKILL) {
+				struct task_struct *dumper = core_state->dumper.task;
+				sigaddset(&dumper->pending.signal, SIGKILL);
+				signal_wake_up(dumper, 1);
+			}
+			return false;
+		}
 		/*
 		 * The process is in the middle of dying, nothing to do.
 		 */
Signature · 1 line
2.29.2
#161 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

14.12.2021 01:53, Eric W. Biederman пишет:

Quoted 86 lines

Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking it by dumb luck.

Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up.

After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task.

Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress.

Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken.

Sort all of this out by making the coredump special case more special, and perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it.

In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending.

Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal.

Update wait_for_dump_helpers to perform a wait_event_killable wait so that if signal_pending gets set spuriously the wait will not be interrupted unless fatal_signal_pending is true.

I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working.

---
 fs/coredump.c   |  4 ++--
 kernel/signal.c | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/coredump.c +2 -2
index a6b3c196cdef..7b91fb32dbb8 100644
@@ -448,7 +448,7 @@ static void coredump_finish(bool core_dumped)
 static bool dump_interrupted(void)
 {
 	/*
-	 * SIGKILL or freezing() interrupt the coredumping. Perhaps we
+	 * SIGKILL or freezing() interrupted the coredumping. Perhaps we
 	 * can do try_to_freeze() and check __fatal_signal_pending(),
 	 * but then we need to teach dump_write() to restart and clear
 	 * TIF_SIGPENDING.
@@ -471,7 +471,7 @@ static void wait_for_dump_helpers(struct file *file)
 	 * We actually want wait_event_freezable() but then we need
 	 * to clear TIF_SIGPENDING and improve dump_interrupted().
 	 */
-	wait_event_interruptible(pipe->rd_wait, pipe->readers == 1);
+	wait_event_killable(pipe->rd_wait, pipe->readers == 1);
 
 	pipe_lock(pipe);
 	pipe->readers--;
kernel/signal.c +2 -2
index 8272cac5f429..7e305a8ec7c2 100644
@@ -907,8 +907,15 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	sigset_t flush;
 
 	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
-			return sig == SIGKILL;
+		struct core_state *core_state = signal->core_state;
+		if (core_state) {

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 921

Quoted 10 lines
kernel/signal.c +7 -0
+			if (sig == SIGKILL) {
+				struct task_struct *dumper = core_state->dumper.task;
+				sigaddset(&dumper->pending.signal, SIGKILL);
+				signal_wake_up(dumper, 1);
+			}
+			return false;
+		}
 		/*
 		 * The process is in the middle of dying, nothing to do.
 		 */

Hi,

This patch breaks userspace, in particular it breaks gst-plugin-scanner of GStreamer which hangs now on next-20211224. IIUC, this tool builds a registry of good/working GStreamer plugins by loading them and blacklisting those that don't work (crash). Before the hang I see systemd-coredump process running, taking snapshot of gst-plugin-scanner and then gst-plugin-scanner gets stuck.

Bisection points at this patch, reverting it restores gst-plugin-scanner. Systemd-coredump still running, but there is no hang anymore and everything works properly as before.

I'm seeing this problem on ARM32 and haven't checked other arches. Please fix, thanks in advance.

#162 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 107 lines · Dmitry Osipenko

14.12.2021 01:53, Eric W. Biederman пишет:

Quoted 86 lines

Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking it by dumb luck.

Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up.

After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task.

Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress.

Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken.

Sort all of this out by making the coredump special case more special, and perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it.

In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending.

Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal.

Update wait_for_dump_helpers to perform a wait_event_killable wait so that if signal_pending gets set spuriously the wait will not be interrupted unless fatal_signal_pending is true.

I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working.

---
 fs/coredump.c   |  4 ++--
 kernel/signal.c | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/coredump.c +2 -2
index a6b3c196cdef..7b91fb32dbb8 100644
@@ -448,7 +448,7 @@ static void coredump_finish(bool core_dumped)
 static bool dump_interrupted(void)
 {
 	/*
-	 * SIGKILL or freezing() interrupt the coredumping. Perhaps we
+	 * SIGKILL or freezing() interrupted the coredumping. Perhaps we
 	 * can do try_to_freeze() and check __fatal_signal_pending(),
 	 * but then we need to teach dump_write() to restart and clear
 	 * TIF_SIGPENDING.
@@ -471,7 +471,7 @@ static void wait_for_dump_helpers(struct file *file)
 	 * We actually want wait_event_freezable() but then we need
 	 * to clear TIF_SIGPENDING and improve dump_interrupted().
 	 */
-	wait_event_interruptible(pipe->rd_wait, pipe->readers == 1);
+	wait_event_killable(pipe->rd_wait, pipe->readers == 1);
 
 	pipe_lock(pipe);
 	pipe->readers--;
kernel/signal.c +2 -2
index 8272cac5f429..7e305a8ec7c2 100644
@@ -907,8 +907,15 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	sigset_t flush;
 
 	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
-			return sig == SIGKILL;
+		struct core_state *core_state = signal->core_state;
+		if (core_state) {

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 921

Quoted 10 lines
kernel/signal.c +7 -0
+			if (sig == SIGKILL) {
+				struct task_struct *dumper = core_state->dumper.task;
+				sigaddset(&dumper->pending.signal, SIGKILL);
+				signal_wake_up(dumper, 1);
+			}
+			return false;
+		}
 		/*
 		 * The process is in the middle of dying, nothing to do.
 		 */

Hi,

This patch breaks userspace, in particular it breaks gst-plugin-scanner of GStreamer which hangs now on next-20211224. IIUC, this tool builds a registry of good/working GStreamer plugins by loading them and blacklisting those that don't work (crash). Before the hang I see systemd-coredump process running, taking snapshot of gst-plugin-scanner and then gst-plugin-scanner gets stuck.

Quoted 6 lines

Bisection points at this patch, reverting it restores gst-plugin-scanner. Systemd-coredump still running, but there is no hang anymore and everything works properly as before.

I'm seeing this problem on ARM32 and haven't checked other arches. Please fix, thanks in advance.

That is weird.

Doubly weird really because this should only change the case where coredumps are interrupted by SIGKILL.

What distro are you running? I would like to match things as closely as I can. So I can reproduce the issue so I can figure out what is wrong so I can fix it.

Eric

#163 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

In reply to Dmitry Osipenko
Quoted 107 lines · Dmitry Osipenko

14.12.2021 01:53, Eric W. Biederman пишет:

Quoted 86 lines

Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking it by dumb luck.

Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up.

After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task.

Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress.

Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken.

Sort all of this out by making the coredump special case more special, and perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it.

In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending.

Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal.

Update wait_for_dump_helpers to perform a wait_event_killable wait so that if signal_pending gets set spuriously the wait will not be interrupted unless fatal_signal_pending is true.

I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working.

---
 fs/coredump.c   |  4 ++--
 kernel/signal.c | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/coredump.c +2 -2
index a6b3c196cdef..7b91fb32dbb8 100644
@@ -448,7 +448,7 @@ static void coredump_finish(bool core_dumped)
 static bool dump_interrupted(void)
 {
 	/*
-	 * SIGKILL or freezing() interrupt the coredumping. Perhaps we
+	 * SIGKILL or freezing() interrupted the coredumping. Perhaps we
 	 * can do try_to_freeze() and check __fatal_signal_pending(),
 	 * but then we need to teach dump_write() to restart and clear
 	 * TIF_SIGPENDING.
@@ -471,7 +471,7 @@ static void wait_for_dump_helpers(struct file *file)
 	 * We actually want wait_event_freezable() but then we need
 	 * to clear TIF_SIGPENDING and improve dump_interrupted().
 	 */
-	wait_event_interruptible(pipe->rd_wait, pipe->readers == 1);
+	wait_event_killable(pipe->rd_wait, pipe->readers == 1);
 
 	pipe_lock(pipe);
 	pipe->readers--;
kernel/signal.c +2 -2
index 8272cac5f429..7e305a8ec7c2 100644
@@ -907,8 +907,15 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	sigset_t flush;
 
 	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
-			return sig == SIGKILL;
+		struct core_state *core_state = signal->core_state;
+		if (core_state) {

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 921

Quoted 10 lines
kernel/signal.c +7 -0
+			if (sig == SIGKILL) {
+				struct task_struct *dumper = core_state->dumper.task;
+				sigaddset(&dumper->pending.signal, SIGKILL);
+				signal_wake_up(dumper, 1);
+			}
+			return false;
+		}
 		/*
 		 * The process is in the middle of dying, nothing to do.
 		 */

Hi,

This patch breaks userspace, in particular it breaks gst-plugin-scanner of GStreamer which hangs now on next-20211224. IIUC, this tool builds a registry of good/working GStreamer plugins by loading them and blacklisting those that don't work (crash). Before the hang I see systemd-coredump process running, taking snapshot of gst-plugin-scanner and then gst-plugin-scanner gets stuck.

Quoted 6 lines

Bisection points at this patch, reverting it restores gst-plugin-scanner. Systemd-coredump still running, but there is no hang anymore and everything works properly as before.

I'm seeing this problem on ARM32 and haven't checked other arches. Please fix, thanks in advance.

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Eric

#164 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 117 lines
Quoted 107 lines · Dmitry Osipenko

14.12.2021 01:53, Eric W. Biederman пишет:

Quoted 86 lines

Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking it by dumb luck.

Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up.

After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task.

Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress.

Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken.

Sort all of this out by making the coredump special case more special, and perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it.

In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending.

Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal.

Update wait_for_dump_helpers to perform a wait_event_killable wait so that if signal_pending gets set spuriously the wait will not be interrupted unless fatal_signal_pending is true.

I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working.

---
 fs/coredump.c   |  4 ++--
 kernel/signal.c | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/coredump.c +2 -2
index a6b3c196cdef..7b91fb32dbb8 100644
@@ -448,7 +448,7 @@ static void coredump_finish(bool core_dumped)
 static bool dump_interrupted(void)
 {
 	/*
-	 * SIGKILL or freezing() interrupt the coredumping. Perhaps we
+	 * SIGKILL or freezing() interrupted the coredumping. Perhaps we
 	 * can do try_to_freeze() and check __fatal_signal_pending(),
 	 * but then we need to teach dump_write() to restart and clear
 	 * TIF_SIGPENDING.
@@ -471,7 +471,7 @@ static void wait_for_dump_helpers(struct file *file)
 	 * We actually want wait_event_freezable() but then we need
 	 * to clear TIF_SIGPENDING and improve dump_interrupted().
 	 */
-	wait_event_interruptible(pipe->rd_wait, pipe->readers == 1);
+	wait_event_killable(pipe->rd_wait, pipe->readers == 1);
 
 	pipe_lock(pipe);
 	pipe->readers--;
kernel/signal.c +2 -2
index 8272cac5f429..7e305a8ec7c2 100644
@@ -907,8 +907,15 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	sigset_t flush;
 
 	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
-			return sig == SIGKILL;
+		struct core_state *core_state = signal->core_state;
+		if (core_state) {

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 921

Quoted 10 lines
kernel/signal.c +7 -0
+			if (sig == SIGKILL) {
+				struct task_struct *dumper = core_state->dumper.task;
+				sigaddset(&dumper->pending.signal, SIGKILL);
+				signal_wake_up(dumper, 1);
+			}
+			return false;
+		}
 		/*
 		 * The process is in the middle of dying, nothing to do.
 		 */

Hi,

This patch breaks userspace, in particular it breaks gst-plugin-scanner of GStreamer which hangs now on next-20211224. IIUC, this tool builds a registry of good/working GStreamer plugins by loading them and blacklisting those that don't work (crash). Before the hang I see systemd-coredump process running, taking snapshot of gst-plugin-scanner and then gst-plugin-scanner gets stuck.

Quoted 6 lines

Bisection points at this patch, reverting it restores gst-plugin-scanner. Systemd-coredump still running, but there is no hang anymore and everything works properly as before.

I'm seeing this problem on ARM32 and haven't checked other arches. Please fix, thanks in advance.

Quoted 7 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

#165 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Eric

#166 lore raw

PATCH 1/2 signal: Have prepare_signal detect coredumps using signal->core_state

In preparation for removing the flag SIGNAL_GROUP_COREDUMP, change prepare_signal to test signal->core_state instead of the flag SIGNAL_GROUP_COREDUMP.

Both fields are protected by siglock and both live in signal_struct so there are no real tradeoffs here, just a change to which field is being tested.

---
 kernel/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/signal.c +2 -2
index 8272cac5f429..f95a4423519d 100644
@@ -906,8 +906,8 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	struct task_struct *t;
 	sigset_t flush;
 
-	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
-		if (!(signal->flags & SIGNAL_GROUP_EXIT))
+	if ((signal->flags & SIGNAL_GROUP_EXIT) || signal->core_state) {
+		if (signal->core_state)
 			return sig == SIGKILL;
 		/*
 		 * The process is in the middle of dying, nothing to do.
Signature · 1 line
2.29.2
#167 lore raw

PATCH 2/2 signal: Make coredump handling explicit in complete_signal

In reply to Eric W. Biederman

Ever since commit 6cd8f0acae34 ("coredump: ensure that SIGKILL always kills the dumping thread") it has been possible for a SIGKILL received during a coredump to set SIGNAL_GROUP_EXIT and trigger a process shutdown (for a second time).

Update the logic to explicitly allow coredumps so that coredumps can set SIGNAL_GROUP_EXIT and shutdown like an ordinary process.

---
 kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +1 -1
index f95a4423519d..0706c1345a71 100644
@@ -1032,7 +1032,7 @@ static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
 	 * then start taking the whole group down immediately.
 	 */
 	if (sig_fatal(p, sig) &&
-	    !(signal->flags & SIGNAL_GROUP_EXIT) &&
+	    (signal->core_state || !(signal->flags & SIGNAL_GROUP_EXIT)) &&
 	    !sigismember(&t->real_blocked, sig) &&
 	    (sig == SIGKILL || !p->ptrace)) {
 		/*
Signature · 1 line
2.29.2
#168 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

In reply to Eric W. Biederman

08.01.2022 21:13, Eric W. Biederman пишет:

Quoted 23 lines
Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

Quoted 8 lines

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Eric, thank you again. I started to look at the reproduction steps and haven't completed it yet. Turned out the problem affects only older NVIDIA Tegra2 Cortex-A9 CPU that lacks support of ARM NEON instructions set, hence the problem isn't visible on x86 and other CPUs out of the box. I'll need to check whether the problem could be simulated on all arches or maybe it's specific to VFP exception handling of ARM32.

#169 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 33 lines · Dmitry Osipenko

08.01.2022 21:13, Eric W. Biederman пишет:

Quoted 23 lines
Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

Quoted 8 lines

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Quoted 6 lines

Eric, thank you again. I started to look at the reproduction steps and haven't completed it yet. Turned out the problem affects only older NVIDIA Tegra2 Cortex-A9 CPU that lacks support of ARM NEON instructions set, hence the problem isn't visible on x86 and other CPUs out of the box. I'll need to check whether the problem could be simulated on all arches or maybe it's specific to VFP exception handling of ARM32.

It sounds like the gstreamer plugins only fail on certain hardware on arm32, and things don't hang in coredumps unless the plugins fail. That does make things tricky to minimize.

I have just verified that the known problematic code is not in linux-next for Jan 11 2022.

If folks as they have time can double check linux-next and verify all is well I would appreciate it. I don't expect that there are problems but sometimes one problem hides another.

Eric

#170 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

11.01.2022 20:20, Eric W. Biederman пишет:

Quoted 46 lines
Quoted 33 lines · Dmitry Osipenko

08.01.2022 21:13, Eric W. Biederman пишет:

Quoted 23 lines
Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

Quoted 8 lines

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Quoted 6 lines

Eric, thank you again. I started to look at the reproduction steps and haven't completed it yet. Turned out the problem affects only older NVIDIA Tegra2 Cortex-A9 CPU that lacks support of ARM NEON instructions set, hence the problem isn't visible on x86 and other CPUs out of the box. I'll need to check whether the problem could be simulated on all arches or maybe it's specific to VFP exception handling of ARM32.

It sounds like the gstreamer plugins only fail on certain hardware on arm32, and things don't hang in coredumps unless the plugins fail. That does make things tricky to minimize.

Quoted 6 lines

I have just verified that the known problematic code is not in linux-next for Jan 11 2022.

If folks as they have time can double check linux-next and verify all is well I would appreciate it. I don't expect that there are problems but sometimes one problem hides another.

Hello Eric,

I reproduced the trouble on x86_64.

Here are the reproduction steps, using ArchLinux and linux-next-20211224:

```
sudo pacman -S base-devel git mesa glu meson wget
git clone https://github.com/grate-driver/gstreamer.git
cd gstreamer
git checkout sigill
meson --prefix=/usr -Dgst-plugins-base:playback=enabled -Dgst-devtools:validate=disabled build
cd build
sudo ninja install
wget https://www.peach.themazzone.com/big_buck_bunny_720p_h264.mov
rm -r ~/.cache/gstreamer-1.0
gst-play-1.0 ./big_buck_bunny_720p_h264.mov
```

The SIGILL, thrown by [1], causes the hang. There is no hang using v5.16.1 kernel.

[1] https://github.com/grate-driver/gstreamer/commit/006f9a2ee6dcf7b31c9b5413815d6054d82a3b2f

#171 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 73 lines · Dmitry Osipenko

11.01.2022 20:20, Eric W. Biederman пишет:

Quoted 46 lines
Quoted 33 lines · Dmitry Osipenko

08.01.2022 21:13, Eric W. Biederman пишет:

Quoted 23 lines
Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

Quoted 8 lines

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Quoted 6 lines

Eric, thank you again. I started to look at the reproduction steps and haven't completed it yet. Turned out the problem affects only older NVIDIA Tegra2 Cortex-A9 CPU that lacks support of ARM NEON instructions set, hence the problem isn't visible on x86 and other CPUs out of the box. I'll need to check whether the problem could be simulated on all arches or maybe it's specific to VFP exception handling of ARM32.

It sounds like the gstreamer plugins only fail on certain hardware on arm32, and things don't hang in coredumps unless the plugins fail. That does make things tricky to minimize.

Quoted 6 lines

I have just verified that the known problematic code is not in linux-next for Jan 11 2022.

If folks as they have time can double check linux-next and verify all is well I would appreciate it. I don't expect that there are problems but sometimes one problem hides another.

Hello Eric,

I reproduced the trouble on x86_64.

Here are the reproduction steps, using ArchLinux and linux-next-20211224:

```
sudo pacman -S base-devel git mesa glu meson wget
git clone https://github.com/grate-driver/gstreamer.git
cd gstreamer
git checkout sigill
meson --prefix=/usr -Dgst-plugins-base:playback=enabled -Dgst-devtools:validate=disabled build
cd build
sudo ninja install
wget https://www.peach.themazzone.com/big_buck_bunny_720p_h264.mov
rm -r ~/.cache/gstreamer-1.0
gst-play-1.0 ./big_buck_bunny_720p_h264.mov
```
Quoted 3 lines

The SIGILL, thrown by [1], causes the hang. There is no hang using v5.16.1 kernel.

[1] https://github.com/grate-driver/gstreamer/commit/006f9a2ee6dcf7b31c9b5413815d6054d82a3b2f

Thank you.

I will verify this works before I add my updated version to my signal-for-v5.18 branch.

Have you by any chance tried a newer version of linux-next without commit fbc11520b58a ("signal: Make SIGKILL during coredumps an explicit special case") in it?

If not I will double check that my pulling the commit out does not break in the case you have documented.

Eric

#172 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

18.01.2022 20:52, Eric W. Biederman пишет:

Quoted 84 lines
Quoted 73 lines · Dmitry Osipenko

11.01.2022 20:20, Eric W. Biederman пишет:

Quoted 46 lines
Quoted 33 lines · Dmitry Osipenko

08.01.2022 21:13, Eric W. Biederman пишет:

Quoted 23 lines
Quoted 6 lines · Dmitry Osipenko

05.01.2022 22:58, Eric W. Biederman пишет:

Quoted 5 lines

I have not yet been able to figure out how to run gst-pluggin-scanner in a way that triggers this yet. In truth I can't figure out how to run gst-pluggin-scanner in a useful way.

Quoted 7 lines
Quoted 3 lines

I am going to set up some unit tests and see if I can reproduce your hang another way, but if you could give me some more information on what you are doing to trigger this I would appreciate it.

Thanks, Eric. The distro is Arch Linux, but it's a development environment where I'm running latest GStreamer from git master. I'll try to figure out the reproduction steps and get back to you.

Thank you.

Until I can figure out why this is causing problems I have dropped the following two patches from my queue:
signal: Make SIGKILL during coredumps an explicit special case
signal: Drop signals received after a fatal signal has been processed

Quoted 8 lines

I have replaced them with the following two patches that just do what is needed for the rest of the code in the series:
signal: Have prepare_signal detect coredumps using
signal: Make coredump handling explicit in complete_signal

Perversely my failure to change the SIGKILL handling when coredumps are happening proves to me that I need to change the SIGKILL handling when coredumps are happening to make the code more maintainable.

Quoted 6 lines

Eric, thank you again. I started to look at the reproduction steps and haven't completed it yet. Turned out the problem affects only older NVIDIA Tegra2 Cortex-A9 CPU that lacks support of ARM NEON instructions set, hence the problem isn't visible on x86 and other CPUs out of the box. I'll need to check whether the problem could be simulated on all arches or maybe it's specific to VFP exception handling of ARM32.

It sounds like the gstreamer plugins only fail on certain hardware on arm32, and things don't hang in coredumps unless the plugins fail. That does make things tricky to minimize.

Quoted 6 lines

I have just verified that the known problematic code is not in linux-next for Jan 11 2022.

If folks as they have time can double check linux-next and verify all is well I would appreciate it. I don't expect that there are problems but sometimes one problem hides another.

Hello Eric,

I reproduced the trouble on x86_64.

Here are the reproduction steps, using ArchLinux and linux-next-20211224:

```
sudo pacman -S base-devel git mesa glu meson wget
git clone https://github.com/grate-driver/gstreamer.git
cd gstreamer
git checkout sigill
meson --prefix=/usr -Dgst-plugins-base:playback=enabled -Dgst-devtools:validate=disabled build
cd build
sudo ninja install
wget https://www.peach.themazzone.com/big_buck_bunny_720p_h264.mov
rm -r ~/.cache/gstreamer-1.0
gst-play-1.0 ./big_buck_bunny_720p_h264.mov
```
Quoted 3 lines

The SIGILL, thrown by [1], causes the hang. There is no hang using v5.16.1 kernel.

[1] https://github.com/grate-driver/gstreamer/commit/006f9a2ee6dcf7b31c9b5413815d6054d82a3b2f

Thank you.

I will verify this works before I add my updated version to my signal-for-v5.18 branch.

Quoted 6 lines

Have you by any chance tried a newer version of linux-next without commit fbc11520b58a ("signal: Make SIGKILL during coredumps an explicit special case") in it?

If not I will double check that my pulling the commit out does not break in the case you have documented.

Recent linux-next works fine.

#173 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

In reply to Eric W. Biederman

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 911

Quoted 7 lines · Eric W. Biederman

        if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
kernel/signal.c +2 -2
-               if (!(signal->flags & SIGNAL_GROUP_EXIT))
-                       return sig == SIGKILL;
+               struct core_state *core_state = signal->core_state;
+               if (core_state) {

This change is very confusing.

Also, why does it do that 'signal->core_state->dumper.task', when we already know that it's the same as 'signal->group_exit_task'?

The only thing that sets 'signal->core_state' also sets 'signal->group_exit_task', and the call chain has set both to the same task.

So the code is odd and makes little sense.

But what's even more odd is how it

(a) sends the SIGKILL to somebody else

(b) does *NOT* send SIGKILL to itself

Now, (a) is explained in the commit message. The intent is to signal the core dumper.

But (b) looks like a fundamental change in semantics. The target of the SIGKILL is still running, might be in some loop in the kernel that wants to be interrupted by a fatal signal, and you expressly disabled the code that would send that fatal signal.

If I send SIGKILL to thread A, then that SIGKILL had *better* be delivered. To thread A, which may be in a "mutex_lock_killable()" or whatever else.

The fact that thread B may be in the process of trying to dump core doesn't change that at all, as far as I can see.

So I think this patch is fundamentally buggy and wrong. Or at least needs much more explanation of why you'd not send SIGKILL to the target thread.

Linus

#174 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 11 lines · Linus Torvalds

kernel/signal.c static bool prepare_signal(int sig, struct task_struct *p, bool force) · line 911

Quoted 7 lines · Eric W. Biederman

        if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
kernel/signal.c +2 -2
-               if (!(signal->flags & SIGNAL_GROUP_EXIT))
-                       return sig == SIGKILL;
+               struct core_state *core_state = signal->core_state;
+               if (core_state) {

This change is very confusing.

Quoted 8 lines

Also, why does it do that 'signal->core_state->dumper.task', when we already know that it's the same as 'signal->group_exit_task'?

The only thing that sets 'signal->core_state' also sets 'signal->group_exit_task', and the call chain has set both to the same task.

So the code is odd and makes little sense.

As you say signal->group_exit_task, and core_state->dumper.task point to the same task. So it may be a little silly when viewed independently of everything else to use core_state->dumper.task instead of group_exit_task as it is an extra cache line dereference.

The thing is signal->group_exit_task is only used by coredumps currently as a flag to tell signal_group_exit to return true. It is exec that actually uses signal->group_exit_task in conjunction with signal->notify_count to wake itself up.

Using a pointer as a flag and not for it's value. Having different semantics for who sets the pointer. All of those are weird enough I just want to make signal->group_exit_task to go away.

By using core_state->dumper.task I was able to make signal->group_exit_task exclusive to the exec case in the following changes, and to rename it signal->group_exec_task so no one gets confused what the field is for.

Quoted 8 lines

But what's even more odd is how it

(a) sends the SIGKILL to somebody else

(b) does *NOT* send SIGKILL to itself

Now, (a) is explained in the commit message. The intent is to signal the core dumper.

Which is the a specific thread of the target process, and it is the only thread running of the target process.

Quoted 9 lines

But (b) looks like a fundamental change in semantics. The target of the SIGKILL is still running, might be in some loop in the kernel that wants to be interrupted by a fatal signal, and you expressly disabled the code that would send that fatal signal.

If I send SIGKILL to thread A, then that SIGKILL had *better* be delivered. To thread A, which may be in a "mutex_lock_killable()" or whatever else.

Quoted 6 lines

The fact that thread B may be in the process of trying to dump core doesn't change that at all, as far as I can see.

So I think this patch is fundamentally buggy and wrong. Or at least needs much more explanation of why you'd not send SIGKILL to the target thread.

If you look at zap_threads. You can observe that it takes the siglock, sets SIGNAL_GROUP_COREDUMP, and sets signal->core_state and in zap_process makes SIGKILL pending is the per-task sigset, and calls signal_wake_up on every task.

This case in prepare_signal happens after that. After every task has been told to die, and __fatal_signal_pending is true for all of them if they have not reached do_exit yet.

If you look in zap_threads you will see that the core dumping thread clears TIF_SIGPENDING, and in general makes fatal_signal_pending false for itself. But keep in mind that this thread because it is dumping core is already on the path to do_exit. It has already processed a fatal signal.

So in the special case I only worry about the dumping task as it is the only task after zap_threads that does not have fatal_signal_pending.

This is different than the ordinary case of delivering SIGKILL where complete_signal makes SIGKILL pending in the per-task sigset of every task in the process.

Currently I suspect changing wait_event_uninterruptible to wait_event_killable, is causing problems.

Or perhaps there is some reason tasks that have already entered do_exit need to have fatal_signal_pending set. (The will have fatal_signal_pending set up until they enter get_signal which calls do_group_exit which calls do_exit).

Which is why I am trying to reproduce the reported failure so I can get the kernel to tell me what is going on. If this is not resolved quickly I won't send you this change, and I will pull it out of linux-next.

Eric

maintainer
#175 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 11 lines · Eric W. Biederman

Currently I suspect changing wait_event_uninterruptible to wait_event_killable, is causing problems.

Or perhaps there is some reason tasks that have already entered do_exit need to have fatal_signal_pending set. (The will have fatal_signal_pending set up until they enter get_signal which calls do_group_exit which calls do_exit).

Which is why I am trying to reproduce the reported failure so I can get the kernel to tell me what is going on. If this is not resolved quickly I won't send you this change, and I will pull it out of linux-next.

It would have been good if you would have removed this from linux-next already.

Anyway, now I also had to spend quite some time to bisect why several test suites just hang with linux-next. It's probably because of holidays that you didn't get more bug reports.

On s390

- ltp
- elfutils selftests
- seccomp kernel selftests

hang with linux-next.

I bisected the problem to this patch using elfutils selftests:

git clone git://sourceware.org/git/elfutils.git
cd elfutils
autoreconf -fi
./configure --enable-maintainer-mode --disable-debuginfod make -j $(nproc) > /dev/null
cd tests
make -j $(nproc) check

Note: I actually didn't verify if this also causes ltp+seccomp selftests
to hang. I just assume it is the case.

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#178 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 6 lines · Eric W. Biederman

I have been able to confirm that changing wait_event_interruptible to wait_event_killable was the culprit.  Something about the way systemd-coredump handles coredumps is not compatible with wait_event_killable.

This is my experience too that systemd-coredump is doing something unexpected. When I tested the patch:
https://lore.kernel.org/lkml/[email protected]/

to make sure that the patch worked, sending coredumps to systemd- coredump was making systemd-coredump, well, core dump... Not very useful...

Sending the dumps through a pipe to anything else than systemd-coredump was working fine.

#179 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 8 lines · Olivier Langlois
Quoted 6 lines · Eric W. Biederman

I have been able to confirm that changing wait_event_interruptible to wait_event_killable was the culprit.  Something about the way systemd-coredump handles coredumps is not compatible with wait_event_killable.

Quoted 7 lines

This is my experience too that systemd-coredump is doing something unexpected. When I tested the patch:
https://lore.kernel.org/lkml/[email protected]/

to make sure that the patch worked, sending coredumps to systemd- coredump was making systemd-coredump, well, core dump... Not very useful...

Oh. Wow....

Quoted 2 lines

Sending the dumps through a pipe to anything else than systemd-coredump was working fine.

Interesting.

I need to read through the pipe code and see how all of that works. For writing directly to disk only ignoring killable interruptions are the usual semantics. Ordinary pipe code has different semantics, and I suspect that is what is tripping things up.

As for systemd-coredump it does whatever it does and I suspect some versions of systemd-coredump are simply not robust if a coredump stops unexpectedly.

The good news is the pipe code is simple enough, it will be possible to completely read through that code.

Eric

#180 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 30 lines · Eric W. Biederman
Quoted 8 lines · Olivier Langlois
Quoted 6 lines · Eric W. Biederman

I have been able to confirm that changing wait_event_interruptible to wait_event_killable was the culprit.  Something about the way systemd-coredump handles coredumps is not compatible with wait_event_killable.

Quoted 7 lines

This is my experience too that systemd-coredump is doing something unexpected. When I tested the patch:
https://lore.kernel.org/lkml/[email protected]/

to make sure that the patch worked, sending coredumps to systemd- coredump was making systemd-coredump, well, core dump... Not very useful...

Oh. Wow....

Quoted 2 lines

Sending the dumps through a pipe to anything else than systemd-coredump was working fine.

Interesting.

I need to read through the pipe code and see how all of that works. For writing directly to disk only ignoring killable interruptions are the usual semantics. Ordinary pipe code has different semantics, and I suspect that is what is tripping things up.

Quoted 6 lines

As for systemd-coredump it does whatever it does and I suspect some versions of systemd-coredump are simply not robust if a coredump stops unexpectedly.

The good news is the pipe code is simple enough, it will be possible to completely read through that code.

My bug, obvious in hindsight is that "try_to_wait_up(TASK_INTERRUPTIBLE)" does not work on a task that is in sleeping in TASK_KILLABLE. That looks fixable in wait_for_dump_helpers it just won't be as easy as changing wait_event_interruptible to wait_event_killable.

To prevent short pipe write from causing short writes during a coredump I believe all we need to do handle -ERSTARTSYS with TIF_NOTIFY_SIGNAL. Something like what I have below.

Until wait_for_dump_helpers is sorted out the coredump won't wait for the dump helper the way it should, but otherwise things should work.

fs/coredump.c +4 -0
index 7dece20b162b..0db1baf91420 100644
@@ -796,6 +796,10 @@ static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)
 	if (dump_interrupted())
 		return 0;
 	n = __kernel_write(file, addr, nr, &pos);
+	while ((n == -ERESTARTSYS) && test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+		tracehook_notify_signal();
+		n = __kernel_write(file, addr, nr, &pos);
+	}
 	if (n != nr)
 		return 0;
 	file->f_pos = pos;

Eric

#181 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

fs/coredump.c static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr) · line 802

Quoted 5 lines · Eric W. Biederman
fs/coredump.c +4 -0
+       while ((n == -ERESTARTSYS) && test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+               tracehook_notify_signal();
+               n = __kernel_write(file, addr, nr, &pos);
+       }

This reads horribly wrongly to me.

That "tracehook_notify_signal()" thing *has* to be renamed before we have anything like this that otherwise looks like "this will just loop forever".

I'm pretty sure we've discussed that "tracehook" thing before - the whole header file is misnamed, and most of the functions in theer are too.

As an ugly alternative, open-code it, so that it's clear that "yup, that clears the TIF_NOTIFY_SIGNAL flag".

Linus

#182 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 14 lines · Linus Torvalds

fs/coredump.c static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr) · line 802

Quoted 5 lines · Eric W. Biederman
fs/coredump.c +4 -0
+       while ((n == -ERESTARTSYS) && test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+               tracehook_notify_signal();
+               n = __kernel_write(file, addr, nr, &pos);
+       }

This reads horribly wrongly to me.

That "tracehook_notify_signal()" thing *has* to be renamed before we have anything like this that otherwise looks like "this will just loop forever".

Quoted 6 lines

I'm pretty sure we've discussed that "tracehook" thing before - the whole header file is misnamed, and most of the functions in theer are too.

As an ugly alternative, open-code it, so that it's clear that "yup, that clears the TIF_NOTIFY_SIGNAL flag".

A cleaner alternative looks like to modify the pipe code to use wake_up_XXX instead of wake_up_interruptible_XXX and then have code that does pipe_write_killable instead of pipe_write_interruptible.

There is also a question of how all of this should interact with the freezer, as I think changing from interruptible to killable means that the coredumps became unfreezable.

I am busily simmering this on my back burner and I hope I can come up with something sensible.

Eric

#183 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 24 lines · Eric W. Biederman
Quoted 22 lines · Linus Torvalds
Quoted 6 lines · Eric W. Biederman

+       while ((n == -ERESTARTSYS) && test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+               tracehook_notify_signal();
+               n = __kernel_write(file, addr, nr, &pos); +       }

This reads horribly wrongly to me.

That "tracehook_notify_signal()" thing *has* to be renamed before we
have anything like this that otherwise looks like "this will just loop
forever".

I'm pretty sure we've discussed that "tracehook" thing before - the whole header file is misnamed, and most of the functions in theer are
too.

Quoted 6 lines
Quoted 2 lines

As an ugly alternative, open-code it, so that it's clear that "yup, that clears the TIF_NOTIFY_SIGNAL flag".

A cleaner alternative looks like to modify the pipe code to use wake_up_XXX instead of wake_up_interruptible_XXX and then have code that does pipe_write_killable instead of pipe_write_interruptible.

Do not forget that the problem might not be limited to the pipe FS as Oleg Nesterov pointed out here:

https://lore.kernel.org/io-uring/[email protected]/

This is why I did like your patch fixing __dump_emit. If the only problem is the tracehook_notify_signal() function unclear name, that should be addressed instead of trying to fix the problem in a different way.

Quoted 8 lines

There is also a question of how all of this should interact with the freezer, as I think changing from interruptible to killable means that
the coredumps became unfreezable.

I am busily simmering this on my back burner and I hope I can come up with something sensible.

IMHO, fixing the problem on the emit function side has the merit of being future proof if something else than io_uring in the future would raise the TIF_NOTIFY_SIGNAL flag

but I am wondering why no one commented anything about my proposal of cancelling io_uring before generating the core dump therefore stopping it to flip TIF_NOTIFY_SIGNAL while the core dump is generated.

Is there something wrong with my proposed approach?
https://lore.kernel.org/lkml/[email protected]/

It did flawlessly created many dozens of io_uring app core dumps in the last months for me...

Olivier

#184 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

Quoted 35 lines · Olivier Langlois
Quoted 24 lines · Eric W. Biederman
Quoted 22 lines · Linus Torvalds
Quoted 6 lines · Eric W. Biederman

+       while ((n == -ERESTARTSYS) && test_thread_flag(TIF_NOTIFY_SIGNAL)) {
+               tracehook_notify_signal();
+               n = __kernel_write(file, addr, nr, &pos); +       }

This reads horribly wrongly to me.

That "tracehook_notify_signal()" thing *has* to be renamed before we
have anything like this that otherwise looks like "this will just loop
forever".

I'm pretty sure we've discussed that "tracehook" thing before - the whole header file is misnamed, and most of the functions in theer are
too.

Quoted 6 lines
Quoted 2 lines

As an ugly alternative, open-code it, so that it's clear that "yup, that clears the TIF_NOTIFY_SIGNAL flag".

A cleaner alternative looks like to modify the pipe code to use wake_up_XXX instead of wake_up_interruptible_XXX and then have code that does pipe_write_killable instead of pipe_write_interruptible.

Do not forget that the problem might not be limited to the pipe FS as Oleg Nesterov pointed out here:

Quoted 6 lines

https://lore.kernel.org/io-uring/[email protected]/

This is why I did like your patch fixing __dump_emit. If the only problem is the tracehook_notify_signal() function unclear name, that should be addressed instead of trying to fix the problem in a different way.

It might be that the fix is to run a portion of the exit_to_userspace loop that does:

	if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
		handle_signal_work(regs, ti_work);

I am deep in brainstorm mode trying to find something that comes out clean.

Oleg is right that while to be POSIX compliant and otherwise compatible with traditional unix behavior sleeps in filesystems need to be uninterruptible. NFS has not always provided that compatibility.

Quoted 16 lines
Quoted 7 lines

There is also a question of how all of this should interact with the freezer, as I think changing from interruptible to killable means that
the coredumps became unfreezable.

I am busily simmering this on my back burner and I hope I can come up with something sensible.

IMHO, fixing the problem on the emit function side has the merit of being future proof if something else than io_uring in the future would raise the TIF_NOTIFY_SIGNAL flag

but I am wondering why no one commented anything about my proposal of cancelling io_uring before generating the core dump therefore stopping it to flip TIF_NOTIFY_SIGNAL while the core dump is generated.

Quoted 5 lines

Is there something wrong with my proposed approach?
https://lore.kernel.org/lkml/[email protected]/

It did flawlessly created many dozens of io_uring app core dumps in the last months for me...

From my perspective I am not at all convinced that io_uring is the only culprit.

Beyond that the purpose of a coredump is to snapshot the process as it is, before anything is shutdown so that someone can examine the coredump and figure out what failed. Running around changing the state of the process has a very real chance of hiding what is going wrong.

Further your change requires that there be a place for io_uring to clean things up. Given that fundamentally that seems like the wrong thing to me I am not interested in making it easy to what looks like the wrong thing.

All of this may be perfection being the enemy of the good (especially as your io_uring magic happens as a special case in do_coredump). My work in this area is to remove hacks so I can be convinced the code works 100% of the time so unfortunately I am not interested in pick up a change that is only good enough. Someone else like Andrew Morton might be.

None of that changes the fact that tracehook_notify_signal needs to be renamed. That effects your approach and my proof of concept approach. So renaming tracehook_notify_signal just needs to be done.

Eric

#185 lore raw

io_uring truncating coredumps

Subject updated to reflect the current discussion.

Quoted 4 lines

Linus Torvalds <[email protected]> writes:

But I really think it's wrong.

Quoted 8 lines

You're trying to work around a problem the wrong way around. If a task is dead, and is dumping core, then signals just shouldn't matter in the first place, and thus the whole "TASK_INTERRUPTIBLE vs TASK_UNINTERRUPTIBLE" really shouldn't be an issue. The fact that it is an issue means there's something wrong in signaling, not in the pipe code.

So I really think that's where the fix should be - on the signal delivery side.

Thinking about it from the perspective of not delivering the wake-ups fixing io_uring and coredumps in a non-hacky way looks comparatively simple. The function task_work_add just needs to not wake anything up after a process has started dying.

Something like the patch below.

The only tricky part I can see is making certain there are not any races between task_work_add and do_coredump depending on task_work_add not causing signal_pending to return true.

kernel/task_work.c +3 -0
index fad745c59234..5f941e377268 100644
@@ -44,6 +44,9 @@ int task_work_add(struct task_struct *task, struct callback_head *work,
 		work->next = head;
 	} while (cmpxchg(&task->task_works, head, work) != head);
 
+	if (notify && (task->signal->flags & SIGNAL_GROUP_EXIT))
+		return 0;
+
 	switch (notify) {
 	case TWA_NONE:
 		break;

Eric

#186 lore raw

Re: io_uring truncating coredumps

Quoted 7 lines · Eric W. Biederman

Thinking about it from the perspective of not delivering the wake-ups fixing io_uring and coredumps in a non-hacky way looks comparatively simple. The function task_work_add just needs to not wake anything up after a process has started dying.

Something like the patch below.

Hmm. Yes, I think this is the right direction.

That said, I think it should not add the work at all, and return -ESRCH, the exact same way that it does for that work_exited condition.

Because it's basically the same thing: the task is dead and shouldn't do more work. In fact, task_work_run() is the thing that sets it to &work_exited as it sees PF_EXITING, so it feels to me that THAT is actually the issue here - we react to PF_EXITING too late. We react to it *after* we've already added the work, and then we do that "no more work" logic only after we've accepted those late work entries?

So my gut feel is that task_work_add() should just also test PF_EXITING.

And in fact, my gut feel is that PF_EXITING is too late anyway (it happens after core-dumping, no?)

But I guess that thing may be on purpose, and maybe the act of dumping core itself wants to do more work, and so that isn't an option?

So I don't think your patch is "right" as-is, and it all worries me, but yes, I think this area is very much the questionable one.

I think that work stopping and the io_uring shutdown should probably move earlier in the exit queue, but as mentioned above, maybe the work addition boundary in particular really wants to be late because the exit process itself still uses task works? ;(

Linus

#187 lore raw

Re: [PATCH 1/8] signal: Make SIGKILL during coredumps an explicit special case

In reply to Eric W. Biederman
Quoted 19 lines · Eric W. Biederman

Olivier Langlois <[email protected]> writes:
From my perspective I am not at all convinced that io_uring is the only
culprit.

Beyond that the purpose of a coredump is to snapshot the process as it
is, before anything is shutdown so that someone can examine the coredump
and figure out what failed.  Running around changing the state of the process has a very real chance of hiding what is going wrong.

Further your change requires that there be a place for io_uring to clean
things up.  Given that fundamentally that seems like the wrong thing to
me I am not interested in making it easy to what looks like the wrong thing.

Quoted 11 lines

All of this may be perfection being the enemy of the good (especially as
your io_uring magic happens as a special case in do_coredump).  My work
in this area is to remove hacks so I can be convinced the code works 100% of the time so unfortunately I am not interested in pick up a change that is only good enough.  Someone else like Andrew Morton might
be.

Fair enough.

You do bring good points but I am not so sure about the second one considering that the coredump is meant to be a snapshot and if io_uring still runs, the state may change as the dump is generated anyway.

I'll follow with interest what you finally come up with but my mindset when I wrote the patch was that there does not seem to be any benefit keeping io_uring active while coredumping and it has the potential to create nasty issues.

I did stumble into core file truncation problem.

Pavel got that when modifying io_uring code:
https://lore.kernel.org/all/[email protected]/

and I find very likely that keeping io_uring active while coredumping might create new nasty but subtle issues down the road...

Greetings,
Olivier

#188 lore raw

PATCH 2/8 signal: Drop signals received after a fatal signal has been processed

In reply to Eric W. Biederman

In 403bad72b67d ("coredump: only SIGKILL should interrupt the coredumping task") Oleg modified the kernel to drop all signals that come in during a coredump except SIGKILL, and suggested that it might be a good idea to generalize that to other cases after the process has received a fatal signal.

Semantically it does not make sense to perform any signal delivery after the process has already been killed.

When a signal is sent while a process is dying today the signal is placed in the signal queue by __send_signal and a single task of the process is woken up with signal_wake_up, if there are any tasks that have not set PF_EXITING.

Take things one step farther and have prepare_signal report that all signals that come after a process has been killed should be ignored. While retaining the historical exception of allowing SIGKILL to interrupt coredumps.

Remove the SIGNAL_GROUP_EXIT test from complete_signal, as it is no longer possible for signal processing to reach complete_signal when SIGNAL_GROUP_EXIT is true.

Update the comment in fs/coredump.c to make it clear coredumps are special in being able to receive SIGKILL.

---
 fs/coredump.c   | 2 +-
 kernel/signal.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
fs/coredump.c +1 -1
index 7b91fb32dbb8..a9c25f20118f 100644
@@ -352,7 +352,7 @@ static int zap_process(struct task_struct *start, int exit_code, int flags)
 	struct task_struct *t;
 	int nr = 0;
 
-	/* ignore all signals except SIGKILL, see prepare_signal() */
+	/* Allow SIGKILL, see prepare_signal() */
 	start->signal->flags = SIGNAL_GROUP_COREDUMP | flags;
 	start->signal->group_exit_code = exit_code;
 	start->signal->group_stop_count = 0;
kernel/signal.c +2 -3
index 7e305a8ec7c2..cdccbacac685 100644
@@ -914,11 +914,11 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 				sigaddset(&dumper->pending.signal, SIGKILL);
 				signal_wake_up(dumper, 1);
 			}
-			return false;
 		}
 		/*
-		 * The process is in the middle of dying, nothing to do.
+		 * The process is in the middle of dying, drop the signal.
 		 */
+		return false;
 	} else if (sig_kernel_stop(sig)) {
 		/*
 		 * This is a stop signal.  Remove SIGCONT from all queues.
@@ -1039,7 +1039,6 @@ static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
 	 * then start taking the whole group down immediately.
 	 */
 	if (sig_fatal(p, sig) &&
-	    !(signal->flags & SIGNAL_GROUP_EXIT) &&
 	    !sigismember(&t->real_blocked, sig) &&
 	    (sig == SIGKILL || !p->ptrace)) {
 		/*
Signature · 1 line
2.29.2
#189 lore raw

PATCH 3/8 signal: Have the oom killer detect coredumps using signal->core_state

In reply to Eric W. Biederman

In preparation for removing the flag SIGNAL_GROUP_COREDUMP change __task_will_free_mem to test signal->core_state instead of the flag SIGNAL_GROUP_COREDUMP.

Both fields are protected by siglock and both live in signal_struct so there are no real tradeoffs here, just a change to which field is being tested.

---
 mm/oom_kill.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/oom_kill.c +1 -1
index 1ddabefcfb5a..5c92aad8ca1a 100644
@@ -793,7 +793,7 @@ static inline bool __task_will_free_mem(struct task_struct *task)
 	 * coredump_task_exit(), so the oom killer cannot assume that
 	 * the process will promptly exit and release memory.
 	 */
-	if (sig->flags & SIGNAL_GROUP_COREDUMP)
+	if (sig->core_state)
 		return false;
 
 	if (sig->flags & SIGNAL_GROUP_EXIT)
Signature · 1 line
2.29.2
#190 lore raw

PATCH 4/8 signal: During coredumps set SIGNAL_GROUP_EXIT in zap_process

In reply to Eric W. Biederman

There are only a few places that test SIGNAL_GROUP_EXIT and are not also already testing SIGNAL_GROUP_COREDUMP.

This will not affect the callers of signal_group_exit as zap_process also sets group_exit_task so signal_group_exit will continue to return true at the same times.

This does not affect wait_task_zombie as the none of the threads wind up in EXIT_ZOMBIE state during a coredump.

This does not affect oom_kill.c:__task_will_free_mem as sig->core_state is tested and handled before SIGNAL_GROUP_EXIT is tested for.

---
 fs/coredump.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/coredump.c +3 -3
index a9c25f20118f..5e5a90de7be3 100644
@@ -347,13 +347,13 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
 	return ispipe;
 }
 
-static int zap_process(struct task_struct *start, int exit_code, int flags)
+static int zap_process(struct task_struct *start, int exit_code)
 {
 	struct task_struct *t;
 	int nr = 0;
 
 	/* Allow SIGKILL, see prepare_signal() */
-	start->signal->flags = SIGNAL_GROUP_COREDUMP | flags;
+	start->signal->flags = SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP;
 	start->signal->group_exit_code = exit_code;
 	start->signal->group_stop_count = 0;
 
@@ -378,7 +378,7 @@ static int zap_threads(struct task_struct *tsk,
 	if (!signal_group_exit(tsk->signal)) {
 		tsk->signal->core_state = core_state;
 		tsk->signal->group_exit_task = tsk;
-		nr = zap_process(tsk, exit_code, 0);
+		nr = zap_process(tsk, exit_code);
 		clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
 		tsk->flags |= PF_DUMPCORE;
 		atomic_set(&core_state->nr_threads, nr);
Signature · 1 line
2.29.2
#191 lore raw

PATCH 5/8 signal: Remove SIGNAL_GROUP_COREDUMP

In reply to Eric W. Biederman

After the previous cleanups "signal->core_state" is set whenever SIGNAL_GROUP_COREDUMP is set and "signal->core_state" is tested whenver the code wants to know if a coredump is in progress. The remaining tests of SIGNAL_GROUP_COREDUMP also test to see if SIGNAL_GROUP_EXIT is set. Similarly the only place that sets SIGNAL_GROUP_COREDUMP also sets SIGNAL_GROUP_EXIT.

Which makes SIGNAL_GROUP_COREDUMP unecessary and redundant so stop setting SIGNAL_GROUP_COREDUMP, stop testing SIGNAL_GROUP_COREDUMP and remove it's definition makeing the code slightly simpler.

With the setting of SIGNAL_GROUP_COREDUMP gone coredump_finish no longer needs to clear SIGNAL_GROUP_COREDUMP out of signal->flags by setting SIGNAL_GROUP_EXIT.

---
 fs/coredump.c                | 3 +--
 include/linux/sched/signal.h | 3 +--
 kernel/signal.c              | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)
fs/coredump.c +1 -2
index 5e5a90de7be3..2c9d16d4b57a 100644
@@ -353,7 +353,7 @@ static int zap_process(struct task_struct *start, int exit_code)
 	int nr = 0;
 
 	/* Allow SIGKILL, see prepare_signal() */
-	start->signal->flags = SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP;
+	start->signal->flags = SIGNAL_GROUP_EXIT;
 	start->signal->group_exit_code = exit_code;
 	start->signal->group_stop_count = 0;
 
@@ -427,7 +427,6 @@ static void coredump_finish(bool core_dumped)
 	if (core_dumped && !__fatal_signal_pending(current))
 		current->signal->group_exit_code |= 0x80;
 	current->signal->group_exit_task = NULL;
-	current->signal->flags = SIGNAL_GROUP_EXIT;
 	next = current->signal->core_state->dumper.next;
 	current->signal->core_state = NULL;
 	spin_unlock_irq(&current->sighand->siglock);
include/linux/sched/signal.h +1 -2
index fa26d2a58413..ecc10e148799 100644
@@ -256,7 +256,6 @@ struct signal_struct {
 #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
 #define SIGNAL_STOP_CONTINUED	0x00000002 /* SIGCONT since WCONTINUED reap */
 #define SIGNAL_GROUP_EXIT	0x00000004 /* group exit in progress */
-#define SIGNAL_GROUP_COREDUMP	0x00000008 /* coredump in progress */
 /*
  * Pending notifications to parent.
  */
@@ -272,7 +271,7 @@ struct signal_struct {
 static inline void signal_set_stop_flags(struct signal_struct *sig,
 					 unsigned int flags)
 {
-	WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP));
+	WARN_ON(sig->flags & SIGNAL_GROUP_EXIT);
 	sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
 }
 
kernel/signal.c +1 -1
index cdccbacac685..9eb3e2c1f9f7 100644
@@ -906,7 +906,7 @@ static bool prepare_signal(int sig, struct task_struct *p, bool force)
 	struct task_struct *t;
 	sigset_t flush;
 
-	if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) {
+	if (signal->flags & SIGNAL_GROUP_EXIT) {
 		struct core_state *core_state = signal->core_state;
 		if (core_state) {
 			if (sig == SIGKILL) {
Signature · 1 line
2.29.2
#192 lore raw

PATCH 6/8 coredump: Stop setting signal->group_exit_task

In reply to Eric W. Biederman

Currently the coredump code sets group_exit_task so that signal_group_exit() will return true during a coredump. Now that the coredump code always sets SIGNAL_GROUP_EXIT there is no longer a need to set signal->group_exit_task.

---
 fs/coredump.c | 2 --
 1 file changed, 2 deletions(-)
fs/coredump.c +0 -2
index 2c9d16d4b57a..ef56595a0d87 100644
@@ -377,7 +377,6 @@ static int zap_threads(struct task_struct *tsk,
 	spin_lock_irq(&tsk->sighand->siglock);
 	if (!signal_group_exit(tsk->signal)) {
 		tsk->signal->core_state = core_state;
-		tsk->signal->group_exit_task = tsk;
 		nr = zap_process(tsk, exit_code);
 		clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
 		tsk->flags |= PF_DUMPCORE;
@@ -426,7 +425,6 @@ static void coredump_finish(bool core_dumped)
 	spin_lock_irq(&current->sighand->siglock);
 	if (core_dumped && !__fatal_signal_pending(current))
 		current->signal->group_exit_code |= 0x80;
-	current->signal->group_exit_task = NULL;
 	next = current->signal->core_state->dumper.next;
 	current->signal->core_state = NULL;
 	spin_unlock_irq(&current->sighand->siglock);
Signature · 1 line
2.29.2
#193 lore raw

PATCH 7/8 signal: Rename group_exit_task group_exec_task

In reply to Eric W. Biederman

The only remaining user of group_exit_task is exec. Rename the field so that it is clear which part of the code uses it.

Update the comment above the definition of group_exec_task to document how it is currently used.

---
 fs/exec.c                    |  8 ++++----
 include/linux/sched/signal.h | 12 ++++--------
 kernel/exit.c                |  4 ++--
 3 files changed, 10 insertions(+), 14 deletions(-)
fs/exec.c +4 -4
index 59cac7c18178..9d2925811011 100644
@@ -1054,7 +1054,7 @@ static int de_thread(struct task_struct *tsk)
 		return -EAGAIN;
 	}
 
-	sig->group_exit_task = tsk;
+	sig->group_exec_task = tsk;
 	sig->notify_count = zap_other_threads(tsk);
 	if (!thread_group_leader(tsk))
 		sig->notify_count--;
@@ -1082,7 +1082,7 @@ static int de_thread(struct task_struct *tsk)
 			write_lock_irq(&tasklist_lock);
 			/*
 			 * Do this under tasklist_lock to ensure that
-			 * exit_notify() can't miss ->group_exit_task
+			 * exit_notify() can't miss ->group_exec_task
 			 */
 			sig->notify_count = -1;
 			if (likely(leader->exit_state))
@@ -1149,7 +1149,7 @@ static int de_thread(struct task_struct *tsk)
 		release_task(leader);
 	}
 
-	sig->group_exit_task = NULL;
+	sig->group_exec_task = NULL;
 	sig->notify_count = 0;
 
 no_thread_group:
@@ -1162,7 +1162,7 @@ static int de_thread(struct task_struct *tsk)
 killed:
 	/* protects against exit_notify() and __exit_signal() */
 	read_lock(&tasklist_lock);
-	sig->group_exit_task = NULL;
+	sig->group_exec_task = NULL;
 	sig->notify_count = 0;
 	read_unlock(&tasklist_lock);
 	return -EAGAIN;
include/linux/sched/signal.h +4 -8
index ecc10e148799..d3248aba5183 100644
@@ -109,13 +109,9 @@ struct signal_struct {
 
 	/* thread group exit support */
 	int			group_exit_code;
-	/* overloaded:
-	 * - notify group_exit_task when ->count is equal to notify_count
-	 * - everyone except group_exit_task is stopped during signal delivery
-	 *   of fatal signals, group_exit_task processes the signal.
-	 */
+	/* notify group_exec_task when notify_count is less or equal to 0 */
 	int			notify_count;
-	struct task_struct	*group_exit_task;
+	struct task_struct	*group_exec_task;
 
 	/* thread group stop support, overloads group_exit_code too */
 	int			group_stop_count;
@@ -275,11 +271,11 @@ static inline void signal_set_stop_flags(struct signal_struct *sig,
 	sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
 }
 
-/* If true, all threads except ->group_exit_task have pending SIGKILL */
+/* If true, all threads except ->group_exec_task have pending SIGKILL */
 static inline int signal_group_exit(const struct signal_struct *sig)
 {
 	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
-		(sig->group_exit_task != NULL);
+		(sig->group_exec_task != NULL);
 }
 
 extern void flush_signals(struct task_struct *);
kernel/exit.c +2 -2
index 6c4b04531f17..527c5e4430ae 100644
@@ -116,7 +116,7 @@ static void __exit_signal(struct task_struct *tsk)
 		 * then notify it:
 		 */
 		if (sig->notify_count > 0 && !--sig->notify_count)
-			wake_up_process(sig->group_exit_task);
+			wake_up_process(sig->group_exec_task);
 
 		if (tsk == sig->curr_target)
 			sig->curr_target = next_thread(tsk);
@@ -697,7 +697,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 
 	/* mt-exec, de_thread() is waiting for group leader */
 	if (unlikely(tsk->signal->notify_count < 0))
-		wake_up_process(tsk->signal->group_exit_task);
+		wake_up_process(tsk->signal->group_exec_task);
 	write_unlock_irq(&tasklist_lock);
 
 	list_for_each_entry_safe(p, n, &dead, ptrace_entry) {
Signature · 1 line
2.29.2
#194 lore raw

PATCH 8/8 signal: Remove the helper signal_group_exit

In reply to Eric W. Biederman

This helper is misleading. It tests for an ongoing exec as well as the process having received a fatal signal.

Sometimes it is appropriate to treat an on-going exec differently than a process that is shutting down due to a fatal signal. In particular taking the fast path out of exit_signals instead of retargeting signals is not appropriate during exec, and not changing the the exit code in do_group_exit during exec.

Removing the helper so that both cases must be coded for explicitly makes it more obvious what is going on as both cases must be coded for explicitly.

While removing the helper fix the two cases where I have observed using signal_group_helper resulted in the wrong result.

For the unset exit_code in do_group_exit during an exec I use 0 as I think that is what group_exit_code has been set to most of the time. During a thread group stop group_exit_code is set to the stop signal and when the thread group receives SIGCONT group_exit_code is reset to 0.

---
 fs/coredump.c                | 5 +++--
 fs/exec.c                    | 2 +-
 include/linux/sched/signal.h | 7 -------
 kernel/exit.c                | 8 ++++++--
 kernel/signal.c              | 8 +++++---
 5 files changed, 15 insertions(+), 15 deletions(-)
fs/coredump.c +3 -2
index ef56595a0d87..09302a6a0d80 100644
@@ -372,11 +372,12 @@ static int zap_process(struct task_struct *start, int exit_code)
 static int zap_threads(struct task_struct *tsk,
 			struct core_state *core_state, int exit_code)
 {
+	struct signal_struct *signal = tsk->signal;
 	int nr = -EAGAIN;
 
 	spin_lock_irq(&tsk->sighand->siglock);
-	if (!signal_group_exit(tsk->signal)) {
-		tsk->signal->core_state = core_state;
+	if (!(signal->flags & SIGNAL_GROUP_EXIT) && !signal->group_exec_task) {
+		signal->core_state = core_state;
 		nr = zap_process(tsk, exit_code);
 		clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
 		tsk->flags |= PF_DUMPCORE;
fs/exec.c +1 -1
index 9d2925811011..82db656ca709 100644
@@ -1045,7 +1045,7 @@ static int de_thread(struct task_struct *tsk)
 	 * Kill all other threads in the thread group.
 	 */
 	spin_lock_irq(lock);
-	if (signal_group_exit(sig)) {
+	if ((sig->flags & SIGNAL_GROUP_EXIT) || sig->group_exec_task) {
 		/*
 		 * Another group action in progress, just
 		 * return so that the signal is processed.
include/linux/sched/signal.h +0 -7
index d3248aba5183..b6ecb9fc4cd2 100644
@@ -271,13 +271,6 @@ static inline void signal_set_stop_flags(struct signal_struct *sig,
 	sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
 }
 
-/* If true, all threads except ->group_exec_task have pending SIGKILL */
-static inline int signal_group_exit(const struct signal_struct *sig)
-{
-	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
-		(sig->group_exec_task != NULL);
-}
-
 extern void flush_signals(struct task_struct *);
 extern void ignore_signals(struct task_struct *);
 extern void flush_signal_handlers(struct task_struct *, int force_default);
kernel/exit.c +6 -2
index 527c5e4430ae..e7104f803be0 100644
@@ -907,15 +907,19 @@ do_group_exit(int exit_code)
 
 	BUG_ON(exit_code & 0x80); /* core dumps don't get here */
 
-	if (signal_group_exit(sig))
+	if (sig->flags & SIGNAL_GROUP_EXIT)
 		exit_code = sig->group_exit_code;
+	else if (sig->group_exec_task)
+		exit_code = 0;
 	else if (!thread_group_empty(current)) {
 		struct sighand_struct *const sighand = current->sighand;
 
 		spin_lock_irq(&sighand->siglock);
-		if (signal_group_exit(sig))
+		if (sig->flags & SIGNAL_GROUP_EXIT)
 			/* Another thread got here before we took the lock.  */
 			exit_code = sig->group_exit_code;
+		else if (sig->group_exec_task)
+			exit_code = 0;
 		else {
 			sig->group_exit_code = exit_code;
 			sig->flags = SIGNAL_GROUP_EXIT;
kernel/signal.c +5 -3
index 9eb3e2c1f9f7..860d844542b2 100644
@@ -2392,7 +2392,8 @@ static bool do_signal_stop(int signr)
 		WARN_ON_ONCE(signr & ~JOBCTL_STOP_SIGMASK);
 
 		if (!likely(current->jobctl & JOBCTL_STOP_DEQUEUED) ||
-		    unlikely(signal_group_exit(sig)))
+		    unlikely(sig->flags & SIGNAL_GROUP_EXIT) ||
+		    unlikely(sig->group_exec_task))
 			return false;
 		/*
 		 * There is no group stop already in progress.  We must
@@ -2699,7 +2700,8 @@ bool get_signal(struct ksignal *ksig)
 		enum pid_type type;
 
 		/* Has this task already been marked for death? */
-		if (signal_group_exit(signal)) {
+		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
+		     signal->group_exec_task) {
 			ksig->info.si_signo = signr = SIGKILL;
 			sigdelset(&current->pending.signal, SIGKILL);
 			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
@@ -2955,7 +2957,7 @@ void exit_signals(struct task_struct *tsk)
 	 */
 	cgroup_threadgroup_change_begin(tsk);
 
-	if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
+	if (thread_group_empty(tsk) || (tsk->signal->flags & SIGNAL_GROUP_EXIT)) {
 		tsk->flags |= PF_EXITING;
 		cgroup_threadgroup_change_end(tsk);
 		return;
Signature · 1 line
2.29.2