From: Gregory Price <gourry@gourry.net>
To: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
Cc: akpm@linux-foundation.org, david@redhat.com,
joshua.hahnjy@gmail.com, ziy@nvidia.com,
ying.huang@linux.alibaba.com, rakie.kim@sk.com, byungchul@sk.com,
apopple@nvidia.com, linux-mm@kvack.org
Subject: Re: [PATCH] mm/mempolicy: prevent the risk of division by 0
Date: Mon, 8 Sep 2025 14:12:29 -0400 [thread overview]
Message-ID: <aL8cjd1mIAamBzXo@gourry-fedora-PF4VCD3F> (raw)
In-Reply-To: <20250907160829.91628-1-chelsyratnawat2001@gmail.com>
On Sun, Sep 07, 2025 at 09:08:29AM -0700, Chelsy Ratnawat wrote:
> If no bits are set in the policy's node mask, then nodes will be 0.
> This patch adds a check if nodes == 0 before dividing.
>
> Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
> ---
> mm/mempolicy.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index eb83cff7db8c..faacc604fc16 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -2530,6 +2530,8 @@ static unsigned long alloc_pages_bulk_interleave(gfp_t gfp,
> unsigned long total_allocated = 0;
>
> nodes = nodes_weight(pol->nodes);
> + if (nodes == 0)
> + return 0;
3 second look at this code would tell you the only way this can happen
is a mempolicy where MPOL_INTERLEAVE is set and the nodemask is empty
The only way this can occur is
1) someone setting that explicitly, which is invalid and protected by
a line in mpol_new:
else if (nodes_empty(*nodes))
return ERR_PTR(-EINVAL);
2) or a rebind event occurring due to a cgroup task migration or
cpuset change - which is protected by a check in the rebind:
if (nodes_empty(tmp))
tmp = *nodes;
I doubt this bug was observed in action.
> nr_pages_per_node = nr_pages / nodes;
> delta = nr_pages - nodes * nr_pages_per_node;
>
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2025-09-08 18:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-07 16:08 Chelsy Ratnawat
2025-09-07 23:53 ` Joshua Hahn
2025-09-08 3:48 ` Huang, Ying
2025-09-08 7:50 ` David Hildenbrand
2025-09-08 18:12 ` Gregory Price [this message]
2025-09-08 21:25 ` Gregory Price
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=aL8cjd1mIAamBzXo@gourry-fedora-PF4VCD3F \
--to=gourry@gourry.net \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=chelsyratnawat2001@gmail.com \
--cc=david@redhat.com \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-mm@kvack.org \
--cc=rakie.kim@sk.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.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