public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] lib: cpu_rmap.c Refactor allocation size calculation in kzalloc()
@ 2025-09-30  9:23 Mehdi Ben Hadj Khelifa
  2025-10-07 22:23 ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Mehdi Ben Hadj Khelifa @ 2025-09-30  9:23 UTC (permalink / raw)
  To: akpm
  Cc: linux-kernel, skhan, david.hunter.linux, linux-kernel-mentees,
	Mehdi Ben Hadj Khelifa

Wrap allocation size calculation in size_add() and size_mul() to avoid
any potential overflow.

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;
 
-- 
2.51.0


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

end of thread, other threads:[~2025-10-20 20:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox