[PATCH 0/2] livepatch: Do not lose exiting tasks during a transition

From: Binoy Ravindran via B4 Relay

Date: Mon Nov 23 2026 - 15:52:51 EST


After exit_notify(), a self-reaping task is unhashed from the task list
but keeps running the rest of do_exit(). The livepatch transition walks
the task list, so it can complete while such a task still runs code from
a patch module that atomic replace is about to free. Yafang Shao and
Petr Mladek discussed this race in [1]. It is hard to hit, but it is
reachable by any livepatch that replaces a function on the exit path,
for example a fix to do_exit() itself.

Every exiting task is already on an RCU-tasks exit list from
exit_tasks_rcu_start(), before exit_notify(), until
exit_tasks_rcu_finish(). After that, do_exit() runs with preemption
disabled until the final switch, so the task cannot sleep or be
preempted. Patch 1 adds helpers to visit the tasks on these lists.
Patch 2 makes every transition step, including reverse and force,
visit them too. The exit path itself is unchanged. Kernels without
CONFIG_TASKS_RCU have no exit lists and are not covered.

We reproduced the crash with two atomic-replace livepatches of the
CVE-2025-38424 fix, which replaces do_exit(). With a debug-only sleep
after exit_notify(), 11 of 12 runs crash without the series and none
with it. With it, there were also no crashes in 1,200 cycles of a /proc
stress test or in 400 cycles with preempt=full. The measurements were
taken on v6.12.1. This series is the forward port to v7.4-rc2. On
mainline it has been build-tested only: it builds without new warnings
with livepatch on, with livepatch on and preemption off, and with
TASKS_RCU off. It has not yet been run on mainline. A reproducer and the
logs are available on request.

[1] https://lore.kernel.org/all/20250127063526.76687-1-laoar.shao@xxxxxxxxx/

---
Binoy Ravindran (2):
rcu-tasks: Add helpers to visit tasks on the exit lists
livepatch: Include exiting tasks in the transition

include/linux/rcupdate.h | 9 ++++++
kernel/livepatch/transition.c | 72 +++++++++++++++++++++++++++++++++++++++++++
kernel/rcu/tasks.h | 67 ++++++++++++++++++++++++++++++++++++----
3 files changed, 142 insertions(+), 6 deletions(-)
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261123-klp-series-v3-d52796c0590f

Best regards,
--
Binoy Ravindran <binoy@xxxxxx>