[PATCH 4/9] cgroup/freezer: test the freeze trap bit under siglock

From: Shakeel Butt

Date: Sun Nov 29 2026 - 13:36:09 EST


When a task leaves the frozen state while its cgroup is still freezing,
for example a vfork parent, cgroup_leave_frozen() sets JOBCTL_TRAP_FREEZE
and TIF_SIGPENDING so that the task traps again. It tests
JOBCTL_TRAP_FREEZE without siglock.

cgroup_freeze_task() sets that bit and then TIF_SIGPENDING, both under
siglock. If the task sees only the first store, it can return to user
space while it is counted as frozen, until the wakeup kick arrives. Take
siglock before the test. The window is a few instructions wide, and this
was not reproduced.

Fixes: cb2c4cd87874 ("cgroup: prevent spurious transition into non-frozen state")
Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
---
kernel/cgroup/freezer.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup/freezer.c b/kernel/cgroup/freezer.c
index a85f8897ffa2..b905df5e416b 100644
--- a/kernel/cgroup/freezer.c
+++ b/kernel/cgroup/freezer.c
@@ -127,10 +127,17 @@ void cgroup_leave_frozen(bool always_leave)
cgroup_update_frozen(cgrp);
WARN_ON_ONCE(!current->frozen);
current->frozen = false;
- } else if (!(current->jobctl & JOBCTL_TRAP_FREEZE)) {
+ } else {
+ /*
+ * Test the trap bit under siglock: cgroup_freeze_task() sets it
+ * before signal_wake_up() sets TIF_SIGPENDING, and a vfork
+ * parent returns to user space right after this.
+ */
spin_lock(&current->sighand->siglock);
- current->jobctl |= JOBCTL_TRAP_FREEZE;
- set_thread_flag(TIF_SIGPENDING);
+ if (!(current->jobctl & JOBCTL_TRAP_FREEZE)) {
+ current->jobctl |= JOBCTL_TRAP_FREEZE;
+ set_thread_flag(TIF_SIGPENDING);
+ }
spin_unlock(&current->sighand->siglock);
}
spin_unlock_irq(&css_set_lock);
--
2.53.1-Meta