From: Gabriel Ravier <gabravier@gmail.com>
To: libc-coord@lists.openwall.com,
"André Almeida" <andrealmeid@igalia.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Arnd Bergmann" <arnd@arndb.de>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Waiman Long" <longman@redhat.com>,
"Ryan Houdek" <Sonicadvance1@gmail.com>,
"Florian Weimer" <fweimer@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-api@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [libc-coord] [PATCH v9 06/14] futex: Use the multi-robust list infrastructure for current syscalls
Date: Sun, 6 Dec 2026 16:18:48 +0100 [thread overview]
Message-ID: <e841aa9a-2deb-4904-9bbb-2eadf8636881@gmail.com> (raw)
In-Reply-To: <20261204-tonyk-robust_futex-v9-6-743d68d488b5@igalia.com>
On 12/4/26 5:15 PM, André Almeida wrote:
> Use the multi-robust list infrastructure for the current system calls and
> drop robust_list and robust_list32 from struct futex_sched_data, relying
> solely on the robust_lists member. Make use of the reserved array positions
> for the current system call and the compat entry point.
>
> For the robust_list_clear_pending() functions, walk the array of robust
> list heads checking which one, if any, matches the pop address.
>
> Syscall set_robust_list() now can return -ENOMEM in case the allocation
> fails.
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> include/linux/futex.h | 4 ----
> include/linux/futex_types.h | 4 ----
> kernel/futex/core.c | 58 +++++++++++++++++++++++++++++++--------------
> kernel/futex/syscalls.c | 24 +++++++++++++++----
> 4 files changed, 59 insertions(+), 31 deletions(-)
>
> diff --git a/include/linux/futex.h b/include/linux/futex.h
> index 0da95f94cfe9..75a83f262d1c 100644
> --- a/include/linux/futex.h
> +++ b/include/linux/futex.h
> @@ -72,10 +72,6 @@ static inline void futex_init_task(struct task_struct *tsk)
> INIT_LIST_HEAD(&tsk->futex.pi_state_list);
> tsk->futex.state = FUTEX_STATE_OK;
> mutex_init(&tsk->futex.exit_mutex);
> - tsk->futex.robust_list = NULL;
> -#ifdef CONFIG_COMPAT
> - tsk->futex.robust_list32 = NULL;
> -#endif
> tsk->futex.robust_lists = NULL;
> }
>
> diff --git a/include/linux/futex_types.h b/include/linux/futex_types.h
> index 20123110c80d..a2b4ec0cb125 100644
> --- a/include/linux/futex_types.h
> +++ b/include/linux/futex_types.h
> @@ -21,10 +21,6 @@ struct robust_list_head;
> * @state: Futex handling state to handle exit races correctly
> */
> struct futex_sched_data {
> - struct robust_list_head __user *robust_list;
> -#ifdef CONFIG_COMPAT
> - struct robust_list_head32 __user *robust_list32;
> -#endif
> uintptr_t *robust_lists;
> struct list_head pi_state_list;
> struct futex_pi_state *pi_state_cache;
> diff --git a/kernel/futex/core.c b/kernel/futex/core.c
> index d15906f3c80c..a0a391330408 100644
> --- a/kernel/futex/core.c
> +++ b/kernel/futex/core.c
> @@ -1223,7 +1223,8 @@ static void exit_robust_list(struct task_struct *curr,
>
> static bool robust_list_clear_pending(unsigned long __user *pop)
> {
> - struct robust_list_head __user *head = current->futex.robust_list;
> + uintptr_t *rl = current->futex.robust_lists;
> + unsigned int i;
>
> if (!put_user(0UL, pop))
> return true;
> @@ -1237,8 +1238,24 @@ static bool robust_list_clear_pending(unsigned long __user *pop)
> * task exits. Better a few stale futexes than corrupted memory. But
> * that's mostly an academic exercise.
> */
> - if (pop == (unsigned long __user *)&head->list_op_pending)
> - current->futex.robust_list = NULL;
> + if (!rl)
> + return false;
> +
> + for (i = 0; i < FUTEX_ROBUST_LIST2_MAX_IDX; i++) {
> + struct robust_list_head __user *head;
> +
> + if (!rl[i] || rl[i] & FUTEX_ROBUST_LIST2_ENTRY_32BIT)
> + continue;
> +
> + head = (struct robust_list_head __user *)
> + (rl[i] & FUTEX_ROBUST_LIST2_ENTRY_MASK);
> +
> + if (pop == (unsigned long __user *)&head->list_op_pending) {
> + rl[i] = (uintptr_t) NULL;
> + break;
> + }
> + }
> +
> return false;
> }
>
> @@ -1342,14 +1359,31 @@ static void exit_robust_list32(struct task_struct *curr,
>
> static bool robust_list_clear_pending32(u32 __user *pop)
> {
> - struct robust_list_head32 __user *head = current->futex.robust_list32;
> + uintptr_t *rl = current->futex.robust_lists;
> + unsigned int i;
>
> if (!put_user(0U, pop))
> return true;
>
> /* See comment in robust_list_clear_pending(). */
> - if (pop == &head->list_op_pending)
> - current->futex.robust_list32 = NULL;
> + if (!rl)
> + return false;
> +
> + for (i = 0; i < FUTEX_ROBUST_LIST2_MAX_IDX; i++) {
> + struct robust_list_head32 __user *head;
> +
> + if (!rl[i] || !(rl[i] & FUTEX_ROBUST_LIST2_ENTRY_32BIT))
> + continue;
> +
> + head = (struct robust_list_head32 __user *)
> + (rl[i] & FUTEX_ROBUST_LIST2_ENTRY_MASK);
> +
> + if (pop == (unsigned __user *)&head->list_op_pending) {
> + rl[i] = (uintptr_t) NULL;
> + break;
> + }
> + }
> +
> return false;
> }
> #else
> @@ -1514,18 +1548,6 @@ static void futex_cleanup(struct task_struct *tsk)
> if (unlikely(tsk->futex.robust_lists))
> exit_robust_lists(tsk);
>
> - if (unlikely(tsk->futex.robust_list)) {
> - exit_robust_list(tsk, tsk->futex.robust_list);
> - tsk->futex.robust_list = NULL;
> - }
> -
> -#ifdef CONFIG_64BIT
> - if (unlikely(tsk->futex.robust_list32)) {
> - exit_robust_list32(tsk, tsk->futex.robust_list32);
> - tsk->futex.robust_list32 = NULL;
> - }
> -#endif
> -
> if (unlikely(!list_empty(&tsk->futex.pi_state_list)))
> exit_pi_state_list(tsk);
> }
> diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c
> index 4a45bace75fc..8e7aec8fe03b 100644
> --- a/kernel/futex/syscalls.c
> +++ b/kernel/futex/syscalls.c
> @@ -27,21 +27,31 @@
> */
> SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head, size_t, len)
> {
> + uintptr_t *rl = futex_get_robust_lists();
> +
> /* The kernel knows only one size for now. */
> if (unlikely(len != sizeof(*head)))
> return -EINVAL;
>
> - current->futex.robust_list = head;
> + if (!rl)
> + return -ENOMEM;
> +
> + rl[FUTEX_ROBUST_LIST2_NATIVE_IDX] = (uintptr_t)head;
> return 0;
> }
>
> static inline void __user *futex_task_robust_list(struct task_struct *p, bool compat)
> {
> + uintptr_t *rl = p->futex.robust_lists;
> +
> + if (!rl)
> + return NULL;
> +
> #ifdef CONFIG_COMPAT
> if (compat)
> - return p->futex.robust_list32;
> + return (void __user *)rl[FUTEX_ROBUST_LIST2_COMPAT_IDX];
> #endif
> - return p->futex.robust_list;
> + return (void __user *)rl[FUTEX_ROBUST_LIST2_NATIVE_IDX];
> }
>
> static void __user *futex_get_robust_list_common(int pid, bool compat)
> @@ -76,7 +86,7 @@ static void __user *futex_get_robust_list_common(int pid, bool compat)
> up_read(&p->signal->exec_update_lock);
> put_task_struct(p);
>
> - return head;
> + return (void __user *)((uintptr_t) head & FUTEX_ROBUST_LIST2_ENTRY_MASK);
>
> err_unlock:
> up_read(&p->signal->exec_update_lock);
> @@ -481,11 +491,15 @@ SYSCALL_DEFINE4(futex_requeue,
> COMPAT_SYSCALL_DEFINE2(set_robust_list, struct robust_list_head32 __user *, head,
> compat_size_t, len)
> {
> + uintptr_t *rl = futex_get_robust_lists();
> +
> if (unlikely(len != sizeof(*head)))
> return -EINVAL;
>
> - current->futex.robust_list32 = head;
> + if (!rl)
> + return -ENOMEM;
>
> + rl[FUTEX_ROBUST_LIST2_COMPAT_IDX] = (uintptr_t)head | FUTEX_ROBUST_LIST2_ENTRY_32BIT;
> return 0;
> }
>
>
Can't this UAF?
As in:
- Reader holds exec_update_lock plus task ref
- Does rl = p->futex.robust_lists; if (!rl) ...; then references rl[i]
- In the meantime, the target task does exit/exec and goes to
futex_cleanup() (exit never takes exec_update_lock, and exec cleans up
in exec_mmap before down_write)
- Reader now dereferences rl[i] simultaneously to a kfree(rl)
(exit_robust_lists in patch 5) -> 8-byte heap info leak to userspace
Patch 5 says robust_lists is always empty, which, sure, at that point,
but this patch populates it :)
(patch 9 makes futex_task_robust_list take an index but the
load-then-deref pattern stays the same)
next prev parent reply other threads:[~2026-12-06 15:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:15 [PATCH v9 00/14] futex: Create {set,get}_robust_list2() syscalls André Almeida
2026-12-04 16:15 ` [PATCH v9 01/14] futex: Use explicit sizes for compat_robust_list structs André Almeida
2026-12-04 16:15 ` [PATCH v9 02/14] futex: Make exit_robust_list32() unconditionally available for 64-bit kernels André Almeida
2026-12-04 16:15 ` [PATCH v9 03/14] futex: Give a specific head pointer to exit_robust_list() André Almeida
2026-12-04 16:15 ` [PATCH v9 04/14] futex: Introduce futex_get_robust_lists() and futex_sched_data::robust_lists André Almeida
2026-12-06 15:42 ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 05/14] futex: Create exit_robust_lists() for multi-robust list André Almeida
2026-12-05 9:55 ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 06/14] futex: Use the multi-robust list infrastructure for current syscalls André Almeida
2026-12-06 15:18 ` Gabriel Ravier [this message]
2026-12-06 15:45 ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 07/14] futex: Expose robust_list2 limits via sysctl André Almeida
2026-12-04 16:15 ` [PATCH v9 08/14] futex: Create syscall set_robust_list2() André Almeida
2026-12-06 15:47 ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 09/14] futex: Make futex_task_robust_list() get list by index André Almeida
2026-12-04 16:15 ` [PATCH v9 10/14] futex: Create get_robust_list2() syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 11/14] futex: Wire up set_robust_list2 syscall André Almeida
2026-12-05 9:55 ` kernel test robot
2026-12-05 9:55 ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 12/14] futex: Wire up get_robust_list2 syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 13/14] selftests/futex: Expand for set_robust_list2() André Almeida
2026-12-06 16:03 ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 14/14] selftests/futex: Expand for get_robust_list2() André Almeida
2026-12-06 16:06 ` [libc-coord] " Gabriel Ravier
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=e841aa9a-2deb-4904-9bbb-2eadf8636881@gmail.com \
--to=gabravier@gmail.com \
--cc=Sonicadvance1@gmail.com \
--cc=andrealmeid@igalia.com \
--cc=arnd@arndb.de \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=fweimer@redhat.com \
--cc=kernel-dev@igalia.com \
--cc=libc-coord@lists.openwall.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
/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