* [PATCH v4] mm: slub: avoid deref of invalid free pointer in object_err()
@ 2025-08-01 6:10 Li Qiong
2025-08-04 0:35 ` Harry Yoo
0 siblings, 1 reply; 2+ messages in thread
From: Li Qiong @ 2025-08-01 6:10 UTC (permalink / raw)
To: Christoph Lameter, David Rientjes, Andrew Morton, Vlastimil Babka
Cc: Roman Gushchin, Harry Yoo, linux-mm, linux-kernel, stable,
Li Qiong
For debugging, object_err() prints free pointer of the object.
However, if object is a invalid pointer, dereferncing `object + s->offset`
can lead to a crash. Therefore, add check_valid_pointer() for
the object.
Fixes: 81819f0fc828 ("SLUB core")
Cc: <stable@vger.kernel.org>
Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
v2:
- rephrase the commit message, add comment for object_err().
v3:
- check object pointer in object_err().
v4:
- restore changes in alloc_consistency_checks().
---
mm/slub.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 31e11ef256f9..17b91e74f7d9 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1104,7 +1104,11 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
return;
slab_bug(s, reason);
- print_trailer(s, slab, object);
+ if (!check_valid_pointer(s, slab, object)) {
+ print_slab_info(slab);
+ pr_err("invalid object 0x%p\n", object);
+ } else
+ print_trailer(s, slab, object);
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
WARN_ON(1);
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] mm: slub: avoid deref of invalid free pointer in object_err()
2025-08-01 6:10 [PATCH v4] mm: slub: avoid deref of invalid free pointer in object_err() Li Qiong
@ 2025-08-04 0:35 ` Harry Yoo
0 siblings, 0 replies; 2+ messages in thread
From: Harry Yoo @ 2025-08-04 0:35 UTC (permalink / raw)
To: Li Qiong
Cc: Christoph Lameter, David Rientjes, Andrew Morton, Vlastimil Babka,
Roman Gushchin, linux-mm, linux-kernel, stable
On Fri, Aug 01, 2025 at 02:10:36PM +0800, Li Qiong wrote:
> For debugging, object_err() prints free pointer of the object.
> However, if object is a invalid pointer, dereferncing `object + s->offset`
> can lead to a crash. Therefore, add check_valid_pointer() for
> the object.
Because this is not only about freelist pointer but also include other
metadata, this can be improved a little bit (+ with a slightly more
detailed description):
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.
In case check_valid_pointer() returns false for the pointer, only print
the pointer value and skip accessing metadata.
> Fixes: 81819f0fc828 ("SLUB core")
The tag looks correct.
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> ---
> v2:
> - rephrase the commit message, add comment for object_err().
> v3:
> - check object pointer in object_err().
> v4:
> - restore changes in alloc_consistency_checks().
> ---
> mm/slub.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 31e11ef256f9..17b91e74f7d9 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -1104,7 +1104,11 @@ static void object_err(struct kmem_cache *s, struct slab *slab,
> return;
>
> slab_bug(s, reason);
> - print_trailer(s, slab, object);
> + if (!check_valid_pointer(s, slab, object)) {
> + print_slab_info(slab);
> + pr_err("invalid object 0x%p\n", object);
I thought you were going to update the message above based on previous
conversation, "Invalid pointer 0x%p\n"?
> + } else
> + print_trailer(s, slab, object);
Per the coding style guideline [1], an else clause should also use
braces { } when the corresponding if clause does.
[1] https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces
> add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
>
> WARN_ON(1);
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-04 0:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 6:10 [PATCH v4] mm: slub: avoid deref of invalid free pointer in object_err() Li Qiong
2025-08-04 0:35 ` Harry Yoo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).