Skip to content

Commit 51ad56a

Browse files
Li Qiongopsiff
authored andcommitted
mm/slub: avoid accessing metadata when pointer is invalid in object_err()
[ Upstream commit b4efccec8d06ceb10a7d34d7b1c449c569d53770 ] object_err() reports details of an object for further debugging, such as the freelist pointer, redzone, etc. However, if the pointer is invalid, attempting to access object metadata can lead to a crash since it does not point to a valid object. One known path to the crash is when alloc_consistency_checks() determines the pointer to the allocated object is invalid because of a freelist corruption, and calls object_err() to report it. The debug code should report and handle the corruption gracefully and not crash in the process. In case the pointer is NULL or check_valid_pointer() returns false for the pointer, only print the pointer value and skip accessing metadata. Fixes: 81819f0 ("SLUB core") Cc: <[email protected]> Signed-off-by: Li Qiong <[email protected]> Reviewed-by: Harry Yoo <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit dda6ec365ab04067adae40ef17015db447e90736)
1 parent 2eefec3 commit 51ad56a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mm/slub.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,12 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
11131113
return;
11141114

11151115
slab_bug(s, reason);
1116-
print_trailer(s, slab, object);
1116+
if (!object || !check_valid_pointer(s, slab, object)) {
1117+
print_slab_info(slab);
1118+
pr_err("Invalid pointer 0x%p\n", object);
1119+
} else {
1120+
print_trailer(s, slab, object);
1121+
}
11171122
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11181123

11191124
WARN_ON(1);

0 commit comments

Comments
 (0)