[PATCH v9 07/14] futex: Expose robust_list2 limits via sysctl
From: André Almeida
Date: Fri Dec 04 2026 - 11:16:21 EST
Expose to userspace the limit of robust lists per task and the
number of elements per robust list via sysctl.
Userspace should check this values to safely use set/get_robust_list2()
syscalls.
Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
kernel/futex/core.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index a0a391330408..0dd2f5594061 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -44,6 +44,7 @@
#include <linux/prctl.h>
#include <linux/rseq.h>
#include <linux/slab.h>
+#include <linux/sysctl.h>
#include <linux/vmalloc.h>
#include <linux/kmemleak.h>
#include <linux/wait_bit.h>
@@ -2161,6 +2162,26 @@ int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
return ret;
}
+static int robust_list2_list_limit = FUTEX_ROBUST_LIST2_PER_USER;
+static int robust_list2_elements_per_list = ROBUST_LIST_LIMIT;
+
+static const struct ctl_table futex_sysctls[] = {
+ {
+ .procname = "robust_list2_list_limit",
+ .data = &robust_list2_list_limit,
+ .maxlen = sizeof(int),
+ .mode = 0444,
+ .proc_handler = proc_dointvec,
+ },
+ {
+ .procname = "robust_list2_elements_per_list",
+ .data = &robust_list2_elements_per_list,
+ .maxlen = sizeof(int),
+ .mode = 0444,
+ .proc_handler = proc_dointvec,
+ },
+};
+
static int __init futex_init(void)
{
unsigned long hashsize, i;
@@ -2187,6 +2208,8 @@ static int __init futex_init(void)
runtime_const_init(mask, __futex_mask);
runtime_const_init(ptr, __futex_queues);
+ register_sysctl_init("kernel/futex", futex_sysctls);
+
barrier();
BUG_ON(!futex_queues());
--
2.56.1