From: Xiang Gao <gxxa03070307@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org, Xiang Gao <gaoxiang17@xiaomi.com>
Subject: [PATCH] sched/numa: fix division by zero in task_nr_scan_windows() and task_scan_min()
Date: Thu, 16 Apr 2026 14:14:29 +0800 [thread overview]
Message-ID: <20260416061429.723362-1-gxxa03070307@gmail.com> (raw)
From: Xiang Gao <gaoxiang17@xiaomi.com>
sysctl_numa_balancing_scan_size is exposed to userspace via debugfs as
scan_size_mb with no lower-bound validation. Writing 0 triggers
division-by-zero crashes in two places:
task_nr_scan_windows():
nr_scan_pages = MB_TO_PAGES(0) = 0
rss = round_up(rss, 0) <- undefined
return rss / 0 <- division by zero
task_scan_min():
windows = MAX_SCAN_WINDOW / 0 <- division by zero
The third call site in task_numa_work() already guards against this
with an explicit "if (!pages) return;" check at line 3522, but these
two functions lack the same protection.
Fix by clamping scan_size to a minimum of 1 in both functions before
using it as a divisor, consistent with the existing guard in
task_numa_work().
Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
---
kernel/sched/fair.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 69361c63353a..32e146796bd5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1665,6 +1665,8 @@ static unsigned int task_nr_scan_windows(struct task_struct *p)
* on resident pages
*/
nr_scan_pages = MB_TO_PAGES(sysctl_numa_balancing_scan_size);
+ if (!nr_scan_pages)
+ nr_scan_pages = 1;
rss = get_mm_rss(p->mm);
if (!rss)
rss = nr_scan_pages;
@@ -1682,6 +1684,8 @@ static unsigned int task_scan_min(struct task_struct *p)
unsigned int scan, floor;
unsigned int windows = 1;
+ if (!scan_size)
+ scan_size = 1;
if (scan_size < MAX_SCAN_WINDOW)
windows = MAX_SCAN_WINDOW / scan_size;
floor = 1000 / windows;
--
2.34.1
reply other threads:[~2026-04-16 6:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260416061429.723362-1-gxxa03070307@gmail.com \
--to=gxxa03070307@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gaoxiang17@xiaomi.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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
all inboxes | Powered by JetHome®