Skip to content

Commit bca4104

Browse files
author
Peter Zijlstra
committed
lockdep: Fix block chain corruption
Kent reported an occasional KASAN splat in lockdep. Mark then noted: > I suspect the dodgy access is to chain_block_buckets[-1], which hits the last 4 > bytes of the redzone and gets (incorrectly/misleadingly) attributed to > nr_large_chain_blocks. That would mean @SiZe == 0, at which point size_to_bucket() returns -1 and the above happens. alloc_chain_hlocks() has 'size - req', for the first with the precondition 'size >= rq', which allows the 0. This code is trying to split a block, del_chain_block() takes what we need, and add_chain_block() puts back the remainder, except in the above case the remainder is 0 sized and things go sideways. Fixes: 810507f ("locking/lockdep: Reuse freed chain_hlocks entries") Reported-by: Kent Overstreet <kent.overstreet@linux.dev> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Kent Overstreet <kent.overstreet@linux.dev> Link: https://lkml.kernel.org/r/20231121114126.GH8262@noisy.programming.kicks-ass.net
1 parent 98b1cc8 commit bca4104

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/locking/lockdep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,8 @@ static int alloc_chain_hlocks(int req)
34973497
size = chain_block_size(curr);
34983498
if (likely(size >= req)) {
34993499
del_chain_block(0, size, chain_block_next(curr));
3500-
add_chain_block(curr + req, size - req);
3500+
if (size > req)
3501+
add_chain_block(curr + req, size - req);
35013502
return curr;
35023503
}
35033504
}

0 commit comments

Comments
 (0)