Skip to content

Commit 3baa1da

Browse files
Li Qionggregkh
authored andcommitted
mm/slub: avoid accessing metadata when pointer is invalid in object_err()
commit b4efcce upstream. 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: <stable@vger.kernel.org> Signed-off-by: Li Qiong <liqiong@nfschina.com> Reviewed-by: Harry Yoo <harry.yoo@oracle.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 47c430e commit 3baa1da

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
@@ -1104,7 +1104,12 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
11041104
return;
11051105

11061106
slab_bug(s, reason);
1107-
print_trailer(s, slab, object);
1107+
if (!object || !check_valid_pointer(s, slab, object)) {
1108+
print_slab_info(slab);
1109+
pr_err("Invalid pointer 0x%p\n", object);
1110+
} else {
1111+
print_trailer(s, slab, object);
1112+
}
11081113
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11091114

11101115
WARN_ON(1);

0 commit comments

Comments
 (0)