Skip to content

Commit e9b78b5

Browse files
Li Qiongharshimogalapalli
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) Signed-off-by: Harshit Mogalapalli <[email protected]>
1 parent e50e042 commit e9b78b5

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
@@ -1117,7 +1117,12 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
11171117
return;
11181118

11191119
slab_bug(s, reason);
1120-
print_trailer(s, slab, object);
1120+
if (!object || !check_valid_pointer(s, slab, object)) {
1121+
print_slab_info(slab);
1122+
pr_err("Invalid pointer 0x%p\n", object);
1123+
} else {
1124+
print_trailer(s, slab, object);
1125+
}
11211126
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11221127

11231128
WARN_ON(1);

0 commit comments

Comments
 (0)