futex: Use a keyed hash for global futex buckets
PATCH 1/1 futex: Use a keyed hash for global futex buckets
The global futex hash is a public jhash2 of the key, which for private and shared-anonymous futexes includes an mm_struct pointer. A task can populate a bucket with futex_waitv() and time nonmatching wakes to learn which chosen user addresses collide. Shared-file keys have predictable inode sequence numbers, so the task can also identify the bucket and turn those timings into constraints on current->mm.
The per-mm private hash does not prevent this: a task can disable it through PR_FUTEX_HASH. NUMA-routed private futexes and shared-anonymous keys also use the global hash.
Use SipHash-2-4 with a boot-time random key for global bucket selection. Hash the three identity fields individually, without padding or the separately handled NUMA node. Keep the original futex keys and equality checks, and leave the per-mm hash, which only hashes userspace addresses and offsets, unchanged. Initialize the secret before the global tables are made available and keep it fixed for their lifetime.
--- kernel/futex/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/futex/core.c +11 -2
@@ -42,7 +42,9 @@#include <linux/pagemap.h> #include <linux/plist.h> #include <linux/prctl.h> +#include <linux/random.h> #include <linux/rseq.h> +#include <linux/siphash.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/kmemleak.h>
@@ -58,6 +60,7 @@static u32 __futex_mask__ro_after_init ;static u32 __futex_shift__ro_after_init ;static struct futex_hash_bucket **__futex_queues__ro_after_init ; +static siphash_key_t futex_hash_key__ro_after_init ; static __always_inline struct futex_hash_bucket **futex_queues(void) {
@@ -386,8 +389,12 @@ __futex_hash(union futex_key *key, struct futex_private_hash *fph, struct futex_ }#endif - hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / sizeof(u32), - key->both.offset); +/* +* Global bucket collisions are observable through futex operations. +* Use a keyed hash so they do not disclose the mm pointer in the key. +*/ + hash =siphash_3u64 (key->both.ptr, key->both.word, key->both.offset, + &futex_hash_key);if (node ==FUTEX_NO_NODE ) {/*
@@ -2090,6 +2097,8 @@ static int __init futex_init(void)unsigned int order, n;unsigned long size; +get_random_bytes (&futex_hash_key,sizeof (futex_hash_key)); +#ifdef CONFIG_BASE_SMALL hashsize =16 ;#else
PATCH v2 1/1 futex: Use a keyed hash for global futex buckets
The global futex hash is a public jhash2 of the key, which for private and shared-anonymous futexes includes an mm_struct pointer. A task can populate a bucket with futex_waitv() and time nonmatching wakes to learn which chosen user addresses collide. Shared-file keys have predictable inode sequence numbers, so the task can also identify the bucket and turn those timings into constraints on current->mm.
Lukas Maar, Jonas Juffinger, Thomas Steinbauer, Daniel Gruss, and Stefan Mangard described this futex mm_struct disclosure in KernelSnitch at NDSS 2025. Section VI-B recovers the pointer by observing futex hash collisions and evaluating jhash2 offline.
The per-mm private hash does not prevent this: a task can disable it through PR_FUTEX_HASH. NUMA-routed private futexes and shared-anonymous keys also use the global hash.
Use SipHash-2-4 with a boot-time random key for global bucket selection. Hash the three identity fields individually, without padding or the separately handled NUMA node. Keep the original futex keys and equality checks, and leave the per-mm hash, which only hashes userspace addresses and offsets, unchanged. Initialize the secret before the global tables are made available and keep it fixed for their lifetime.
---
Changes in v2:
- Credit the KernelSnitch authors and link their prior publication.
- Add the original researcher's Reported-by trailer.
- No source changes.
kernel/futex/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/futex/core.c +11 -2
@@ -42,7 +42,9 @@#include <linux/pagemap.h> #include <linux/plist.h> #include <linux/prctl.h> +#include <linux/random.h> #include <linux/rseq.h> +#include <linux/siphash.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/kmemleak.h>
@@ -58,6 +60,7 @@static u32 __futex_mask__ro_after_init ;static u32 __futex_shift__ro_after_init ;static struct futex_hash_bucket **__futex_queues__ro_after_init ; +static siphash_key_t futex_hash_key__ro_after_init ; static __always_inline struct futex_hash_bucket **futex_queues(void) {
@@ -388,8 +391,12 @@ __futex_hash(union futex_key *key, struct futex_private_hash *fph, struct futex_ }#endif - hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / sizeof(u32), - key->both.offset); +/* +* Global bucket collisions are observable through futex operations. +* Use a keyed hash so they do not disclose the mm pointer in the key. +*/ + hash =siphash_3u64 (key->both.ptr, key->both.word, key->both.offset, + &futex_hash_key);if (node ==FUTEX_NO_NODE ) {/*
@@ -2092,6 +2099,8 @@ static int __init futex_init(void)unsigned int order, n;unsigned long size; +get_random_bytes (&futex_hash_key,sizeof (futex_hash_key)); +#ifdef CONFIG_BASE_SMALL hashsize =16 ;#else
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
Thomas Gleixner
maintainerQuoted 16 lines · Kyle Zeng
The global futex hash is a public jhash2 of the key, which for private and shared-anonymous futexes includes an
mm_structpointer. A task can populate a bucket withfutex_waitv()and time nonmatching wakes to learn which chosen user addresses collide. Shared-file keys have predictable inode sequence numbers, so the task can also identify the bucket and turn those timings into constraints oncurrent->mm.Lukas Maar, Jonas Juffinger, Thomas Steinbauer, Daniel Gruss, and Stefan Mangard described this futex
mm_structdisclosure in KernelSnitch at NDSS 2025. Section VI-B recovers the pointer by observing futex hash collisions and evaluating jhash2 offline.The per-mm private hash does not prevent this: a task can disable it through
PR_FUTEX_HASH. NUMA-routed private futexes and shared-anonymous keys also use the global hash.
Quoted 6 lines
Use SipHash-2-4 with a boot-time random key for global bucket selection. Hash the three identity fields individually, without padding or the separately handled NUMA node. Keep the original futex keys and equality checks, and leave the per-mm hash, which only hashes userspace addresses and offsets, unchanged. Initialize the secret before the global tables are made available and keep it fixed for their lifetime.
Fine. Did you evaluate the performance impact of this change?
kernel test robot
build botkernel test robot noticed a -6.0% regression of will-it-scale.per_thread_ops on:
Hello,
kernel test robot noticed a -6.0% regression of will-it-scale.per_thread_ops on:
commit: c44a057178cbedbc04c63404258524975e87a64f ("[PATCH v2] futex: Use a keyed hash for global futex buckets")
url: https://github.com/intel-lab-lkp/linux/commits/Kyle-Zeng/futex-Use-a-keyed-hash-for-global-futex-buckets/20261019-113334
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH v2] futex: Use a keyed hash for global futex buckets
testcase: will-it-scale
config: x86_64-rhel-9.4
compiler: gcc-14
test machine: 224 threads 2 sockets Intel(R) Xeon(R) Platinum 8480CTDX (Sapphire Rapids) with 512G memory parameters:
nr_task: 100%
mode: thread
test: futex2
cpufreq_governor: performance
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
Details are as below:
-------------------------------------------------------------------------------------------------->
The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20261105/[email protected]
=========================================================================================
compiler/cpufreq_governor/kconfig/mode/nr_task/rootfs/tbox_group/test/testcase:
gcc-14/performance/x86_64-rhel-9.4/thread/100%/debian-13-x86_64-20250902.cgz/lkp-spr-2sp5/futex2/will-it-scale
commit:
0fcb05b723 ("Merge tag 'libcrypto-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux")
c44a057178 ("[PATCH v2] futex: Use a keyed hash for global futex buckets")
0fcb05b72344f408 c44a057178cbedbc04c63404258
---------------- ---------------------------
%stddev %change %stddev
\ | \
7.026e+08 -6.0% 6.607e+08 will-it-scale.224.threads 3136755 -6.0% 2949754 will-it-scale.per_thread_ops 7.026e+08 -6.0% 6.607e+08 will-it-scale.workload
Disclaimer:
Results have been estimated based on internal Intel analysis and are provided for informational purposes only. Any difference in system hardware or software design or configuration may affect actual performance.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 52 lines · kernel test robot
Hello,
kernel test robot noticed a -6.0% regression of will-it-scale.per_thread_ops on:
commit:
c44a057178cbedbc04c63404258524975e87a64f("[PATCH v2] futex: Use a keyed hash for global futex buckets")
url: https://github.com/intel-lab-lkp/linux/commits/Kyle-Zeng/futex-Use-a-keyed-hash-for-global-futex-buckets/20261019-113334
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH v2] futex: Use a keyed hash for global futex bucketstestcase: will-it-scale
config: x86_64-rhel-9.4
compiler: gcc-14
test machine: 224 threads 2 sockets Intel(R) Xeon(R) Platinum 8480CTDX (Sapphire Rapids) with 512G memory parameters:
nr_task: 100%
mode: thread
test: futex2
cpufreq_governor: performanceIf you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]Details are as below:
-------------------------------------------------------------------------------------------------->The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20261105/[email protected]=========================================================================================
compiler/cpufreq_governor/kconfig/mode/nr_task/rootfs/tbox_group/test/testcase:
gcc-14/performance/x86_64-rhel-9.4/thread/100%/debian-13-x86_64-20250902.cgz/lkp-spr-2sp5/futex2/will-it-scalecommit:
0fcb05b723("Merge tag 'libcrypto-fixes-for-linus' ofgit://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux")
c44a057178("[PATCH v2] futex: Use a keyed hash for global futex buckets")
0fcb05b72344f408c44a057178cbedbc04c63404258
---------------- ---------------------------
%stddev %change %stddev
\ | \7.026e+08 -6.0% 6.607e+08 will-it-scale.224.threads 3136755 -6.0% 2949754 will-it-scale.per_thread_ops 7.026e+08 -6.0% 6.607e+08 will-it-scale.workload
Quoted 11 lines
Disclaimer:
Results have been estimated based on internal Intel analysis and are provided for informational purposes only. Any difference in system hardware or software design or configuration may affect actual performance.Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
I wonder what is the best way to run this above regression test and what will be an acceptable threshold for the patch to be merged. I'd like to iterate on the patch, fixing the issue while avoiding the the performance regression.
Best,
Kyle