* [PATCH v2] sched/topology: change kzalloc to kcalloc
@ 2025-01-19 18:23 Ethan Carter Edwards
2025-02-09 3:45 ` Ethan Carter Edwards
2025-02-09 11:00 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-01-19 18:23 UTC (permalink / raw)
To: mingo
Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
kernel-hardening@lists.openwall.com, bsegall@google.com,
peterz@infradead.org
We are replacing any instances of kzalloc(size * count, ...) with
kcalloc(count, size, ...) due to risk of overflow [1].
[1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Link: https://github.com/KSPP/linux/issues/162
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
V2: fix email client formatting.
kernel/sched/topology.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 9748a4c8d668..17eb12819563 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1920,7 +1920,7 @@ void sched_init_numa(int offline_node)
*/
sched_domains_numa_levels = 0;
- masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL);
+ masks = kcalloc(nr_levels, sizeof(void *), GFP_KERNEL);
if (!masks)
return;
@@ -1929,7 +1929,7 @@ void sched_init_numa(int offline_node)
* CPUs of nodes that are that many hops away from us.
*/
for (i = 0; i < nr_levels; i++) {
- masks[i] = kzalloc(nr_node_ids * sizeof(void *), GFP_KERNEL);
+ masks[i] = kcalloc(nr_node_ids, sizeof(void *), GFP_KERNEL);
if (!masks[i])
return;
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/topology: change kzalloc to kcalloc
2025-01-19 18:23 [PATCH v2] sched/topology: change kzalloc to kcalloc Ethan Carter Edwards
@ 2025-02-09 3:45 ` Ethan Carter Edwards
2025-02-09 11:00 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-02-09 3:45 UTC (permalink / raw)
To: mingo
Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
kernel-hardening@lists.openwall.com, bsegall@google.com,
peterz@infradead.org
I wanted to check in on this. Anything I need to change?
Thanks,
Ethan
On 25/01/19 01:23PM, Ethan Carter Edwards wrote:
> We are replacing any instances of kzalloc(size * count, ...) with
> kcalloc(count, size, ...) due to risk of overflow [1].
>
> [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> Link: https://github.com/KSPP/linux/issues/162
>
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
> ---
> V2: fix email client formatting.
> kernel/sched/topology.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index 9748a4c8d668..17eb12819563 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -1920,7 +1920,7 @@ void sched_init_numa(int offline_node)
> */
> sched_domains_numa_levels = 0;
>
> - masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL);
> + masks = kcalloc(nr_levels, sizeof(void *), GFP_KERNEL);
> if (!masks)
> return;
>
> @@ -1929,7 +1929,7 @@ void sched_init_numa(int offline_node)
> * CPUs of nodes that are that many hops away from us.
> */
> for (i = 0; i < nr_levels; i++) {
> - masks[i] = kzalloc(nr_node_ids * sizeof(void *), GFP_KERNEL);
> + masks[i] = kcalloc(nr_node_ids, sizeof(void *), GFP_KERNEL);
> if (!masks[i])
> return;
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/topology: change kzalloc to kcalloc
2025-01-19 18:23 [PATCH v2] sched/topology: change kzalloc to kcalloc Ethan Carter Edwards
2025-02-09 3:45 ` Ethan Carter Edwards
@ 2025-02-09 11:00 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-02-09 11:00 UTC (permalink / raw)
To: Ethan Carter Edwards, kernel-hardening, linux-hardening,
Ingo Molnar
Cc: LKML, kernel-janitors, Ben Segall, Peter Zijlstra
> We are replacing any instances of kzalloc(size * count, ...) with
> kcalloc(count, size, ...) due to risk of overflow [1].
* See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n94
* How do you think about to use a summary phrase like “Replace two kzalloc() calls
by kcalloc() in sched_init_numa()”?
* Would you be looking for any coccicheck extensions accordingly?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-09 11:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-19 18:23 [PATCH v2] sched/topology: change kzalloc to kcalloc Ethan Carter Edwards
2025-02-09 3:45 ` Ethan Carter Edwards
2025-02-09 11:00 ` Markus Elfring
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).