From: David Hildenbrand <david@redhat.com>
To: Ming Wang <wangming01@loongson.cn>,
Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Oscar Salvador <osalvador@suse.de>,
Andrii Nakryiko <andrii@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Michal Hocko <mhocko@suse.cz>,
David Rientjes <rientjes@google.com>,
Joern Engel <joern@logfs.org>, Hugh Dickins <hughd@google.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Huacai Chen <chenhuacai@kernel.org>,
lixuefeng@loongson.cn, Hongchen Zhang <zhanghongchen@loongson.cn>
Subject: Re: [PATCH] smaps: Fix crash in smaps_hugetlb_range for non-present hugetlb entries
Date: Wed, 23 Apr 2025 09:07:36 +0200 [thread overview]
Message-ID: <b64aea02-cc44-433a-8214-854feda2c06d@redhat.com> (raw)
In-Reply-To: <20250423010359.2030576-1-wangming01@loongson.cn>
On 23.04.25 03:03, Ming Wang wrote:
> When reading /proc/pid/smaps for a process that has mapped a hugetlbfs
> file with MAP_PRIVATE, the kernel might crash inside pfn_swap_entry_to_page.
> This occurs on LoongArch under specific conditions.
>
> The root cause involves several steps:
> 1. When the hugetlbfs file is mapped (MAP_PRIVATE), the initial PMD
> (or relevant level) entry is often populated by the kernel during mmap()
> with a non-present entry pointing to the architecture's invalid_pte_table
> On the affected LoongArch system, this address was observed to
> be 0x90000000031e4000.
> 2. The smaps walker (walk_hugetlb_range -> smaps_hugetlb_range) reads
> this entry.
> 3. The generic is_swap_pte() macro checks `!pte_present() && !pte_none()`.
> The entry (invalid_pte_table address) is not present. Crucially,
> the generic pte_none() check (`!(pte_val(pte) & ~_PAGE_GLOBAL)`)
> returns false because the invalid_pte_table address is non-zero.
> Therefore, is_swap_pte() incorrectly returns true.
> 4. The code enters the `else if (is_swap_pte(...))` block.
> 5. Inside this block, it checks `is_pfn_swap_entry()`. Due to a bit
> pattern coincidence in the invalid_pte_table address on LoongArch,
> the embedded generic `is_migration_entry()` check happens to return
> true (misinterpreting parts of the address as a migration type).
> 6. This leads to a call to pfn_swap_entry_to_page() with the bogus
> swap entry derived from the invalid table address.
> 7. pfn_swap_entry_to_page() extracts a meaningless PFN, finds an
> unrelated struct page, checks its lock status (unlocked), and hits
> the `BUG_ON(is_migration_entry(entry) && !PageLocked(p))` assertion.
>
> The original code's intent in the `else if` block seems aimed at handling
> potential migration entries, as indicated by the inner `is_pfn_swap_entry()`
> check. The issue arises because the outer `is_swap_pte()` check incorrectly
> includes the invalid table pointer case on LoongArch.
This has a big loongarch smell to it.
If we end up passing !pte_present() && !pte_none(), then loongarch must
be fixed to filter out these weird non-present entries.
is_swap_pte() must not succeed on something that is not an actual swap pte.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-04-23 7:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 1:03 [PATCH] smaps: Fix crash in smaps_hugetlb_range for non-present hugetlb entries Ming Wang
2025-04-23 4:42 ` Huacai Chen
2025-04-23 7:07 ` David Hildenbrand [this message]
2025-04-23 8:14 ` Ming Wang
2025-04-24 12:21 ` David Hildenbrand
2025-04-24 12:36 ` Huacai Chen
2025-04-24 12:39 ` David Hildenbrand
2025-04-25 2:09 ` Ming Wang
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=b64aea02-cc44-433a-8214-854feda2c06d@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=hughd@google.com \
--cc=joern@logfs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=mhocko@suse.cz \
--cc=nao.horiguchi@gmail.com \
--cc=osalvador@suse.de \
--cc=rientjes@google.com \
--cc=ryan.roberts@arm.com \
--cc=wangming01@loongson.cn \
--cc=willy@infradead.org \
--cc=zhanghongchen@loongson.cn \
/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