* [PATCH v2] mm/hugetlb: stop hashing address_space pointers for fault mutexes
@ 2026-12-06 0:42 Zhengchuan Liang
2026-12-06 2:53 ` Muchun Song
2026-12-06 4:09 ` + mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch added to mm-unstable branch Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Zhengchuan Liang @ 2026-12-06 0:42 UTC (permalink / raw)
To: Muchun Song
Cc: Oscar Salvador, David Hildenbrand, Andrew Morton, Davidlohr Bueso,
linux-mm, linux-kernel, Zhengchuan Liang
hugetlb_fault_mutex_hash() hashes an address_space pointer and huge page
index to select a mutex from a global table. An unprivileged process can
exercise it by faulting a HugeTLB memfd mapped with MAP_NORESERVE. The
mutex is selected before allocation, so the hash remains reachable when
no huge pages are available and the fault returns SIGBUS.
Fault timing under contention reveals whether chosen indices share a
bucket. These collisions allow exact recovery of the mapping pointer over
the allocator-valid address range. Since address_space is embedded at a
fixed offset in struct hugetlbfs_inode_info, the leak also identifies the
containing hugetlbfs_inode_cache object and replacement objects if its
slab page is later reused.
Hash only the page index and use mapping->host->i_ino as the seed.
hugetlbfs assigns each inode a nonzero 32-bit value from get_next_ino()
before exposing the inode, and the value remains stable for the inode's
lifetime. jhash2() mixes the inode number before reducing the result to
the mutex table size; the seed does not need to be unique, random, or
secret. This keeps the same mapping and index on the same mutex while
varying bucket selection by inode, without encoding a kernel address.
Fixes: 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
Cc: stable@vger.kernel.org
Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
---
Changes in v2:
- Use the public, lifetime-stable hugetlbfs inode number as the hash seed
instead of adding a random field to struct hugetlbfs_inode_info.
- Make the resulting hash const.
- Explain the timing-collision recovery and cross-cache impact.
- Drop David's Reviewed-by and Oscar's Acked-by because the implementation
changed.
v1: https://lore.kernel.org/r/9a97a64f7e7aabc668499c426a2417a77d13a2f4.1795587203.git.zcliangcn@gmail.com
---
mm/hugetlb.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f0119f440..a0f25fbb1 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6295,13 +6295,8 @@ backout_unlocked:
#ifdef CONFIG_SMP
u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx)
{
- unsigned long key[2];
- u32 hash;
-
- key[0] = (unsigned long) mapping;
- key[1] = idx;
-
- hash = jhash2((u32 *)&key, sizeof(key)/(sizeof(u32)), 0);
+ const u32 hash = jhash2((u32 *)&idx, sizeof(idx) / sizeof(u32),
+ mapping->host->i_ino);
return hash & (num_fault_mutexes - 1);
}
base-commit: 2d2d9f22c9c7ae457ba93480ba82ebf57cbf0df8
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm/hugetlb: stop hashing address_space pointers for fault mutexes
2026-12-06 0:42 [PATCH v2] mm/hugetlb: stop hashing address_space pointers for fault mutexes Zhengchuan Liang
@ 2026-12-06 2:53 ` Muchun Song
2026-12-06 4:09 ` + mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch added to mm-unstable branch Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2026-12-06 2:53 UTC (permalink / raw)
To: Zhengchuan Liang
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton,
Davidlohr Bueso, linux-mm, linux-kernel
> On Dec 6, 2026, at 08:42, Zhengchuan Liang <zcliangcn@gmail.com> wrote:
>
> hugetlb_fault_mutex_hash() hashes an address_space pointer and huge page
> index to select a mutex from a global table. An unprivileged process can
> exercise it by faulting a HugeTLB memfd mapped with MAP_NORESERVE. The
> mutex is selected before allocation, so the hash remains reachable when
> no huge pages are available and the fault returns SIGBUS.
>
> Fault timing under contention reveals whether chosen indices share a
> bucket. These collisions allow exact recovery of the mapping pointer over
> the allocator-valid address range. Since address_space is embedded at a
> fixed offset in struct hugetlbfs_inode_info, the leak also identifies the
> containing hugetlbfs_inode_cache object and replacement objects if its
> slab page is later reused.
>
> Hash only the page index and use mapping->host->i_ino as the seed.
> hugetlbfs assigns each inode a nonzero 32-bit value from get_next_ino()
> before exposing the inode, and the value remains stable for the inode's
> lifetime. jhash2() mixes the inode number before reducing the result to
> the mutex table size; the seed does not need to be unique, random, or
> secret. This keeps the same mapping and index on the same mutex while
> varying bucket selection by inode, without encoding a kernel address.
>
> Fixes: 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* + mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch added to mm-unstable branch
2026-12-06 0:42 [PATCH v2] mm/hugetlb: stop hashing address_space pointers for fault mutexes Zhengchuan Liang
2026-12-06 2:53 ` Muchun Song
@ 2026-12-06 4:09 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-12-06 4:09 UTC (permalink / raw)
To: mm-commits, stable, osalvador, muchun.song, davidlohr, david,
zcliangcn, akpm
The patch titled
Subject: mm/hugetlb: stop hashing address_space pointers for fault mutexes
has been added to the -mm mm-unstable branch. Its filename is
mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Zhengchuan Liang <zcliangcn@gmail.com>
Subject: mm/hugetlb: stop hashing address_space pointers for fault mutexes
Date: Sat, 5 Dec 2026 16:42:39 -0800
hugetlb_fault_mutex_hash() hashes an address_space pointer and huge page
index to select a mutex from a global table. An unprivileged process can
exercise it by faulting a HugeTLB memfd mapped with MAP_NORESERVE. The
mutex is selected before allocation, so the hash remains reachable when no
huge pages are available and the fault returns SIGBUS.
Fault timing under contention reveals whether chosen indices share a
bucket. These collisions allow exact recovery of the mapping pointer over
the allocator-valid address range. Since address_space is embedded at a
fixed offset in struct hugetlbfs_inode_info, the leak also identifies the
containing hugetlbfs_inode_cache object and replacement objects if its
slab page is later reused.
Hash only the page index and use mapping->host->i_ino as the seed.
hugetlbfs assigns each inode a nonzero 32-bit value from get_next_ino()
before exposing the inode, and the value remains stable for the inode's
lifetime. jhash2() mixes the inode number before reducing the result to
the mutex table size; the seed does not need to be unique, random, or
secret. This keeps the same mapping and index on the same mutex while
varying bucket selection by inode, without encoding a kernel address.
Link: https://patch.msgid.link/20261206004239.3250411-1-zcliangcn@gmail.com
Fixes: 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: Davidlohr Bueso <davidlohr@hp.com>
Cc: <stable@vger.kernel.org>
mm/hugetlb.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
--- a/mm/hugetlb.c~mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes
+++ a/mm/hugetlb.c
@@ -6295,13 +6295,8 @@ backout_unlocked:
#ifdef CONFIG_SMP
u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx)
{
- unsigned long key[2];
- u32 hash;
-
- key[0] = (unsigned long) mapping;
- key[1] = idx;
-
- hash = jhash2((u32 *)&key, sizeof(key)/(sizeof(u32)), 0);
+ const u32 hash = jhash2((u32 *)&idx, sizeof(idx) / sizeof(u32),
+ mapping->host->i_ino);
return hash & (num_fault_mutexes - 1);
}
_
Patches currently in -mm which might be from zcliangcn@gmail.com are
mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-06 4:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 0:42 [PATCH v2] mm/hugetlb: stop hashing address_space pointers for fault mutexes Zhengchuan Liang
2026-12-06 2:53 ` Muchun Song
2026-12-06 4:09 ` + mm-hugetlb-stop-hashing-address_space-pointers-for-fault-mutexes.patch added to mm-unstable branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.