[PATCH v2] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
From: Li Qiong
Date: Fri Jul 25 2025 - 02:50:03 EST
For debugging, object_err() prints free pointer of the object.
However, if check_valid_pointer() returns false for a object,
dereferncing `object + s->offset` can lead to a crash. Therefore,
print the object's address in such cases.
Fixes: bb192ed9aa71 ("mm/slub: Convert most struct page to struct slab by spatch")
Signed-off-by: Li Qiong <liqiong@xxxxxxxxxxxx>
---
v2:
- rephrase the commit message, add comment for object_err().
---
mm/slub.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 31e11ef256f9..8b24f1cf3079 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1097,6 +1097,10 @@ static void print_trailer(struct kmem_cache *s, struct slab *slab, u8 *p)
size_from_object(s) - off);
}
+/*
+ * object - should be a valid object.
+ * check_valid_pointer(s, slab, object) should be true.
+ */
static void object_err(struct kmem_cache *s, struct slab *slab,
u8 *object, const char *reason)
{
@@ -1587,7 +1591,7 @@ static inline int alloc_consistency_checks(struct kmem_cache *s,
return 0;
if (!check_valid_pointer(s, slab, object)) {
- object_err(s, slab, object, "Freelist Pointer check fails");
+ slab_err(s, slab, "Invalid object pointer 0x%p", object);
return 0;
}
--
2.30.2