* [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
@ 2025-07-29 8:14 Li Qiong
2025-07-29 13:41 ` Harry Yoo
0 siblings, 1 reply; 5+ messages in thread
From: Li Qiong @ 2025-07-29 8:14 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 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")
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().
---
mm/slub.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 31e11ef256f9..d3abae5a2193 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);
@@ -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, "Freelist Pointer(0x%p) check fails", object);
return 0;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
2025-07-29 8:14 [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid Li Qiong
@ 2025-07-29 13:41 ` Harry Yoo
2025-07-30 1:46 ` liqiong
0 siblings, 1 reply; 5+ messages in thread
From: Harry Yoo @ 2025-07-29 13:41 UTC (permalink / raw)
To: Li Qiong
Cc: Christoph Lameter, David Rientjes, Andrew Morton, Vlastimil Babka,
Roman Gushchin, linux-mm, linux-kernel, stable
On Tue, Jul 29, 2025 at 04:14:55PM +0800, Li Qiong wrote:
> 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.
As the code changed a bit, I think the commit message could better reflect
what this patch actually does.
> Fixes: bb192ed9aa71 ("mm/slub: Convert most struct page to struct slab by spatch")
As Vlastimil mentioned in previous version, this is not the first commit
that introduced this problem.
> 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().
> ---
> mm/slub.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 31e11ef256f9..d3abae5a2193 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);
Can we just handle this inside print_trailer() because that's the function
that prints the object's free pointer, metadata, etc.?
Also, the message should start with a capital letter.
and "invalid object" sounds misleading because it's the pointer
that is invalid. Perhaps simply "Invalid pointer 0x%p\n"?
(What would be the most comprehensive message here? :P)
> + } else
> + print_trailer(s, slab, object);
> add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
>
> WARN_ON(1);
> @@ -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, "Freelist Pointer(0x%p) check fails", object);
> return 0;
Do we really need this hunk after making object_err() resiliant
against wild pointers?
> }
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
2025-07-29 13:41 ` Harry Yoo
@ 2025-07-30 1:46 ` liqiong
2025-07-30 5:04 ` Harry Yoo
0 siblings, 1 reply; 5+ messages in thread
From: liqiong @ 2025-07-30 1:46 UTC (permalink / raw)
To: Harry Yoo
Cc: David Rientjes, Andrew Morton, Vlastimil Babka, Roman Gushchin,
linux-kernel, stable
在 2025/7/29 21:41, Harry Yoo 写道:
> On Tue, Jul 29, 2025 at 04:14:55PM +0800, Li Qiong wrote:
>> 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.
> As the code changed a bit, I think the commit message could better reflect
> what this patch actually does.
Yes.
>
>> Fixes: bb192ed9aa71 ("mm/slub: Convert most struct page to struct slab by spatch")
> As Vlastimil mentioned in previous version, this is not the first commit
> that introduced this problem.
>
>> 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().
>> ---
>> mm/slub.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index 31e11ef256f9..d3abae5a2193 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);
> Can we just handle this inside print_trailer() because that's the function
> that prints the object's free pointer, metadata, etc.?
Maybe it's clearer , if object pointer being invalid, don't enter print_trailer(),
print_trailer() prints valid object.
>
> Also, the message should start with a capital letter.
>
> and "invalid object" sounds misleading because it's the pointer
> that is invalid. Perhaps simply "Invalid pointer 0x%p\n"?
> (What would be the most comprehensive message here? :P)
Make sense, will change it.
>
>> + } else
>> + print_trailer(s, slab, object);
>> add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
>>
>> WARN_ON(1);
>> @@ -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, "Freelist Pointer(0x%p) check fails", object);
>> return 0;
> Do we really need this hunk after making object_err() resiliant
> against wild pointers?
That's the origin issue, it may be inappropriate to use object_err(), if check_valid_pointer being false.
>
>> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
2025-07-30 1:46 ` liqiong
@ 2025-07-30 5:04 ` Harry Yoo
2025-07-30 8:36 ` liqiong
0 siblings, 1 reply; 5+ messages in thread
From: Harry Yoo @ 2025-07-30 5:04 UTC (permalink / raw)
To: liqiong
Cc: David Rientjes, Andrew Morton, Vlastimil Babka, Roman Gushchin,
linux-kernel, stable
On Wed, Jul 30, 2025 at 09:46:09AM +0800, liqiong wrote:
> 在 2025/7/29 21:41, Harry Yoo 写道:
> > On Tue, Jul 29, 2025 at 04:14:55PM +0800, Li Qiong wrote:
> >> Fixes: bb192ed9aa71 ("mm/slub: Convert most struct page to struct slab by spatch")
> > As Vlastimil mentioned in previous version, this is not the first commit
> > that introduced this problem.
Please don't forget to update Fixes: tag :)
> >> 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().
> >> ---
> >> mm/slub.c | 8 ++++++--
> >> 1 file changed, 6 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/mm/slub.c b/mm/slub.c
> >> index 31e11ef256f9..d3abae5a2193 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);
> > Can we just handle this inside print_trailer() because that's the function
> > that prints the object's free pointer, metadata, etc.?
> Maybe it's clearer , if object pointer being invalid, don't enter print_trailer(),
> print_trailer() prints valid object.
You're probably right. No strong opinion.
object_err() is the only user anyway.
> >> + } else
> >> + print_trailer(s, slab, object);
> >> add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
> >>
> >> WARN_ON(1);
> >> @@ -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, "Freelist Pointer(0x%p) check fails", object);
> >> return 0;
> > Do we really need this hunk after making object_err() resiliant
> > against wild pointers?
>
> That's the origin issue, it may be inappropriate to use object_err(), if check_valid_pointer being false.
That was the original issue, but you're making it not crash even if
with bad pointers are passed?
> >> }
>
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid
2025-07-30 5:04 ` Harry Yoo
@ 2025-07-30 8:36 ` liqiong
0 siblings, 0 replies; 5+ messages in thread
From: liqiong @ 2025-07-30 8:36 UTC (permalink / raw)
To: Harry Yoo
Cc: David Rientjes, Andrew Morton, Vlastimil Babka, Roman Gushchin,
linux-kernel, stable
在 2025/7/30 13:04, Harry Yoo 写道:
> On Wed, Jul 30, 2025 at 09:46:09AM +0800, liqiong wrote:
>> 在 2025/7/29 21:41, Harry Yoo 写道:
>>> On Tue, Jul 29, 2025 at 04:14:55PM +0800, Li Qiong wrote:
>>>> Fixes: bb192ed9aa71 ("mm/slub: Convert most struct page to struct slab by spatch")
>>> As Vlastimil mentioned in previous version, this is not the first commit
>>> that introduced this problem.
> Please don't forget to update Fixes: tag :)
It seems that it's the first commit: 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().
>>>> ---
>>>> mm/slub.c | 8 ++++++--
>>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/mm/slub.c b/mm/slub.c
>>>> index 31e11ef256f9..d3abae5a2193 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);
>>> Can we just handle this inside print_trailer() because that's the function
>>> that prints the object's free pointer, metadata, etc.?
>> Maybe it's clearer , if object pointer being invalid, don't enter print_trailer(),
>> print_trailer() prints valid object.
> You're probably right. No strong opinion.
> object_err() is the only user anyway.
>
>>>> + } else
>>>> + print_trailer(s, slab, object);
>>>> add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
>>>>
>>>> WARN_ON(1);
>>>> @@ -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, "Freelist Pointer(0x%p) check fails", object);
>>>> return 0;
>>> Do we really need this hunk after making object_err() resiliant
>>> against wild pointers?
>> That's the origin issue, it may be inappropriate to use object_err(), if check_valid_pointer being false.
> That was the original issue, but you're making it not crash even if
> with bad pointers are passed?
Make sense, fix in object_err(), it wouldn't crash and print the message.
>
>>>> }
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-30 8:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29 8:14 [PATCH v3] mm: slub: avoid deref of free pointer in sanity checks if object is invalid Li Qiong
2025-07-29 13:41 ` Harry Yoo
2025-07-30 1:46 ` liqiong
2025-07-30 5:04 ` Harry Yoo
2025-07-30 8:36 ` liqiong
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).