From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796088448; b=2Lr8TSyuKB40kU2Aa7RIkDfMxvNWIZewM4eyTO6tpqvUgsX4S7shWPrWOW8Kgye+29r3 ySn9hmPVR9HRBV8wzFlfhOYIeqVNpij6aEKxdVaUn868LgZkFivup09PP0mr9TBSUueBP 04SYNv/o3WdkT04QkV6U+FV7GAsF7mStrARpOnQ8tO+msHc77Znm1IhRK4iYXlyhM2oF1 fIFMrZo6ySnizpIn1lKHopMvzFYgJcGZBfuDsIrfYybrl35+tCzRUtXWVZJnzBswkDmZb oDAopAE+pTmUXvm4JTDZSksKRGDLJ0lXW9EvUn4cudzUkkFtmBLFIY/7Hgsd/C9mRiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796088448; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=91EgVBaYD/1dF95/nBm5EDW1Z3T2ZoIB0QyWMTEQw/g=; b=ERC18mTAndyems6oNUJgp8Pm5+9NHPKFqxtWpjZ70YtnEE3wCrytIyZG0xXRnUjKm18D H/TLPsQ8i0+FfKLpByH+pEXLxoAutaCxvwJrtJbYVxpeyvQsRHuz7nd0ObWQQF8YJxwVb Ooyfi1aJlkdpwk4Vq/b11FKRfwmF2FxXUqiW9z98NGJbxp3RQNBmi6klGRy29T5BsMVj0 zcEp/gtG+fO3q1jxSS9gzPUtg8k9oWfQCZhnc968qlZGmM7hxI5CadNmxal3XlLhEuXHI 3LHW7D2GSIQ4wlyjXEOY+04U+XpxEDb//Lu/iTQ7Q6Sg6vbiyHqcwMGMnOcINAXCF+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gja0Hq7v; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 565C6606A320; Tue, 1 Dec 2026 01:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gja0Hq7v Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C61E1F000C1; Tue, 1 Dec 2026 01:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796088447; bh=91EgVBaYD/1dF95/nBm5EDW1Z3T2ZoIB0QyWMTEQw/g=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Gja0Hq7vVhxf0khZTjTVjxjsFpqyV6Bg7PnPRZyzikbqqkGO1h3YHpaVaTjZcUWts h2AXNX/r0YWJDruFO/4Sq8h7c0FmB86E7UJ90Pi9S7dLjbuabk2Fv1RASGmDe7BKBQ +mpFnDhZPGJv6UqiXZ/qOxHq9AOjycxEndQldcCtYVSfVg8Im3gasgcH0rZPUZNf/K bbMtI64WyTCJsxBkqIEb0KSd1daETsJ3wnzmhiJPL0394IdFbqsSPh2Vc6KtfwX2cn dtOQEgbiSr+jHMViTf+VNcY3ck0DlqlriSYEHWiuc+vzolno05OMokVfpmMhUVkqai ukFQBbRzYoRiQ== From: Thomas Gleixner To: =?utf-8?Q?Andr=C3=A9?= Almeida , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Arnd Bergmann , Sebastian Andrzej Siewior , Waiman Long , Ryan Houdek Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?Q?Andr=C3=A9?= Almeida Subject: Re: [PATCH v8 04/10] futex: Create set_robust_list2() syscall In-Reply-To: <20261115-tonyk-robust_futex-v8-4-a4fe47333a28@igalia.com> References: <20261115-tonyk-robust_futex-v8-0-a4fe47333a28@igalia.com> <20261115-tonyk-robust_futex-v8-4-a4fe47333a28@igalia.com> Date: Tue, 01 Dec 2026 02:27:24 +0100 Message-ID: <8733shrds3.ffs@fw13> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Nov 15 2026 at 14:31, Andr=C3=A9 Almeida wrote: > +enum robust_list2_cmd { > + FUTEX_ROBUST_LIST_CMD_CREATE_64, > + FUTEX_ROBUST_LIST_CMD_CREATE_32, This is a complete misnomer. It does not create a robust list. It installs a robust list pointer which is handed in from user space. > + FUTEX_ROBUST_LIST_CMD_MODIFY_64, > + FUTEX_ROBUST_LIST_CMD_MODIFY_32, > + FUTEX_ROBUST_LIST_CMD_LIST_LIMIT, > + FUTEX_ROBUST_LIST_CMD_USER_MAX, > +int futex_robust_list_create(uintptr_t head, enum robust_list2_cmd cmd) > +{ > + uintptr_t *rl =3D current->futex.robust_lists, entry =3D FUTEX_ROBUST_L= IST_ENTRY_INUSE; > + unsigned int index; > + > + if (!rl) { > + rl =3D kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL); > + if (!rl) > + return -ENOMEM; > + > + scoped_guard(mutex, ¤t->futex.exit_mutex) { > + /* check if another thread set the list before us */ How so? task::futex.robust_lists is strictly per thread and there is no way for another thread to set it. This whole mutex dance is pointless voodoo programming all over the place. > + if (current->futex.robust_lists) { > + kfree(rl); > + rl =3D current->futex.robust_lists; > + } else { > + current->futex.robust_lists =3D rl; > + } > + } > + } > + > + switch (cmd) { > + case FUTEX_ROBUST_LIST_CMD_CREATE_32: > + if (head) > + entry |=3D FUTEX_ROBUST_LIST_ENTRY_32BIT; > + fallthrough; > + case FUTEX_ROBUST_LIST_CMD_CREATE_64: > + /* Search for an empty slot */ > + for (index =3D FUTEX_ROBUST_LIST2_IDX; > + index < FUTEX_ROBUST_LIST2_MAX_IDX; index++) { > + if (rl[index] =3D=3D 0) > + goto exit; > + } > + return -ENOSPC; > + default: > + return -EINVAL; So if this is invoked with a NULL entry it will happily give out an unused index to user space. As a consequence: If this is a FUTEX_ROBUST_LIST_CMD_CREATE_32 command, then it will return a valid index, which means success for user space and then a subsequent MODIFY for that index will fail the bitness check. That does not make any sense at all. That aside, this switch case is overengineered and tasteless. There is zero reason to hand in @cmd. All what this function needs to know is whether this is a 32 bit or a 64bit list pointer. So you can make this: int robust_list_install(uintptr_t entry) { if (!(entry & FUTEX_ROBUST_LIST_ENTRY_MASK)) return; uintptr_t *rl =3D current->futex.robust_lists; if (!rl) { rl =3D kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL); if (!rl) return -ENOMEM; current->futex.robust_lists =3D rl; } /* Search for an empty slot */ for (unsigned int idx =3D FUTEX_ROBUST_LIST2_IDX; idx < FUTEX_ROBUST_LIST2= _MAX_IDX; idx++) { if (rl[idx]) continue; rl[idx] =3D head; return idx - FUTEX_ROBUST_LIST2_IDX; } return -ENOSPC; } And let the caller do: case FUTEX_ROBUST_LIST_CMD_INSTALL_32: entry |=3D FUTEX_ROBUST_LIST_ENTRY_32BIT; fallthrough; case FUTEX_ROBUST_LIST_CMD_INSTALL_64: .... ret =3D robust_list_install(entry); No? But see below ... > +int futex_robust_list_modify(uintptr_t head, enum robust_list2_cmd cmd, > + unsigned int index) > +{ > + uintptr_t *rl =3D current->futex.robust_lists, entry =3D head; > + > + if (index >=3D FUTEX_ROBUST_LIST2_MAX_IDX - FUTEX_ROBUST_LIST2_IDX) > + return -EINVAL; > + > + /* See comment about index mapping at sys_set_robust_list2() */ > + index +=3D FUTEX_ROBUST_LIST2_IDX; > + > + if (!rl || !rl[index]) > + return -ENOENT; > + > + switch (cmd) { > + case FUTEX_ROBUST_LIST_CMD_MODIFY_64: > + if (rl[index] & FUTEX_ROBUST_LIST_ENTRY_32BIT) > + return -EINVAL; > + if (futex_in_32bit_syscall()) > + return -EINVAL; A 32bit syscall cannot even reach this code ... > + break; > + case FUTEX_ROBUST_LIST_CMD_MODIFY_32: > + if (!(rl[index] & FUTEX_ROBUST_LIST_ENTRY_32BIT)) > + return -EINVAL; > + if (entry) > + entry |=3D FUTEX_ROBUST_LIST_ENTRY_32BIT; > + break; > + default: > + return -EINVAL; > + } > + > + scoped_guard(mutex, ¤t->futex.exit_mutex) > + rl[index] =3D entry; Again this whole thing can be simplified. int futex_robust_list_modify(uintptr_t entry, unsigned int idx) { uintptr_t tmp, *rl =3D current->futex.robust_lists; if (idx >=3D FUTEX_ROBUST_LIST2_MAX_USER_IDX) return -EINVAL; idx +=3D FUTEX_ROBUST_LIST2_IDX; if (!rl || !rl[idx]) return -ENOENT; // Validate that bitness matches if ((rl[idx] ^ entry) & FUTEX_ROBUST_LIST_ENTRY_32BIT) return -EINVAL; rl[idx] =3D entry & FUTEX_ROBUST_LIST_ENTRY_MASK ? : NULL; return 0; } But see below ... > +static void exit_robust_lists(struct task_struct *tsk) Unused function > +{ > + uintptr_t *rl =3D tsk->futex.robust_lists; What guarantees that rl is not NULL? > + tsk->futex.robust_lists =3D NULL; > + > + for (unsigned int idx =3D 0; idx < FUTEX_ROBUST_LIST2_MAX_IDX; idx++) { > + uintptr_t entry =3D rl[idx]; > + > + if (!(entry & FUTEX_ROBUST_LIST_ENTRY_MASK)) > + continue; > + > + /* > + * If the list type is the same as the kernel bitness, always > + * calls exit_robust_list(). exit_robust_list32() is only for > + * 32-bit lists in a 64-bit kernel. > + */ You really have a tendency to comment the obvious... > + if (IS_ENABLED(CONFIG_64BIT) && (entry & FUTEX_ROBUST_LIST_ENTRY_32BIT= )) { > + struct robust_list_head32 __user *head; > + > + entry &=3D FUTEX_ROBUST_LIST_ENTRY_MASK; > + > + head =3D (__force struct robust_list_head32 __user *)entry; > + exit_robust_list32(tsk, head); > + } else { > + struct robust_list_head __user *head; > + > + entry &=3D FUTEX_ROBUST_LIST_ENTRY_MASK; > + > + head =3D (__force struct robust_list_head __user *)entry; > + exit_robust_list(tsk, head); > + } > + } > + > + kfree(rl); > +} > + > static void futex_cleanup(struct task_struct *tsk) > { > if (unlikely(tsk->futex.robust_list)) { > - exit_robust_list(tsk); > + exit_robust_list(tsk, tsk->futex.robust_list); This want's to be a preparatory change and not something in the middle of introducing a new syscall... > tsk->futex.robust_list =3D NULL; > } >=20=20 > #ifdef CONFIG_64BIT > if (unlikely(tsk->futex.robust_list32)) { > - exit_robust_list32(tsk); > + exit_robust_list32(tsk, tsk->futex.robust_list32); Ditto. > tsk->futex.robust_list32 =3D NULL; > } > #endif > +SYSCALL_DEFINE4(set_robust_list2, struct robust_list_head * __user, head= , unsigned int, > + cmd, unsigned int, index, unsigned int, flags) > +{ > + uintptr_t entry =3D (__force uintptr_t)head; > + size_t align =3D sizeof(u32); > + int ret; > + > + if (flags) > + return -EINVAL; > + > + if (cmd >=3D FUTEX_ROBUST_LIST_CMD_USER_MAX) > + return -EINVAL; These two checks can be combined in one conditional. > + if (cmd =3D=3D FUTEX_ROBUST_LIST_CMD_CREATE_64 || > + cmd =3D=3D FUTEX_ROBUST_LIST_CMD_MODIFY_64) { No line break required. > + if (futex_in_32bit_syscall()) > + return -EOPNOTSUPP; > + align =3D sizeof(u64); > + } > + > + switch (cmd) { > + case FUTEX_ROBUST_LIST_CMD_CREATE_64: > + case FUTEX_ROBUST_LIST_CMD_CREATE_32: > + if (index) > + return -EINVAL; This check is pretty pointless because 0 is also a valid index, no? > + if (entry % align) > + return -EINVAL; This should also validate that the head pointer is a valid user space address. If not, return -EFAULT. > + /* > + * The first two indexes are reserved for the kernel to be used > + * with the legacy syscall, so we hide them from userspace. > + * > + * We map [0, FUTEX_ROBUST_LISTS_PER_USER) to > + * [FUTEX_ROBUST_LIST2_IDX, FUTEX_ROBUST_LIST2_MAX_IDX) > + */ This comment is not really helpful here. > + ret =3D futex_robust_list_create(entry, cmd); > + > + if (ret >=3D 0) > + ret -=3D FUTEX_ROBUST_LIST2_IDX; See above. > + return ret; > + > + case FUTEX_ROBUST_LIST_CMD_MODIFY_64: > + case FUTEX_ROBUST_LIST_CMD_MODIFY_32: > + if (entry % align) > + return -EINVAL; See above. > + return futex_robust_list_modify(entry, cmd, index); > + case FUTEX_ROBUST_LIST_CMD_LIST_LIMIT: > + return FUTEX_ROBUST_LISTS_PER_USER; This does not make sense at all because that's a compile time constant so it should be read from a sysctl and not be multiplexed into this syscall just because, no? > + } > + > + return -EINVAL; > +} This whole thing can be simplified so it becomes comprehensible. SYSCALL_DEFINE4(set_robust_list2, struct robust_list_head * __user, head, u= nsigned int, cmd, unsigned int, index, unsigned int, flags) { if (flags || cmd >=3D FUTEX_ROBUST_LIST_CMD_USER_MAX) return -EINVAL; size_t align =3D sizeof(u32); switch (cmd) { case FUTEX_ROBUST_LIST_CMD_INSTALL_64: case FUTEX_ROBUST_LIST_CMD_MODIFY_64: if (futex_in_32bit_syscall()) return -EOPNOTSUPP; align =3D sizeof(u64); } if (unlikely(!access_ok(uaddr, align))) return -EFAULT; uintptr_t entry =3D (__force uintptr_t)head; if (entry % align) return -EINVAL; switch (cmd) { case FUTEX_ROBUST_LIST_CMD_INSTALL_32: entry |=3D FUTEX_ROBUST_LIST_ENTRY_32BIT; fallthrough; case FUTEX_ROBUST_LIST_CMD_INSTALL_64: return futex_robust_list_create(entry); case FUTEX_ROBUST_LIST_CMD_MODIFY_32: entry |=3D FUTEX_ROBUST_LIST_ENTRY_32BIT; fallthrough; case FUTEX_ROBUST_LIST_CMD_MODIFY_64: return futex_robust_list_modify(entry, index); } return -EINVAL; } No? But I really have to ask how the distinction between INSTALL and MODIFY is actually valuable. This whole thing can be made _ONE_ operation, which removes boatloads of pointless code and solves the install NULL and then modify issue I pointed out above: static int __robust_list_install(uintptr_t *rl, , unsigned int idx, uintptr= _t entry) { rl[idx] =3D entry & FUTEX_ROBUST_LIST_ENTRY_MASK ? : NULL; return idx - FUTEX_ROBUST_LIST2_IDX; } int robust_list_install(uintptr_t entry, unsigned int idx) { uintptr_t *rl =3D robust_get_lists(); if (!rl) return -ENOMEM; // Update an distinct entry? if (idx !=3D FUTEX_ROBUST_LIST2_NEW_ENTRY) { if (idx >=3D FUTEX_ROBUST_LIST2_MAX_USER_IDX) return -EINVAL; return __robust_list_install(rl, idx, entry); } =20=20=20=20=20=20=20=20=09 /* Search for an empty slot */ for (idx =3D FUTEX_ROBUST_LIST2_IDX; idx < FUTEX_ROBUST_LIST2_MAX_IDX; idx= ++) { if (!rl[idx]) return __robust_list_install(rl, idx, entry); } return -ENOSPC; } Note that this does not care whether there is a bitness mismatch in case of updating a particular index. Why? The kernel is not responsible for user space to get its act together and there is zero impact for the kernel if user space screws that up. No? That said, the whole ordering approach of this patch set is backwards and unreviewable. What you want to do is: 1) Preperatory patches Patch 02/03 plus patches which change the exit_robust_list() signature and add missing sanity checks to the existing syscalls. 2) Introduce robust_get_lists() which either returns the existing robust lists pointer or allocates the robust list array uintptr_t *robust_get_lists(void) { uintptr_t *rl =3D current->futex.robust_lists; =20=20=20 if (!rl) { rl =3D kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL); current->futex.robust_lists =3D rl; } return rl; } 3) Provide the exit() walker for this new thing and invoke it which will be a NOOP because the list is empty. 4) Use #2/#3 for the existing syscalls and remove the then unused leftovers SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head, = size_t, len) { uintptr_t *rl =3D robust_get_lists(); if (!rl) return -ENOMEM; rl[FUTEX_ROBUST_LIST_NATIVE_IDX] =3D head; return 0; } ... 5/6) Add the new syscalls 7/8) Wire up the syscalls Thanks, tglx