Kernel fixes bad concurrency IDs after exec and affinity changes
Stable patches close a use-after-free and stop restartable sequences from seeing an invalid ID or a needlessly wide ID range.
Mathieu Desnoyers has posted fixes for the kernel's restartable-sequence concurrency IDs, the small numbers user space uses to index per-thread data. Three of the changes are marked for stable. They cover a failed exec, affinity changes that the memory descriptor never records, and a use-after-free found with KASAN by Weiming Shi.
Each address space is supposed to hand out IDs that stay below the number of possible CPUs, and ideally below the smaller of its thread count and the CPUs its tasks may run on. User space sizes its tables from the possible-CPU bound. A missed compact target does not crash anything, but it spreads that data over more memory than the process needs.
A failed exec was leaving and rejoining that ID accounting. The task could then return to user space with the unset value 0x80000000, leak an ID, or spin trying to obtain one. Desnoyers moves the hooks so a failed exec no longer drops out of the accounting at all. A separate window let an affinity change during exec or fork vanish, so a process that later ran on many CPUs could keep sparse IDs (in one test, 1 and 63 for two remaining threads). New address spaces now start with no allowed CPUs and pick up each task's mask when that task joins.
The use-after-free is in the same area. Another task can change a process's CPU affinity while that process is in exec, and the update can touch the old address space after it has been freed. Shi reported it under KASAN. Without that sanitizer the same path would write freed memory. Any process allowed to change the victim's affinity can hit it. On the exec path the race needs a kernel built without futex support. A review also found the same class of window when a kernel thread drops a borrowed address space. The fix holds the task lock across join and leave so affinity updates only use an address space the task still owns.
A fourth change, not a stable fix, stops io_uring SQPOLL threads and vhost workers from taking IDs. Those workers never return to user space and have no restartable-sequence area, but they were counted as users and could widen the CPU set. A process confined to two CPUs could then see IDs above that limit. The series also adds selftests that fail on the invalid ID and note, rather than fail, when IDs are merely less compact than the kernel aims for.