* [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc()
@ 2024-11-21 13:58 Andy Shevchenko
2024-11-21 14:04 ` Marco Elver
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-11-21 13:58 UTC (permalink / raw)
To: Andy Shevchenko, kasan-dev, linux-kernel; +Cc: Marco Elver, Dmitry Vyukov
Use krealloc_array() to replace krealloc() with multiplication.
krealloc_array() has multiply overflow check, which will be safer.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
kernel/kcsan/debugfs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
index 53b21ae30e00..be7051d0e7f4 100644
--- a/kernel/kcsan/debugfs.c
+++ b/kernel/kcsan/debugfs.c
@@ -166,10 +166,10 @@ static ssize_t insert_report_filterlist(const char *func)
} else if (report_filterlist.used == report_filterlist.size) {
/* resize filterlist */
size_t new_size = report_filterlist.size * 2;
- unsigned long *new_addrs =
- krealloc(report_filterlist.addrs,
- new_size * sizeof(unsigned long), GFP_ATOMIC);
+ unsigned long *new_addrs;
+ new_addrs = krealloc_array(report_filterlist.addrs,
+ new_size, sizeof(*new_addrs), GFP_ATOMIC);
if (new_addrs == NULL) {
/* leave filterlist itself untouched */
ret = -ENOMEM;
--
2.43.0.rc1.1336.g36b5255a03ac
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc()
2024-11-21 13:58 [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc() Andy Shevchenko
@ 2024-11-21 14:04 ` Marco Elver
2024-11-21 14:11 ` Marco Elver
2024-11-21 14:12 ` Andy Shevchenko
0 siblings, 2 replies; 5+ messages in thread
From: Marco Elver @ 2024-11-21 14:04 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: kasan-dev, linux-kernel, Dmitry Vyukov
On Thu, 21 Nov 2024 at 14:58, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Use krealloc_array() to replace krealloc() with multiplication.
> krealloc_array() has multiply overflow check, which will be safer.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Marco Elver <elver@google.com>
Do you have a tree to take this through? Otherwise I'll take it.
> ---
> kernel/kcsan/debugfs.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
> index 53b21ae30e00..be7051d0e7f4 100644
> --- a/kernel/kcsan/debugfs.c
> +++ b/kernel/kcsan/debugfs.c
> @@ -166,10 +166,10 @@ static ssize_t insert_report_filterlist(const char *func)
> } else if (report_filterlist.used == report_filterlist.size) {
> /* resize filterlist */
> size_t new_size = report_filterlist.size * 2;
> - unsigned long *new_addrs =
> - krealloc(report_filterlist.addrs,
> - new_size * sizeof(unsigned long), GFP_ATOMIC);
> + unsigned long *new_addrs;
>
> + new_addrs = krealloc_array(report_filterlist.addrs,
> + new_size, sizeof(*new_addrs), GFP_ATOMIC);
> if (new_addrs == NULL) {
> /* leave filterlist itself untouched */
> ret = -ENOMEM;
> --
> 2.43.0.rc1.1336.g36b5255a03ac
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc()
2024-11-21 14:04 ` Marco Elver
@ 2024-11-21 14:11 ` Marco Elver
2024-11-21 14:16 ` Andy Shevchenko
2024-11-21 14:12 ` Andy Shevchenko
1 sibling, 1 reply; 5+ messages in thread
From: Marco Elver @ 2024-11-21 14:11 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: kasan-dev, linux-kernel, Dmitry Vyukov
On Thu, 21 Nov 2024 at 15:04, Marco Elver <elver@google.com> wrote:
>
> On Thu, 21 Nov 2024 at 14:58, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Use krealloc_array() to replace krealloc() with multiplication.
> > krealloc_array() has multiply overflow check, which will be safer.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Reviewed-by: Marco Elver <elver@google.com>
Unreview.
> Do you have a tree to take this through? Otherwise I'll take it.
Whoops. We got rid of that krealloc() in 59458fa4ddb4 ("kcsan: Turn
report_filterlist_lock into a raw_spinlock"). And the replacement
kmalloc() is already a kmalloc_array(). I suppose this patch is
therefore obsolete.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc()
2024-11-21 14:11 ` Marco Elver
@ 2024-11-21 14:16 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-11-21 14:16 UTC (permalink / raw)
To: Marco Elver; +Cc: kasan-dev, linux-kernel, Dmitry Vyukov
On Thu, Nov 21, 2024 at 03:11:41PM +0100, Marco Elver wrote:
> On Thu, 21 Nov 2024 at 15:04, Marco Elver <elver@google.com> wrote:
> > On Thu, 21 Nov 2024 at 14:58, Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > Use krealloc_array() to replace krealloc() with multiplication.
> > > krealloc_array() has multiply overflow check, which will be safer.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > Reviewed-by: Marco Elver <elver@google.com>
>
> Unreview.
>
> > Do you have a tree to take this through? Otherwise I'll take it.
>
> Whoops. We got rid of that krealloc() in 59458fa4ddb4 ("kcsan: Turn
> report_filterlist_lock into a raw_spinlock"). And the replacement
> kmalloc() is already a kmalloc_array(). I suppose this patch is
> therefore obsolete.
Ah, I made this on top of v6.12 + something most likely unrelated.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc()
2024-11-21 14:04 ` Marco Elver
2024-11-21 14:11 ` Marco Elver
@ 2024-11-21 14:12 ` Andy Shevchenko
1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-11-21 14:12 UTC (permalink / raw)
To: Marco Elver; +Cc: kasan-dev, linux-kernel, Dmitry Vyukov
On Thu, Nov 21, 2024 at 03:04:04PM +0100, Marco Elver wrote:
> On Thu, 21 Nov 2024 at 14:58, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Use krealloc_array() to replace krealloc() with multiplication.
> > krealloc_array() has multiply overflow check, which will be safer.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Reviewed-by: Marco Elver <elver@google.com>
Thank you!
> Do you have a tree to take this through? Otherwise I'll take it.
No, but please, wait a bit, I have a sequential dependent patch.
I'll send a v2 soon.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-21 14:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-21 13:58 [PATCH v1 1/1] kcsan: debugfs: Use krealloc_array() to replace krealloc() Andy Shevchenko
2024-11-21 14:04 ` Marco Elver
2024-11-21 14:11 ` Marco Elver
2024-11-21 14:16 ` Andy Shevchenko
2024-11-21 14:12 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.