From: Mike Rapoport <rppt@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
linux-sh@vger.kernel.org, Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] sh: mm: replace the page size bits in pte_mkhuge()
Date: Wed, 28 Oct 2026 21:11:21 +0200 [thread overview]
Message-ID: <auJI2blzfpFD9yLe@kernel.org> (raw)
In-Reply-To: <20260926183904.76186-2-kmehltretter@gmail.com>
On Sat, Sep 26, 2026 at 08:39:03PM +0200, Karl Mehltretter wrote:
> pte_mkhuge() ORs _PAGE_SZHUGE into a PTE that already carries the base
> page size from _PAGE_FLAGS_HARD, which every PAGE_* protection
> includes. The PTEL size field is an encoding, not a set of flags: on
> SH-4 with 4 KiB pages and 64 KiB huge pages, _PAGE_SZ0 | _PAGE_SZ1
> selects a 1 MiB page. Every hugetlb mapping is therefore loaded into
> the UTLB as a 1 MiB page whose physical base is the huge page's address
> rounded down to 1 MiB, so user accesses land in unrelated kernel
> memory.
>
> In a QEMU r2d guest, after touching a MAP_HUGETLB mapping at
> 0x30000000, QEMU's "info tlb" shows
>
> vpn=c0000 ppn=32e00 sz=3 size=1048576
>
> and writing the two huge pages overwrites kernel data, for example
> page tables ("bad pgd 5a5a5a5a" on munmap) or a struct file:
>
> Fault in unaligned fixup: 0000 [#1]
> PC is at file_tty_write.isra.0+0x24/0x220
> R1 : 5a5a5a5a
>
> The SH-X2 extended size field has the same problem: a 4 KiB base page
> (ESZ0) combined with 64 KiB huge pages (ESZ2) encodes 256 KiB. Only the
> configurations whose huge size encoding happens to contain the base
> encoding, such as 1 MiB over 4 KiB on SH-4, have worked.
>
> Clear the size field before setting the huge page size. All hugetlb
> PTE constructors, including huge_pte_modify() on mprotect() and the
> fork/COW paths, go through arch_make_huge_pte() and so pte_mkhuge().
> With this change the same entry is loaded as
>
> vpn=c0000 ppn=32e00 sz=2 size=65536
>
> and the mappings read back correctly after mprotect() and fork()/COW.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
This implies nobody ever used hugetlb on sh-4, doesn't it?
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> arch/sh/include/asm/pgtable_32.h | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-10-28 19:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 18:39 [PATCH 0/2] sh: mm: fix hugetlb on SH-4 Karl Mehltretter
2026-09-26 18:39 ` [PATCH 1/2] sh: mm: replace the page size bits in pte_mkhuge() Karl Mehltretter
2026-10-28 19:11 ` Mike Rapoport [this message]
2026-09-26 18:39 ` [PATCH 2/2] sh: mm: align hugetlb mappings to the huge page size Karl Mehltretter
2026-09-26 18:43 ` [PATCH 0/2] sh: mm: fix hugetlb on SH-4 John Paul Adrian Glaubitz
2026-09-27 18:35 ` Karl Mehltretter
2026-09-27 19:58 ` John Paul Adrian Glaubitz
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=auJI2blzfpFD9yLe@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dalias@libc.org \
--cc=david@kernel.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=kmehltretter@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sh@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=ysato@users.sourceforge.jp \
/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®