Skip to content

Commit b4efcce

Browse files
Li Qiongtehcaster
authored andcommitted
mm/slub: avoid accessing metadata when pointer is invalid in object_err()
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]>
1 parent 1b237f1 commit b4efcce

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
@@ -1140,7 +1140,12 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
11401140
return;
11411141

11421142
slab_bug(s, reason);
1143-
print_trailer(s, slab, object);
1143+
if (!object || !check_valid_pointer(s, slab, object)) {
1144+
print_slab_info(slab);
1145+
pr_err("Invalid pointer 0x%p\n", object);
1146+
} else {
1147+
print_trailer(s, slab, object);
1148+
}
11441149
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11451150

11461151
WARN_ON(1);

0 commit comments

Comments
 (0)