From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796570335; b=Mc8Eex/GcbepgBiyS23cFcDG7YY8rS3FiGnhRxwltnE8ChDa9q4ak8v8uWyKb/srhTqj DDUSVFJQn7MJOwqtunzWoycjOBfZSHeF9byxP6T09r6wQtTrh3gvrORelh4fnNa3CRTEA V/hEgIsSUXT8/iLxpoIght7xdH3JXCL8k3VMtjVG4ooXasrZw2ZGDcgx2htBFosFXyWHX i6Ma3CzJDoQbKiQDJ36hhPz1BwrSh3FrqjOIpybTAzqxyoDnqq/jtzZBUArSR1CMYSdHy PyB9jvtcOlYHzeAOaiX40Awvcf/xuIiscOFAxBL5lVcnmdrRN0wprNw38ERD4pmr49w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796570335; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=zCSUfr8kvncNCXxrKyg2x6qRB3X6AdX6qOtWIkxlio8=; b=ZbeQs6VnDw34dCSh0yHN4yiwJFhZ1J1CyyFga0seDTSBQsLcYAK5n0qJe3jRvefMbs33 O6Ff2pOd26FeYx5DFNx0/iwVTx5ECRLO6L0BSqUL1QBPoQh+X1mgKxevoGgQSXco98zH9 Lcv4wndFnuOyC5b5tpw0f4mt9Ic2XJ846BK64iX6Oa6op/MA0fyTNbSIvyLe5tTaZJmJS kvw1tMSAeM3wzt2VHIZIHYeFbsmUvKJpxWbkB0AXPbiyxCI1TDOct+5vmfbT1PAXs2BT5 k6aDTld1NG/HDiLmdLic/0THkUagFlQQqet9PSejLJ6F2PXXe/E6s5V57U25R2EHm9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K6CTVBiV; arc=none smtp.remote-ip=209.85.128.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EAB6606A31F for ; Sun, 6 Dec 2026 15:18:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2EAB6606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K6CTVBiV Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso15209185e9.0 for ; Sun, 06 Dec 2026 07:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796570332; x=1797175132; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zCSUfr8kvncNCXxrKyg2x6qRB3X6AdX6qOtWIkxlio8=; b=K6CTVBiVIKuyCWNHllCL2w5OSluxzUojt/2ALOsTTXUew9SqyRFp5MKJLJ4+cROsD8 1D/DN4OCpZWc3qF7e50AG0N7+MiH2JbWiXtFRMQqm8VwAdCtJ+gJaxqXtsFkoR2PbSAw Phh8/pg2XdEBbTnqRFV/nnBKcI4U+/FFMo19enqXa7VfSe9Joc6wInauhZWhikNI9UhH ep34H9Jg52oAR7HJNGTDrMjWJxbsMsQpgsXnZ8X5mzzn06c0yC8CBxDqHZxmlTlLtwo7 R6Ns80ByHMa+MjqnVzygdc1eACq9pwwlfnOmgjw3uDdGM0jKJujcO70e5uOSLovd+eEC FsHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796570332; x=1797175132; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zCSUfr8kvncNCXxrKyg2x6qRB3X6AdX6qOtWIkxlio8=; b=yZ3rjhrz31+PkAaOrsAJ/uz+Y48fzf88g2bh2DWEOton/K/RZqejcAXBIl1w3Mca4m eYcSWbBLbbjkK8UzD9f+tqMK/GJCN08VyNKNNR79HGO6P0v0dJ09mrT26IQhC1a1323C iUgjfSndDI3Mzy/0Ov7WpXSJlhPiJydZVgSQ5/3XjSjVs9bH6VX+JFdPjQnbtz0O/O17 5nidzqygXAryU2xS5SqgBSUVxThF234vni1Xf7C6BrY1T4EDqXlJhcKNAcsF4tTQUzIR bByAl2aX61y6IkogZuHOGw7xC+PIYHAdGhaSjw7mmR9J1zYwUq0zVHS7BvMBMCt5kuzE GtCw== X-Forwarded-Encrypted: i=1; AL+hErGr17a1VlH3+tSP5s0eN/rwfhUqcW1EQKuffYE2g8LuZqPga/8xkoy6jYabucRyUKZw74IeAsQncAE=@vger.kernel.org X-Gm-Message-State: APuU4Z/2WmLUcC8Yv7CwQWObLh4kwpf9onZsjrK28MpY1jyUTv2U1RBS o8Jc063+3vWkNCWUTd5WQgcUVkky4nsjgoJTC1GDEGIuu611DXcs2aJ3 X-Gm-Gg: AZFdTZeFzeDIxSGtvduIfR8yyS0hQ66RUSserj9ZTOXI8r97UgmqV119V+Qm8Vbg8yp xSZGEV7E+WwddIzkVwqoED940MWHKVej6sZFKJTuZpjUyxq0TvW86aWvXsTYTQAf1X7junH6oYE WrnB907vg2fy272mYSBWm+YdykttL+Nmn45tKGqvUHqhySic+u2RzMCGEr5epaBJNspEuSw7nlS RzS5JdnIDOtxTJNh3xVQC7YwGxOXjb/NLUKX0HLY2p0exKZi0GiHY38178yHA/ULn66Yla3xQOt JCFP5r5OS7lVDS0jQIhafd8WC13JicPOVy54487dIc9QYJFueL3R5W1wqSUbU6mNrPe5GWNrQYu pwXAYDBHq3Kgjv8LGRzyCTQyVF3OZLTjJV3ts3n+LLeuRpB+aFqbd8e86thfBVzCz6EYY4qfWoR Aeu3CFpYTKGCMIdxs+acFbAQ17OCPBajXYlQ3BqBMJFju+7snrTkgvKUssV6V4e+bciOsZSFg4r a1MOc/pC4MpSECoSEolnqHUa3/gO4EF/4hoybVpyCw7tjUOyC2ZZSTFkoniHMLsWCgkuQsm/ppP 37ti7KZN0iyT1SRT/JhgQbaUU0O6PWgOOcbrEiKU4DEOTxdMaEv3AuLCRlYvnBcf89gqBEgTcG8 = X-Received: by 2002:a05:600c:3ac5:b0:4bb:647d:dabe with SMTP id 5b1f17b1804b1-4bbeb6fc0e2mr155501855e9.3.1796570332273; Sun, 06 Dec 2026 07:18:52 -0800 (PST) Received: from ?IPV6:2a0d:e487:419d:c934:db1f:58a0:980:8f76? ([2a0d:e487:419d:c934:db1f:58a0:980:8f76]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2a0484sm214535095e9.11.2026.12.06.07.18.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2026 07:18:51 -0800 (PST) Message-ID: Date: Sun, 6 Dec 2026 16:18:48 +0100 X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [libc-coord] [PATCH v9 06/14] futex: Use the multi-robust list infrastructure for current syscalls To: libc-coord@lists.openwall.com, =?UTF-8?Q?Andr=C3=A9_Almeida?= , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Arnd Bergmann , Sebastian Andrzej Siewior , Waiman Long , Ryan Houdek , Florian Weimer , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, kernel-dev@igalia.com References: <20261204-tonyk-robust_futex-v9-0-743d68d488b5@igalia.com> <20261204-tonyk-robust_futex-v9-6-743d68d488b5@igalia.com> Content-Language: en-US From: Gabriel Ravier In-Reply-To: <20261204-tonyk-robust_futex-v9-6-743d68d488b5@igalia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 > --- > 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)