Livepatch can free a module an exiting task is still running
A revised fix walks RCU exit lists and waits out the last non-preemptible stretch of task exit, after the first posting left that gap open.
Linux livepatching can finish a transition, and with atomic replace free the old patch module, while a task that has already left the process list is still executing that module's code. Binoy Ravindran posted a fix after reproducing crashes by livepatching the exit path itself.
The window opens once a self-reaping task is unhashed during exit but has not yet made its final context switch. The transition walks the task list, so it never sees that task. Any livepatch that replaces a function on the exit path can hit it, including a fix to exit itself. Yafang Shao and Petr Mladek had already described the race. Ravindran calls it hard to hit but reachable.
On a 6.12 kernel he alternated two atomic-replace patches of the CVE-2025-38424 fix, which replaces the exit path, and inserted a debug sleep to widen the window. Eleven of twelve runs crashed without the change and none with it. Longer stress runs also stayed up. The posting is a forward port toward 7.4 and has only been build-tested on mainline.
Reviewers did not accept the first version as written. A task still on both the process list and an RCU-tasks exit list can be visited twice, and after it leaves the exit list but before its last switch it is on neither list and can still enter patched code with a stale state. Shao had declined an earlier, similar idea from Josh Poimboe for that second reason: the exit list narrows the race but does not close it.
Ravindran agreed. A revision will skip tasks that are still hashed, so each is visited once, and will call the existing transition barrier before a function enters transition and again before completion. That barrier schedules work on every online CPU. In the uncovered stretch the exiting task has already disabled preemption, so the next switch on its CPU is its last. Once every CPU has switched, those tasks are gone. He also agreed to make the tasks-RCU option an explicit livepatch dependency. On the architectures that support livepatch it is already selected, so the change documents the requirement rather than altering today's builds. He asked reviewers to wait until that version has been run on mainline.