Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_weighted_interleave
@ 2026-09-02  9:04 Liu Jing
  2026-09-02 13:57 ` Gregory Price
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Jing @ 2026-09-02  9:04 UTC (permalink / raw)
  To: akpm
  Cc: david, ziy, matthew.brost, joshua.hahnjy, rakie.kim, byungchul,
	gourry, ying.huang, apopple, linux-mm, linux-kernel, Liu Jing

In alloc_pages_bulk_weighted_interleave(), if the iw_table contains
all-zero weights for every node in the policy nodemask, weight_total
sums to zero. The subsequent "rem_pages / weight_total" and
"rem_pages % weight_total" trigger a divide-by-zero panic.

The function already guards against !nnodes but not against a zero
weight_total. Add the missing check, freeing the locally allocated
weights buffer before returning.

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
 mm/mempolicy.c | 5 +++++
 1 file changed, 5 insertion(+), 0 deletion(-)

--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2697,6 +2697,11 @@
 	/* calculate total, detect system default usage */
 	for_each_node_mask(node, nodes)
 		weight_total += weights[node];
+
+	if (!weight_total) {
+		kfree(weights);
+		return total_allocated;
+	}
 
 	/*
 	 * Calculate rounds/partial rounds to minimize __alloc_pages_bulk calls.

--
2.43.0




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

end of thread, other threads:[~2026-09-02 21:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  9:04 [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_weighted_interleave Liu Jing
2026-09-02 13:57 ` Gregory Price
2026-09-02 21:40   ` Andrew Morton
2026-09-02 21:52     ` Gregory Price

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