Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: stop hashing address_space pointers for fault mutexes
@ 2026-11-25  6:15 Zhengchuan Liang
  2026-11-25 11:58 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 2+ messages in thread
From: Zhengchuan Liang @ 2026-11-25  6:15 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() uses the address_space pointer and page index
to select an entry in a global mutex table. An unprivileged user can
create a no-reserve HugeTLB memfd with an empty huge page pool, build
contention on one index, and time SIGBUS faults at chosen indices.
Pointer-dependent mutex collisions expose equations that recover the
exact address_space address.

Give each hugetlbfs inode a dedicated random hash seed instead, and hash
the page index with that value. Operations on the same mapping continue
to select the same mutex, while separate mappings retain independent
bucket distributions without encoding an address. The seed is not
relied upon as a secret and is not reused by another hash table.

Fixes: 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability")
Cc: stable@vger.kernel.org
Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
---
 fs/hugetlbfs/inode.c    | 2 ++
 include/linux/hugetlb.h | 1 +
 mm/hugetlb.c            | 9 ++-------
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 558007fa5e88..72a406b97f9e 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -35,6 +35,7 @@
 #include <linux/security.h>
 #include <linux/magic.h>
 #include <linux/migrate.h>
+#include <linux/random.h>
 #include <linux/uio.h>
 
 #include <linux/uaccess.h>
@@ -1182,6 +1183,7 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb)
 		hugetlbfs_inc_free_inodes(sbinfo);
 		return NULL;
 	}
+	p->fault_mutex_hash_seed = get_random_u32();
 	return &p->vfs_inode;
 }
 
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 58f755e70e96..61d833b7a76c 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -504,6 +504,7 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
 struct hugetlbfs_inode_info {
 	struct inode vfs_inode;
 	struct resv_map *resv_map;
+	u32 fault_mutex_hash_seed;
 	unsigned int seals;
 #ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
 	atomic64_t pmd_sharing_count;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ce9c8e57b8e5..6865ff468343 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6091,13 +6091,8 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
 #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);
+	u32 seed = HUGETLBFS_I(mapping->host)->fault_mutex_hash_seed;
+	u32 hash = jhash2((u32 *)&idx, sizeof(idx) / sizeof(u32), seed);
 
 	return hash & (num_fault_mutexes - 1);
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/hugetlb: stop hashing address_space pointers for fault mutexes
  2026-11-25  6:15 [PATCH] mm/hugetlb: stop hashing address_space pointers for fault mutexes Zhengchuan Liang
@ 2026-11-25 11:58 ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-25 11:58 UTC (permalink / raw)
  To: Zhengchuan Liang, Muchun Song
  Cc: Oscar Salvador, Andrew Morton, Davidlohr Bueso, linux-mm,
	linux-kernel

On 11/25/26 07:15, Zhengchuan Liang wrote:
> hugetlb_fault_mutex_hash() uses the address_space pointer and page index
> to select an entry in a global mutex table. An unprivileged user can
> create a no-reserve HugeTLB memfd with an empty huge page pool, build
> contention on one index, and time SIGBUS faults at chosen indices.
> Pointer-dependent mutex collisions expose equations that recover the
> exact address_space address.

I'm not sure we care about this problem. I'll let other speak up.

Attacking hugetlb users is stupid. This doesn't matter in practice.

[I had stupid AI fix that allocated fault mutexes for each inode that I
discarded immediately]

> 
> Give each hugetlbfs inode a dedicated random hash seed instead, and hash
> the page index with that value. Operations on the same mapping continue
> to select the same mutex, while separate mappings retain independent
> bucket distributions without encoding an address. The seed is not
> relied upon as a secret and is not reused by another hash table.

Can't we still end up with the same problem, just slightly different, afterwards?

-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  6:15 [PATCH] mm/hugetlb: stop hashing address_space pointers for fault mutexes Zhengchuan Liang
2026-11-25 11:58 ` David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox