From nobody Mon Jun 8 08:29:03 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B99A43DA2D; Wed, 3 Jun 2026 14:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496693; cv=none; b=qXVAe+AfEjGbfpOnzE7s9KawOJseXYhtfD4bkLZ3Undnx6idgh8j/EleZ3rqJUCYOD7HiQzVSvSw1N4MN7GZ3fkwfWPxUsTS8VG7/3g0ZdXAP5ssLsfqShHwRD4JY0/sp32XlXzce/KDWlQn9ChC7NVdIRa28HkJ+OYRyMp/wCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496693; c=relaxed/simple; bh=tvkzkrp+Z+hU1MbhTqrsRM9gIQ1T62Evx3dCq9xX1ac=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=nET1/InMEJJhv3ReEffA1v47O+S7RL5H/gc+yZ+D1WN+w1Mg2mzPvNayjPQovWEIBsXF5lbJAtXDQKJM1hDh49oC/9sGL0Ge3FR+ouZeE9JFj8s81Hwb72fz8HwAv8yZ/3cNeEv/JcZIJ2pyS71yb426+si1PDjm35ZpET34Gpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oGd8/Pq4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b+NMG5kF; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oGd8/Pq4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b+NMG5kF" Date: Wed, 03 Jun 2026 14:24:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780496691; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1IXUK2YVa8jFUeUoYxBY36v2hV8/rxyZgv+2/MuZ7Po=; b=oGd8/Pq4+JsRoZQCN2B4fSNr5jsEcTJf2dWvXlJrZp/U/PEqpWuve+Kbug1c7Iwb1jnJBE zKOwaHksQyszrplLw4Mr97LordUW8s1QOlA8Em3VB4R6v2n3xZ4o2stQF2zWpPcb4fsdJC /b7Ip88q9LspTgQCurwuxL7ySBLqDlx0USLTsCyPLJZ7/iahd5Q/5nYR/RBMEQs6K0JfQa xyUFJsiTuf9GniZyDU+fKhK0s5cFNwsZ0utUgnkHg+c+jp5Ia1ulPCzE+p1TLc5SQGV3A1 hsn3VerBJNwfP9qpX0ti+y337c51UBIJFZhgGBkd9NAQ4fQc9g5MprDVygYfXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780496691; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1IXUK2YVa8jFUeUoYxBY36v2hV8/rxyZgv+2/MuZ7Po=; b=b+NMG5kFYDlOeTVySppBdFP/dYc0hhcphtIQCWJdZvRu77h28yQmVxd6mQN/5DwoV+L1lN pJFdQQkvybJJniDg== From: tip-bot2 for =?utf-8?q?Andr=C3=A9?= Almeida Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] Documentation: futex: Add a note about robust list race condition Cc: andrealmeid@igalia.com, Thomas Gleixner , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260602090535.936286833@kernel.org> References: <20260602090535.936286833@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178049668965.710.2405769454867094009.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: 3f63e2545978abda58f2cf7ff0d7a2942965e8cb Gitweb: https://git.kernel.org/tip/3f63e2545978abda58f2cf7ff0d7a2942= 965e8cb Author: Andr=C3=A9 Almeida AuthorDate: Tue, 02 Jun 2026 11:10:16 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 03 Jun 2026 11:38:52 +02:00 Documentation: futex: Add a note about robust list race condition Add a note to the documentation giving a brief explanation why doing a robust futex release in userspace is racy, what should be done to avoid it and provide links to read more. [ tglx: Fixed a few typos ] Signed-off-by: Andr=C3=A9 Almeida Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260329-tonyk-vdso_test-v2-1-b7db810e44a1@i= galia.com Link: https://patch.msgid.link/20260602090535.936286833@kernel.org --- Documentation/locking/robust-futex-ABI.rst | 44 +++++++++++++++++++++- 1 file changed, 44 insertions(+) diff --git a/Documentation/locking/robust-futex-ABI.rst b/Documentation/loc= king/robust-futex-ABI.rst index f24904f..5e6a066 100644 --- a/Documentation/locking/robust-futex-ABI.rst +++ b/Documentation/locking/robust-futex-ABI.rst @@ -153,6 +153,9 @@ On removal: 3) release the futex lock, and 4) clear the 'lock_op_pending' word. =20 +Please note that the removal of a robust futex purely in userspace is +racy. Refer to the next chapter to learn more and how to avoid this. + On exit, the kernel will consider the address stored in 'list_op_pending' and the address of each 'lock word' found by walking the list starting at 'head'. For each such address, if the bottom 30 @@ -182,3 +185,44 @@ any point: When the kernel sees a list entry whose 'lock word' doesn't have the current threads TID in the lower 30 bits, it does nothing with that entry, and goes on to the next entry. + +Robust release is racy +---------------------- + +The removal of a robust futex from the list is racy when doing it solely in +userspace. Quoting Thomas Gleixner for the explanation: + + The robust futex unlock mechanism is racy in respect to the clearing of = the + robust_list_head::list_op_pending pointer because unlock and clearing the + pointer are not atomic. The race window is between the unlock and cleari= ng + the pending op pointer. If the task is forced to exit in this window, ex= it + will access a potentially invalid pending op pointer when cleaning up the + robust list. That happens if another task manages to unmap the object + containing the lock before the cleanup, which results in an UAF. In the + worst case this UAF can lead to memory corruption when unrelated content + has been mapped to the same address by the time the access happens. + +A full in-depth analysis can be read at +https://lore.kernel.org/lkml/20260316162316.356674433@kernel.org/ + +To overcome that, the kernel needs to participate in the lock release oper= ation. +This ensures that the release happens "atomically" with regard to releasing +the lock and removing the address from ``list_op_pending``. If the release= is +interrupted by a signal, the kernel will also verify if it interrupted the +release operation. + +For the contended unlock case, where other threads are waiting for the lock +release, there's the ``FUTEX_ROBUST_UNLOCK`` operation feature flag for the +``futex()`` system call, which must be used with one of the following +operations: ``FUTEX_WAKE``, ``FUTEX_WAKE_BITSET`` or ``FUTEX_UNLOCK_PI``. +The kernel will release the lock (set the futex word to zero), clean the +``list_op_pending`` field. Then, it will proceed with the normal wake path. + +For the non-contended path, there's still a race between checking the fute= x word +and clearing the ``list_op_pending`` field. To solve this without the need= of a +complete system call, userspace should call the virtual syscall +``__vdso_futex_robust_listXX_try_unlock()`` (where XX is either 32 or 64, +depending on the size of the pointer). If the vDSO call succeeds, it means= that +it released the lock and cleared ``list_op_pending``. If it fails, that me= ans +that there are waiters for this lock and a call to ``futex()`` syscall with +``FUTEX_ROBUST_UNLOCK`` is needed.