[PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_interleave
From: Liu Jing
Date: Wed Sep 02 2026 - 05:03:50 EST
In alloc_pages_bulk_interleave(), nodes_weight(pol->nodes) may return
0 if all nodes in the policy mask have been offlined at runtime. The
subsequent division "nr_pages / nodes" triggers a divide-by-zero
panic.
Add a zero check returning 0 (no pages allocated) when the nodemask
is empty, consistent with the guard in
alloc_pages_bulk_weighted_interleave().
Signed-off-by: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
---
mm/mempolicy.c | 3 +++
1 file changed, 3 insertion(+), 0 deletion(-)
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2600,6 +2600,9 @@
unsigned long total_allocated = 0;
nodes = nodes_weight(pol->nodes);
+ if (!nodes)
+ return 0;
+
nr_pages_per_node = nr_pages / nodes;
delta = nr_pages - nodes * nr_pages_per_node;
--
2.43.0