From: Muchun Song <muchun.song@linux.dev>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Linux Memory Management List <linux-mm@kvack.org>,
linux-kernel@vger.kernel.org,
Muchun Song <songmuchun@bytedance.com>,
Andi Kleen <ak@linux.intel.com>, Sasha Levin <sashal@kernel.org>,
Anders Roxell <anders.roxell@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] hugetlb: check for undefined shift on 32 bit architectures
Date: Thu, 16 Feb 2023 11:01:13 +0800 [thread overview]
Message-ID: <9B09A3E9-09E6-44E4-9B4F-30975C6947B7@linux.dev> (raw)
In-Reply-To: <20230216013542.138708-1-mike.kravetz@oracle.com>
> On Feb 16, 2023, at 09:35, Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
> Users can specify the hugetlb page size in the mmap, shmget and
> memfd_create system calls. This is done by using 6 bits within the
> flags argument to encode the base-2 logarithm of the desired page size.
> The routine hstate_sizelog() uses the log2 value to find the
> corresponding hugetlb hstate structure. Converting the log2 value
> (page_size_log) to potential hugetlb page size is the simple statement:
>
> 1UL << page_size_log
>
> Because only 6 bits are used for page_size_log, the left shift can not
> be greater than 63. This is fine on 64 bit architectures where a long
> is 64 bits. However, if a value greater than 31 is passed on a 32 bit
> architecture (where long is 32 bits) the shift will result in undefined
> behavior. This was generally not an issue as the result of the
> undefined shift had to exactly match hugetlb page size to proceed.
>
> Recent improvements in runtime checking have resulted in this undefined
> behavior throwing errors such as reported below.
>
> Fix by comparing page_size_log to BITS_PER_LONG before doing shift.
>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Link: https://lore.kernel.org/lkml/CA+G9fYuei_Tr-vN9GS7SfFyU1y9hNysnf=PB7kT0=yv4MiPgVg@mail.gmail.com/
> Fixes: 42d7395feb56 ("mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
Acked-by: Muchun Song <songmuchun@bytedance.com>
Thanks.
next prev parent reply other threads:[~2023-02-16 3:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 1:35 Mike Kravetz
2023-02-16 2:08 ` Jesper Juhl
2023-02-16 3:01 ` Muchun Song [this message]
2023-02-16 15:35 ` Naresh Kamboju
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=9B09A3E9-09E6-44E4-9B4F-30975C6947B7@linux.dev \
--to=muchun.song@linux.dev \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=anders.roxell@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naresh.kamboju@linaro.org \
--cc=sashal@kernel.org \
--cc=songmuchun@bytedance.com \
--cc=stable@vger.kernel.org \
/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