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=1796047250; b=SBwC5n4no9DvvvixVkooptrrxeV+iFZ+xfD299Qweym9nZLo6PlaUrEe9T1edEVWSIO3 ZGigzKp6ZuYOGpuqQcqD20du1o92TFQmkcdn4N/AXgagAyCmO+Le/4ddJ1qxUggS7BWlG 6f3PYnHvLSREAg6zRIUl81F3RNhBOdZvHt+DfTxgB9vL6h6yf+hD6kY4dDFHCTeZvmpxI acVwbYk5TCeEy1bThNQpBwRGeOKzw4pakL26mIyhKNlcBNL4wJlMEOxpszY3AuaPXzpnv 6c+ef3s68H4kb+u0TXMY+cSMEgTb2UI9FF9OPv0J10hJlzED3zLVJ8UqpqLisKWmXWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047250; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=R/IxkthJyOGGdwEjhXzCsm4mv+U8JS5rewavlGkrG3Q=; b=lLAbOStdvQqy5qwtGGYqBuQV9eVViVIhU4Ck/85tpDJTMzaFYLmv/vluUH6yqFXOqiVP BuPO1kL/F6Ikbf7WfAp5rbNcSdbt/QnmHDo7INsOcj98idljuVDXDtEc/E3kvZ4lgtOGk uy38w/a5Q78Wng1KvB/5w6uzGGwhs5rIQECEQbhrL8mcFxiMHKM7cq3MSChSz3FW7pDOF z0xLhTh6HcjU6kHU1OIwq6qu0LcPyBlr0AHuEozwxqlpkfyxHqla8RDjumYnRNPYtXkFI ZtLEEUFYU4TSuORS+ThsgONzLl8X268V/91KqMMDslBQclxFxpRQkb8zWmRFXHKA7nw== 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=lNKxC8tf; 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 11789606A31C for ; Mon, 30 Nov 2026 14:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lNKxC8tf Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA6561F00925; Mon, 30 Nov 2026 14:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796047249; bh=R/IxkthJyOGGdwEjhXzCsm4mv+U8JS5rewavlGkrG3Q=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=lNKxC8tfapkSo6g0uNGnwLjpqlFaD+1+hipHgULDfvZSycIEg55EemC6XZTIhANvF QTdrISoVhoESqLphjXJyaMIuOBT7UGnExnxEvU1X+Dl8Kp4MS2bfh2anKcnIfZdSkw 3KzzKV6c9//YIqSrcGjl/f8rMVqoNxXBmR83R7kYUFA9UDbVBCpzMQg9X1SR70fn5t xAJzEwu5NVB/471fUjOrp3BL2U+KCKj3B4zYlj6bw20fNS5a32fEpjjCykQoyDprtU mfe1JOrih/C0Hi4neu0ZepWlOKMJftuWJwpq+sEspuX16zw0DnybyN46TN37ExUWo1 VjGiCknv+DQcg== From: Thomas Gleixner To: Daniel Wade , Ingo Molnar , Peter Zijlstra , Darren Hart Cc: Davidlohr Bueso , Andre Almeida , Sebastian Andrzej Siewior , Kyle Zeng , linux-kernel@vger.kernel.org Subject: Re: [PATCH] futex/pi: Reject owners that have no mm In-Reply-To: <20261116132622.34793-1-danjwade95@gmail.com> References: <20261116132622.34793-1-danjwade95@gmail.com> Date: Mon, 30 Nov 2026 15:00:46 +0100 Message-ID: <87h5gyqv01.ffs@fw13> X-Mailing-List: linux-kernel@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 On Mon, Nov 16 2026 at 23:56, Daniel Wade wrote: > attach_to_pi_owner() attaches PI state to the task named in the futex word > and rejects kernel threads, which cannot own a user space futex. > > A usermode helper thread runs with PF_KTHREAD cleared and acquires an mm at > exec(). While it is in that state, any task that can see its TID can name > it as the owner of a shared PI futex. > The helper then execs or exits, exit_pi_state_list() takes a reference on > the private hash of current->mm, and futex_private_hash() dereferences a > NULL mm. Indeed. > The oops path calls do_exit(), which runs the futex cleanup again > and blocks on the futex exit_mutex, so the thread stays there and with > preemptible RCU grace periods stop completing. That's not really relevant because that's just a subsequent failure. > Module auto-loading starts usermode helpers on behalf of ordinary > users, so an unprivileged task reaches this. > diff --git a/kernel/futex/pi.c b/kernel/futex/pi.c > index 98f1b962e59a..77e88dd5dc22 100644 > --- a/kernel/futex/pi.c > +++ b/kernel/futex/pi.c > @@ -515,6 +515,18 @@ static int attach_to_pi_owner(u32 __user *uaddr, u32 uval, union futex_key *key, > return ret; > } > > + /* > + * A usermode helper thread runs with PF_KTHREAD cleared and acquires > + * an mm at exec(), so the kernel thread test above lets it through. > + * Its exec() or exit() cleanup runs exit_pi_state_list(), which uses > + * current->mm. That comment is confusing at best. > + */ > + if (unlikely(!p->mm)) { > + raw_spin_unlock_irq(&p->pi_lock); > + put_task_struct(p); > + return -EPERM; > + } Why putting this into the pi_lock held region? p->pi_lock protects nothing here and the access to p->mm is racy in any case and will trigger KCSAN splats. So the below is sufficient. Thanks, tglx --- --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -473,7 +473,13 @@ static int attach_to_pi_owner(u32 __user if (!p) return handle_exit_race(uaddr, uval); - if (unlikely(p->flags & PF_KTHREAD)) { + /* + * Don't attach to kernel threads or user mode helpers without mm. The + * access to p->mm is racy as the mm could be swapped right at this + * moment, but the only relevant information at this point is whether + * it's NULL or not. + */ + if (unlikely(p->flags & PF_KTHREAD || !data_race(p->mm))) { put_task_struct(p); return -EPERM; }