From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E57B938550C for ; Tue, 2 Jun 2026 09:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780391421; cv=none; b=d++FoXuNflAoEdGBl3p1l2soKBhgsAG0OX3oAtmaoq2ffB84IdxWqsOsK34ZzwLzk4ocgtAGUiYy4gRWa10CRSucH989lfP+Ah4rNOxROsCkm/MT+RJPyIv9T/OBF2v8NhjX09H2PIDieLGUTesn0FbHM5COKB0yyrglMJbRn64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780391421; c=relaxed/simple; bh=x65A7Sgq9st06xADyskLzSfYbSl4LlgWl5xcnprbNYI=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=E08UuuWmBuoxsw/L11r7ypf/NUUhKeYYgfygxDHpTncdp/Pf2koxl8aqk02ZLkw1Iw/FtemjqQ3f6joj+OyUeCE6GiHjs/sZL/+yc/xzf/S8wAJPLFbEU8RSOJdY9xF88ObrqCbsl8NPWptAD6jKnIHgBvQWnPBrMHUhIPYcKps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fXw0wwXr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fXw0wwXr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C0971F00898; Tue, 2 Jun 2026 09:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780391419; bh=zzII8FLiWJ8gpExZKBjRjgwEoHvENoTT+3jkRaQYsPc=; h=Date:From:To:Cc:Subject:References; b=fXw0wwXr3F73m/Dc1FrNrtFSlhKvSpzL8edO+2T5Vte9ceRApUhd62SQ6NnvpKQiT xE0lDIrYwycXEdiqBbmsKKYjdWYTjZaYpa3++0DFWbVyh9f0oZ1GJfe+Mrj+PE4NTt 0jOWyJ3H1xX1na1DMK8OTtRGLhg8N5pNqIJ7HtAzJmxq1jBYwnWPA1IFVT2rimz7v1 exWkxs6CUwvcL+1h2CrUJyJVAjY9s1O67d1wqGuVrgph9Ztwtg3T4Eh+mdYXTdY0Ao Zn7V7HCx5ucUYFHCTTVN4sVQU7SOx5wJ8/EW8e9DPGMTZlpiIWeV9N7KySiIWdU2+e NI5d8nHQARvIw== Date: Tue, 02 Jun 2026 11:10:16 +0200 Message-ID: <20260602090535.936286833@kernel.org> User-Agent: quilt/0.69 From: Thomas Gleixner To: LKML Cc: Mathieu Desnoyers , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Sebastian Andrzej Siewior , Carlos O'Donell , Peter Zijlstra , Florian Weimer , Rich Felker , Torvald Riegel , Darren Hart , Ingo Molnar , Davidlohr Bueso , Arnd Bergmann , "Liam R . Howlett" , Uros Bizjak , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Mark Brown , Richard Weinberger Subject: [patch V5 14/16] Documentation: futex: Add a note about robust list race condition References: <20260602084648.462672743@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: André Almeida 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é Almeida Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260329-tonyk-vdso_test-v2-1-b7db810e44a1@igalia.com --- Documentation/locking/robust-futex-ABI.rst | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) --- a/Documentation/locking/robust-futex-ABI.rst +++ b/Documentation/locking/robust-futex-ABI.rst @@ -153,6 +153,9 @@ manipulating this list), the user code m 3) release the futex lock, and 4) clear the 'lock_op_pending' word. +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 @@ The kernel exit code will silently stop 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 clearing + the pending op pointer. If the task is forced to exit in this window, exit + 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 operation. +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 futex 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 means +that there are waiters for this lock and a call to ``futex()`` syscall with +``FUTEX_ROBUST_UNLOCK`` is needed.