From: Shuah Khan <skhan@linuxfoundation.org>
To: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>,
akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com,
linux-kernel-mentees@lists.linuxfoundation.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] lib: cpu_rmap.c Refactor allocation size calculation in kzalloc()
Date: Tue, 7 Oct 2025 16:23:32 -0600 [thread overview]
Message-ID: <10082c41-4302-4cb3-a2bf-788e59bad0c8@linuxfoundation.org> (raw)
In-Reply-To: <20250930092327.27848-1-mehdi.benhadjkhelifa@gmail.com>
On 9/30/25 03:23, Mehdi Ben Hadj Khelifa wrote:
> Wrap allocation size calculation in size_add() and size_mul() to avoid
> any potential overflow.
How did you find this problem and how did you test this change?
>
> Signed-off-by: Mehdi Ben Hadj Khelifa <mehdi.benhadjkhelifa@gmail.com>
> ---
> lib/cpu_rmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
> index f03d9be3f06b..18b2146a73d2 100644
> --- a/lib/cpu_rmap.c
> +++ b/lib/cpu_rmap.c
> @@ -36,7 +36,7 @@ struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags)
> obj_offset = ALIGN(offsetof(struct cpu_rmap, near[nr_cpu_ids]),
> sizeof(void *));
>
> - rmap = kzalloc(obj_offset + size * sizeof(rmap->obj[0]), flags);
> + rmap = kzalloc(size_add(obj_offset, size_mul(size, sizeof(rmap->obj[0]))), flags);
> if (!rmap)
> return NULL;
>
thanks,
-- Shuah
next prev parent reply other threads:[~2025-10-07 22:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 9:23 [PATCH] lib: cpu_rmap.c Refactor allocation size calculation in kzalloc() Mehdi Ben Hadj Khelifa
2025-10-07 22:23 ` Shuah Khan [this message]
2025-10-09 15:16 ` Mehdi Ben Hadj Khelifa
2025-10-10 17:00 ` Shuah Khan
2025-10-18 16:52 ` Mehdi Ben Hadj Khelifa
2025-10-20 20:36 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10082c41-4302-4cb3-a2bf-788e59bad0c8@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=david.hunter.linux@gmail.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mehdi.benhadjkhelifa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox