linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller()
@ 2022-09-14  2:00 Peter Collingbourne
  2022-09-14  6:52 ` Hyeonggon Yoo
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Collingbourne @ 2022-09-14  2:00 UTC (permalink / raw)
  To: Andrey Konovalov, Hyeonggon Yoo, Andrew Morton
  Cc: Peter Collingbourne, linux-mm, linux-kernel, stable

We were failing to call kasan_malloc() from __kmalloc_*track_caller()
which was causing us to sometimes fail to produce KASAN error reports
for allocations made using e.g. devm_kcalloc(), as the KASAN poison was
not being initialized. Fix it.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Cc: <stable@vger.kernel.org> # 5.15
---
The same problem is being fixed upstream in:
https://lore.kernel.org/all/20220817101826.236819-6-42.hyeyoo@gmail.com/
as part of a larger patch series, but this more targeted fix seems
more suitable for the stable kernel. Hyeonggon, maybe you can add
this patch to the start of your series and it can be picked up
by the stable maintainers.

 mm/slub.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/slub.c b/mm/slub.c
index 862dbd9af4f5..875c569c5cbe 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4926,6 +4926,8 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
 	/* Honor the call site pointer we received. */
 	trace_kmalloc(caller, ret, s, size, s->size, gfpflags);
 
+	ret = kasan_kmalloc(s, ret, size, gfpflags);
+
 	return ret;
 }
 EXPORT_SYMBOL(__kmalloc_track_caller);
@@ -4957,6 +4959,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
 	/* Honor the call site pointer we received. */
 	trace_kmalloc_node(caller, ret, s, size, s->size, gfpflags, node);
 
+	ret = kasan_kmalloc(s, ret, size, gfpflags);
+
 	return ret;
 }
 EXPORT_SYMBOL(__kmalloc_node_track_caller);
-- 
2.37.2.789.g6183377224-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller()
  2022-09-14  2:00 [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller() Peter Collingbourne
@ 2022-09-14  6:52 ` Hyeonggon Yoo
  2022-09-16 17:32   ` Vlastimil Babka
  0 siblings, 1 reply; 4+ messages in thread
From: Hyeonggon Yoo @ 2022-09-14  6:52 UTC (permalink / raw)
  To: Peter Collingbourne
  Cc: Andrey Konovalov, Andrew Morton, linux-mm, vbabka, linux-kernel, stable

On Tue, Sep 13, 2022 at 07:00:01PM -0700, Peter Collingbourne wrote:
> We were failing to call kasan_malloc() from __kmalloc_*track_caller()
> which was causing us to sometimes fail to produce KASAN error reports
> for allocations made using e.g. devm_kcalloc(), as the KASAN poison was
> not being initialized. Fix it.
> 
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Cc: <stable@vger.kernel.org> # 5.15
> ---
> The same problem is being fixed upstream in:
> https://lore.kernel.org/all/20220817101826.236819-6-42.hyeyoo@gmail.com/
> as part of a larger patch series, but this more targeted fix seems
> more suitable for the stable kernel. Hyeonggon, maybe you can add
> this patch to the start of your series and it can be picked up
> by the stable maintainers.
> 
>  mm/slub.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 862dbd9af4f5..875c569c5cbe 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4926,6 +4926,8 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
>  	/* Honor the call site pointer we received. */
>  	trace_kmalloc(caller, ret, s, size, s->size, gfpflags);
>  
> +	ret = kasan_kmalloc(s, ret, size, gfpflags);
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL(__kmalloc_track_caller);
> @@ -4957,6 +4959,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
>  	/* Honor the call site pointer we received. */
>  	trace_kmalloc_node(caller, ret, s, size, s->size, gfpflags, node);
>  
> +	ret = kasan_kmalloc(s, ret, size, gfpflags);
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL(__kmalloc_node_track_caller);
> -- 
> 2.37.2.789.g6183377224-goog
>

Ah, I should have sent it to stable team ;)

I think "Option 3" in Documentation/process/stable-kernel-rules.rst will be appropriate,
So will resend this after the series goes to Linus's tree.

Thank you Peter!

-- 
Thanks,
Hyeonggon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller()
  2022-09-14  6:52 ` Hyeonggon Yoo
@ 2022-09-16 17:32   ` Vlastimil Babka
  2022-09-19 11:42     ` Hyeonggon Yoo
  0 siblings, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2022-09-16 17:32 UTC (permalink / raw)
  To: Hyeonggon Yoo, Peter Collingbourne
  Cc: Andrey Konovalov, Andrew Morton, linux-mm, linux-kernel, stable

On 9/14/22 08:52, Hyeonggon Yoo wrote:

Thanks for the Cc.

> On Tue, Sep 13, 2022 at 07:00:01PM -0700, Peter Collingbourne wrote:
>> We were failing to call kasan_malloc() from __kmalloc_*track_caller()
>> which was causing us to sometimes fail to produce KASAN error reports
>> for allocations made using e.g. devm_kcalloc(), as the KASAN poison was
>> not being initialized. Fix it.
>>
>> Signed-off-by: Peter Collingbourne <pcc@google.com>
>> Cc: <stable@vger.kernel.org> # 5.15
>> ---
>> The same problem is being fixed upstream in:

The "upstream" here is now only in -next, not mainline yet, so we still
have more options at this point.

>> https://lore.kernel.org/all/20220817101826.236819-6-42.hyeyoo@gmail.com/
>> as part of a larger patch series, but this more targeted fix seems
>> more suitable for the stable kernel. Hyeonggon, maybe you can add
>> this patch to the start of your series and it can be picked up
>> by the stable maintainers.
...
> 
> Ah, I should have sent it to stable team ;)
> 
> I think "Option 3" in Documentation/process/stable-kernel-rules.rst will be appropriate,
> So will resend this after the series goes to Linus's tree.

I'll pick this for sending to Linus after rc6, which means the series in
slab.git / -next will afterwards cause a trivial conflict to resolve
when merging. AFAIK Linus prefers that over late rebasing.
It will also make it simple for stable.

> Thank you Peter!
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller()
  2022-09-16 17:32   ` Vlastimil Babka
@ 2022-09-19 11:42     ` Hyeonggon Yoo
  0 siblings, 0 replies; 4+ messages in thread
From: Hyeonggon Yoo @ 2022-09-19 11:42 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Peter Collingbourne, Andrey Konovalov, Andrew Morton, linux-mm,
	linux-kernel, stable

On Fri, Sep 16, 2022 at 07:32:50PM +0200, Vlastimil Babka wrote:
> On 9/14/22 08:52, Hyeonggon Yoo wrote:
> 
> Thanks for the Cc.
> 
> > On Tue, Sep 13, 2022 at 07:00:01PM -0700, Peter Collingbourne wrote:
> >> We were failing to call kasan_malloc() from __kmalloc_*track_caller()
> >> which was causing us to sometimes fail to produce KASAN error reports
> >> for allocations made using e.g. devm_kcalloc(), as the KASAN poison was
> >> not being initialized. Fix it.
> >>
> >> Signed-off-by: Peter Collingbourne <pcc@google.com>
> >> Cc: <stable@vger.kernel.org> # 5.15
> >> ---
> >> The same problem is being fixed upstream in:
> 
> The "upstream" here is now only in -next, not mainline yet, so we still
> have more options at this point.
> 
> >> https://lore.kernel.org/all/20220817101826.236819-6-42.hyeyoo@gmail.com/
> >> as part of a larger patch series, but this more targeted fix seems
> >> more suitable for the stable kernel. Hyeonggon, maybe you can add
> >> this patch to the start of your series and it can be picked up
> >> by the stable maintainers.
> ...
> > 
> > Ah, I should have sent it to stable team ;)
> > 
> > I think "Option 3" in Documentation/process/stable-kernel-rules.rst will be appropriate,
> > So will resend this after the series goes to Linus's tree.
> 
> I'll pick this for sending to Linus after rc6, which means the series in
> slab.git / -next will afterwards cause a trivial conflict to resolve
> when merging. AFAIK Linus prefers that over late rebasing.
> It will also make it simple for stable.

I think that is better option, thanks!

> 
> > Thank you Peter!
> > 
> 

-- 
Thanks,
Hyeonggon

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-19 11:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  2:00 [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller() Peter Collingbourne
2022-09-14  6:52 ` Hyeonggon Yoo
2022-09-16 17:32   ` Vlastimil Babka
2022-09-19 11:42     ` Hyeonggon 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).