* [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree
@ 2025-04-23 22:21 Andrew Morton
2025-04-23 22:40 ` SeongJae Park
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2025-04-23 22:21 UTC (permalink / raw)
To: mm-commits, sj, suhui, akpm
The quilt patch titled
Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
has been removed from the -mm tree. Its filename was
mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch
This patch was dropped because it was withdrawn
------------------------------------------------------
From: Su Hui <suhui@nfschina.com>
Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
Date: Mon, 21 Apr 2025 14:24:24 +0800
It's safer to use kmalloc_array() and size_add() because it can prevent
possible overflow problem.
Link: https://lkml.kernel.org/r/20250421062423.740605-1-suhui@nfschina.com
Signed-off-by: Su Hui <suhui@nfschina.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/damon/sysfs-schemes.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--- a/mm/damon/sysfs-schemes.c~mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add
+++ a/mm/damon/sysfs-schemes.c
@@ -465,7 +465,8 @@ static ssize_t memcg_path_store(struct k
{
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
struct damon_sysfs_scheme_filter, kobj);
- char *path = kmalloc(sizeof(*path) * (count + 1), GFP_KERNEL);
+ char *path = kmalloc_array(size_add(count, 1), sizeof(*path),
+ GFP_KERNEL);
if (!path)
return -ENOMEM;
@@ -2064,7 +2065,7 @@ static int damon_sysfs_memcg_path_to_id(
if (!memcg_path)
return -EINVAL;
- path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
+ path = kmalloc_array(PATH_MAX, sizeof(*path), GFP_KERNEL);
if (!path)
return -ENOMEM;
_
Patches currently in -mm which might be from suhui@nfschina.com are
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree
2025-04-23 22:21 [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree Andrew Morton
@ 2025-04-23 22:40 ` SeongJae Park
2025-04-24 6:00 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: SeongJae Park @ 2025-04-23 22:40 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, mm-commits, suhui, Dan Carpenter,
Christophe JAILLET
Hi Andrew,
On Wed, 23 Apr 2025 15:21:09 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> The quilt patch titled
> Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> has been removed from the -mm tree. Its filename was
> mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch
>
> This patch was dropped because it was withdrawn
>
> ------------------------------------------------------
> From: Su Hui <suhui@nfschina.com>
> Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> Date: Mon, 21 Apr 2025 14:24:24 +0800
>
> It's safer to use kmalloc_array() and size_add() because it can prevent
> possible overflow problem.
>
> Link: https://lkml.kernel.org/r/20250421062423.740605-1-suhui@nfschina.com
> Signed-off-by: Su Hui <suhui@nfschina.com>
> Reviewed-by: SeongJae Park <sj@kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Dan did mention "No need to change"[1], but I think that means this patch needs
no additional change, and hence nobody really asked withdrawal of this patch.
Cc-ing Dan and Christophe to make it clear. Please let me know if I'm
misunderstanindg something.
[1] https://lore.kernel.org/all/fd372c23-1bf7-4c93-a51d-ba5dad255b04@stanley.mountain/
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree
2025-04-23 22:40 ` SeongJae Park
@ 2025-04-24 6:00 ` Dan Carpenter
2025-04-24 6:43 ` SeongJae Park
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2025-04-24 6:00 UTC (permalink / raw)
To: SeongJae Park
Cc: Andrew Morton, mm-commits, suhui, Christophe JAILLET,
Justin Stitt, Kees Cook
Let me add Justin to the CC list because there could be a way to make
this work with a compiler extension.
On Wed, Apr 23, 2025 at 03:40:56PM -0700, SeongJae Park wrote:
> Hi Andrew,
>
> On Wed, 23 Apr 2025 15:21:09 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> >
> > The quilt patch titled
> > Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> > has been removed from the -mm tree. Its filename was
> > mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch
> >
> > This patch was dropped because it was withdrawn
> >
> > ------------------------------------------------------
> > From: Su Hui <suhui@nfschina.com>
> > Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> > Date: Mon, 21 Apr 2025 14:24:24 +0800
> >
> > It's safer to use kmalloc_array() and size_add() because it can prevent
> > possible overflow problem.
> >
> > Link: https://lkml.kernel.org/r/20250421062423.740605-1-suhui@nfschina.com
> > Signed-off-by: Su Hui <suhui@nfschina.com>
> > Reviewed-by: SeongJae Park <sj@kernel.org>
> > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>
> Dan did mention "No need to change"[1], but I think that means this patch needs
> no additional change, and hence nobody really asked withdrawal of this patch.
>
> Cc-ing Dan and Christophe to make it clear. Please let me know if I'm
> misunderstanindg something.
>
> [1] https://lore.kernel.org/all/fd372c23-1bf7-4c93-a51d-ba5dad255b04@stanley.mountain/
The patch isn't necessary.
I don't really think it makes the code more readable. Personally, I feel
like writing "size * sizeof(char)" is ugly. I'd prefer to just have:
path = kmalloc(PATH_MAX, GFP_KERNEL);
It would be nice to not have any math in allocations but it's probably
not workable right now. There are just too many:
$ git grep -w 'kmalloc' | grep '\+' | wc -l
489
$ git grep -w 'kmalloc' | grep ' \* ' | wc -l
494
But here is an idea. I had discussed with Justin that it would be great
if we had a safe_math() macro which does saturation math instead of
wrapping. The problem is that if you have complicated math then
size_add/mul() is a pain.
bytes = size_mul(size_add(count, 1), sizeof(*path))
Terrible. But we could create a macro:
bytes = safe_math(sizeof(*path) * (count + 1));
Look how much nicer that is! This is very doable but the problem is that
compiler features have to be ten years old before we can count on them to
be there on everyone's systems. It's too discouraging to even think
about.
But for kmalloc() we could just hide the safe_math() macro inside
the define:
#define kmalloc(size, gfp) __kmalloc(safe_math(size), (gfp))
We could enable this right away and people without the new compiler
wouldn't be affected.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree
2025-04-24 6:00 ` Dan Carpenter
@ 2025-04-24 6:43 ` SeongJae Park
0 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2025-04-24 6:43 UTC (permalink / raw)
To: Dan Carpenter
Cc: SeongJae Park, Andrew Morton, mm-commits, suhui,
Christophe JAILLET, Justin Stitt, Kees Cook
On Thu, 24 Apr 2025 09:00:52 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:
> Let me add Justin to the CC list because there could be a way to make
> this work with a compiler extension.
>
> On Wed, Apr 23, 2025 at 03:40:56PM -0700, SeongJae Park wrote:
> > Hi Andrew,
> >
> > On Wed, 23 Apr 2025 15:21:09 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > >
> > > The quilt patch titled
> > > Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> > > has been removed from the -mm tree. Its filename was
> > > mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch
> > >
> > > This patch was dropped because it was withdrawn
> > >
> > > ------------------------------------------------------
> > > From: Su Hui <suhui@nfschina.com>
> > > Subject: mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
> > > Date: Mon, 21 Apr 2025 14:24:24 +0800
> > >
> > > It's safer to use kmalloc_array() and size_add() because it can prevent
> > > possible overflow problem.
> > >
> > > Link: https://lkml.kernel.org/r/20250421062423.740605-1-suhui@nfschina.com
> > > Signed-off-by: Su Hui <suhui@nfschina.com>
> > > Reviewed-by: SeongJae Park <sj@kernel.org>
> > > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> >
> > Dan did mention "No need to change"[1], but I think that means this patch needs
> > no additional change, and hence nobody really asked withdrawal of this patch.
> >
> > Cc-ing Dan and Christophe to make it clear. Please let me know if I'm
> > misunderstanindg something.
> >
> > [1] https://lore.kernel.org/all/fd372c23-1bf7-4c93-a51d-ba5dad255b04@stanley.mountain/
>
> The patch isn't necessary.
Thank you, I understand that you are asking to withdraw this patch. I have no
objection to that.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-24 6:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 22:21 [withdrawn] mm-damon-sysfs-schemes-using-kmalloc_array-and-size_add.patch removed from -mm tree Andrew Morton
2025-04-23 22:40 ` SeongJae Park
2025-04-24 6:00 ` Dan Carpenter
2025-04-24 6:43 ` SeongJae Park
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.