From: Michal Hocko <mhocko@kernel.org>
To: Jingxiangfeng <jingxiangfeng@huawei.com>
Cc: akpm@linux-foundation.org, hughd@google.com,
mike.kravetz@oracle.com, n-horiguchi@ah.jp.nec.com,
aarcange@redhat.com, kirill.shutemov@linux.intel.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/hugetlb: Fix unsigned overflow in __nr_hugepages_store_common()
Date: Mon, 18 Feb 2019 10:27:50 +0100 [thread overview]
Message-ID: <20190218092750.GF4525@dhcp22.suse.cz> (raw)
In-Reply-To: <1550323872-119049-1-git-send-email-jingxiangfeng@huawei.com>
On Sat 16-02-19 21:31:12, Jingxiangfeng wrote:
> From: Jing Xiangfeng <jingxiangfeng@huawei.com>
>
> We can use the following command to dynamically allocate huge pages:
> echo NR_HUGEPAGES > /proc/sys/vm/nr_hugepages
> The count in __nr_hugepages_store_common() is parsed from /proc/sys/vm/nr_hugepages,
> The maximum number of count is ULONG_MAX,
> the operation 'count += h->nr_huge_pages - h->nr_huge_pages_node[nid]' overflow and count will be a wrong number.
Could you be more specific of what is the runtime effect on the
overflow? I haven't checked closer but I would assume that we will
simply shrink the pool size because count will become a small number.
Is there any reason to report an error in that case? We do not report
errors when we cannot allocate the requested number of huge pages so why
is this case any different?
> So check the overflow to fix this problem.
>
> Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
> ---
> mm/hugetlb.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index afef616..55173c3 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2423,7 +2423,12 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
> * per node hstate attribute: adjust count to global,
> * but restrict alloc/free to the specified node.
> */
> + unsigned long old_count = count;
> count += h->nr_huge_pages - h->nr_huge_pages_node[nid];
> + if (count < old_count) {
> + err = -EINVAL;
> + goto out;
> + }
> init_nodemask_of_node(nodes_allowed, nid);
> } else
> nodes_allowed = &node_states[N_MEMORY];
> --
> 2.7.4
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2019-02-18 9:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-16 13:31 [PATCH] mm/hugetlb: Fix unsigned overflow in __nr_hugepages_store_common() Jingxiangfeng
2019-02-18 9:27 ` Michal Hocko [this message]
2019-02-19 23:45 ` Mike Kravetz
2019-02-22 6:10 ` Jing Xiangfeng
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=20190218092750.GF4525@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=jingxiangfeng@huawei.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.kravetz@oracle.com \
--cc=n-horiguchi@ah.jp.nec.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