Skip to content

Commit 85ba94b

Browse files
Matt Mackalltorvalds
authored andcommitted
SLOB: fix bogus ksize calculation
SLOB's ksize calculation was braindamaged and generally harmlessly underreported the allocation size. But for very small buffers, it could in fact overreport them, leading code depending on krealloc to overrun the allocation and trample other data. Signed-off-by: Matt Mackall <[email protected]> Tested-by: Peter Zijlstra <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e09e6e2 commit 85ba94b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/slob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ size_t ksize(const void *block)
515515

516516
sp = (struct slob_page *)virt_to_page(block);
517517
if (slob_page(sp))
518-
return ((slob_t *)block - 1)->units + SLOB_UNIT;
518+
return (((slob_t *)block - 1)->units - 1) * SLOB_UNIT;
519519
else
520520
return sp->page.private;
521521
}

0 commit comments

Comments
 (0)