backport to fix a race condition/UAF in padata_reorder
Subsystems (2)
cover backport to fix a race condition/UAF in padata_reorder
After applying these patches to v6.12.y, the padata.c file matches the upstream version at commit 71203f68c774, with two exceptions:
1. cpumask_next_wrap API difference (line 310): The v6.12.y kernel still uses the old 4-argument form cpumask_next_wrap(cpu, pd->cpumask.pcpu, -1, false), whereas upstream uses the newer 2-argument form cpumask_next_wrap(cpu, pd->cpumask.pcpu). These are functionally equivalent — upstream simply changed the API signature in a separate commit (dc5bb9b769c9), which is too invasive to backport.
2. Divide-by-zero guard in padata_mt_helper (after line 496): The v6.12.y doesn't include an extra check that forces chunk_size to at least 1 when the caller sets min_chunk to 0. This prevents a divide-by-zero panic.
Thanks
Bin Lan
Herbert Xu (2):
padata: Fix pd UAF once and for all
padata: Remove comment for reorder_work
include/linux/padata.h | 4 -- kernel/padata.c | 136 +++++++++++------------------------------ 2 files changed, 37 insertions(+), 103 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 padata: Fix pd UAF once and for all
From: Herbert Xu <[email protected]>
[ Upstream commit 71203f68c7749609d7fc8ae6ad054bdedeb24f91 ]
There is a race condition/UAF in padata_reorder that goes back to the initial commit. A reference count is taken at the start of the process in padata_do_parallel, and released at the end in padata_serial_worker.
This reference count is (and only is) required for padata_replace to function correctly. If padata_replace is never called then there is no issue.
In the function padata_reorder which serves as the core of padata, as soon as padata is added to queue->serial.list, and the associated spin lock released, that padata may be processed and the reference count on pd would go away.
Fix this by getting the next padata before the squeue->serial lock is released.
In order to make this possible, simplify padata_reorder by only calling it once the next padata arrives.
[ Adjust context of padata_find_next(). Replace cpumask_next_wrap(cpu, pd->cpumask.pcpu) with cpumask_next_wrap(cpu, pd->cpumask.pcpu, -1, false) in padata_reorder() in v6.12 according to dc5bb9b769c9 ("cpumask: deprecate cpumask_next_wrap()") and f954a2d37637 ("padata: switch padata_find_next() to using cpumask_next_wrap()") . ]
--- include/linux/padata.h | 3 - kernel/padata.c | 136 +++++++++++------------------------------ 2 files changed, 37 insertions(+), 102 deletions(-)
include/linux/padata.h +0 -3
@@ -91,7 +91,6 @@ struct padata_cpumask {* @cpu: Next CPU to be processed. * @cpumask: The cpumasks in use for parallel and serial workers. * @reorder_work: work struct for reordering. -* @lock: Reorder lock. */ struct parallel_data {struct padata_shell *ps;
@@ -102,8 +101,6 @@ struct parallel_data {unsigned int processed;int cpu;struct padata_cpumask cpumask; -struct work_struct reorder_work; -spinlock_t ____cacheline_aligned lock; };/**
kernel/padata.c +37 -99
202 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 2/2 padata: Remove comment for reorder_work
In reply to Bin LanFrom: Herbert Xu <[email protected]>
[ Upstream commit 82a0302e7167d0b7c6cde56613db3748f8dd806d ]
Remove comment for reorder_work which no longer exists.
--- include/linux/padata.h | 1 - 1 file changed, 1 deletion(-)
include/linux/padata.h +0 -1
@@ -90,7 +90,6 @@ struct padata_cpumask {* @processed: Number of already processed objects. * @cpu: Next CPU to be processed. * @cpumask: The cpumasks in use for parallel and serial workers. -* @reorder_work: work struct for reordering. */ struct parallel_data {struct padata_shell *ps;
Signature · 1 line
2.43.0