signal: unconditionally leave the frozen state in ptrace_stop()
PATCH RESEND 1/1 signal: unconditionally leave the frozen state in ptrace_stop()
Alex Xu reported a regression in strace, caused by the introduction of the cgroup v2 freezer. The regression can be reproduced by stracing the following simple program:
#include <unistd.h>
int main() {
write(1, "a", 1);
return 0;
}An attempt to run strace ./a.out leads to the infinite loop:
[ pre-main omitted ]
write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
[ repeats forever ]
The problem occurs because the traced task leaves ptrace_stop() (and the signal handling loop) with the frozen bit set. So let's call cgroup_leave_frozen(true) unconditionally after sleeping in ptrace_stop().
With this patch applied, strace works as expected:
[ pre-main omitted ]
write(1, "a", 1) = 1
exit_group(0) = ?
+++ exited with 0 +++
--- kernel/signal.c | 1 + 1 file changed, 1 insertion(+)
kernel/signal.c +1 -0
@@ -2112,6 +2112,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, kernel_siginfo_tpreempt_enable_no_resched ();cgroup_enter_frozen ();freezable_schedule (); +cgroup_leave_frozen (true); }else {/* * By the time we got the lock, our tracer went away.
Signature · 1 line
2.20.1
Quoted 32 lines · Roman Gushchin
Alex Xu reported a regression in strace, caused by the introduction of the cgroup v2 freezer. The regression can be reproduced by stracing the following simple program:
#include <unistd.h> int main() { write(1, "a", 1); return 0; }An attempt to run strace ./a.out leads to the infinite loop:
[ pre-main omitted ]write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) write(1, "a", 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)[ repeats forever ]
The problem occurs because the traced task leaves
ptrace_stop()(and the signal handling loop) with the frozen bit set. So let's callcgroup_leave_frozen(true)unconditionally after sleeping inptrace_stop().With this patch applied, strace works as expected:
[ pre-main omitted ]
write(1, "a", 1)= 1
exit_group(0)= ?
+++ exited with 0 +++
Quoted 5 lines
Reported-by Alex Xu <[email protected]>Fixes 76f969e8948d ("cgroup: cgroup v2 freezer")Signed-off-by Roman Gushchin <[email protected]>Acked-by Oleg Nesterov <[email protected]>Cc Tejun Heo <[email protected]>
Applied to cgroup/for-5.2-fixes.
Thanks.
Signature · 1 line
tejun