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=1796385117; b=Xa3KfLEYVyATXKLFT27Yr3LjcWyIh2AbrWcg8L5N9iDUBZXVYZ09GRZNUfgkx1yhEXWE y74tyzd3Dh9U8dMxq84HraAhjqdeb4IfXfwNpjyrNX+EkIsQ7z81jqXqybIxgtBBmW3Af hHZYJLD4+bJdglrR6mvmckClz4V4HHi8J9gJzlezLYn6Y/35snZTBHZZ2IJnwtKayiW5U uPooObk7TQ+tgPlUBflb3B0Lq074kyr+6S9O7zPr+la/nYMkXl4K2BPuR6gpyb3RPJSwJ Wrt1eBzTUaB+HwvSi2dkOe2Bz2ikppVBubwi9Z+GnhBIFxOrRbEnCvRqidpc0+fs+Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385117; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=fDdX8uwCgmZqSNq+KxUtnoyLozNRAZBljODHwloL6c8=; b=cO1AXQ8qN/iBWaIP2lbvAnaWLIcYPPht+GAVM2S5k+VX0pRDgWlZbJW4qM8XjBQQlBW6 8pEyHfdHFYbIwhD+moPYpZzkVu8pC/D3E4oSEdpvlWEapvwoMQPK9PQCnWzwwQ90ZhBnP L5mi60uo5lARkpL8YzEuMtvYtvcacOco5UmiOm3ScZWMv2mmQ9dKYWdOOXJXIHNtZUkP/ xZrbPDwIMj1t/FmkIx3T9YKjRzy0jEiDypYS19QPvfX+WW476Ll6H5nET9/MARaPXM9Bf 4zDUlTvQ5TL5GsUdKu2WtUcbtd1PdE6kkutKLFwXSNKQqmSUoUg0H4oCJiiAIGhNvew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0SOLkkGH; 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 84E98606A322; Fri, 4 Dec 2026 11:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0SOLkkGH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 010D91F00937; Fri, 4 Dec 2026 11:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385117; bh=fDdX8uwCgmZqSNq+KxUtnoyLozNRAZBljODHwloL6c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0SOLkkGHa3rqpJbLLXHNPZpNLoZv+xCZlSWS3FpwiU0HO/w7ahAy6n2etoC6WbVY/ jIk1UVz4KypxMLGNp15LMPRZSU6CLU4IFz5cOq0wZsNCL8UzbS8QFZQfAsdoYG3Qsz Dk7XafzeTfnC2/wariBOzoMgjGDOvEl3pY1Jqb7o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuan Chen , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0426/1167] bpf: Claim the per-CPU send_signal irq_work before filling it Date: Fri, 4 Dec 2026 18:57:33 +0900 Message-ID: <20261204100713.114941682@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuan Chen [ Upstream commit 2d1f101ee619435873ed8a23fcb3bd09204a5024 ] irq_work_is_busy() cannot see the per-CPU send_signal_work while it is being filled: the check only matches after irq_work_queue() has claimed the work. A concurrent caller therefore passes it, both callers race for the same irq_work, and the loser's signal is silently lost along with its task reference while the queued work runs with a mix of both callers' fields. kprobe, tracepoint and perf_event programs exclude each other on the same CPU through bpf_prog_active, so for two callers to meet, one of the programs has to be a raw tracepoint or an fentry one. And since commit 87c544108b61 ("bpf: Send signals asynchronously if !preemptible") this path runs with IRQs enabled too, so a hard IRQ can interrupt the fill as well, not only an NMI. Found by code inspection and reproduced with a perf_event NMI program racing an fentry one. Claim the work through work->task itself: cmpxchg() it from NULL to the target task before touching the other fields, and set it back to NULL once the callback has consumed them. A context finding the work claimed returns the documented -EBUSY. Fixes: 1bc7896e9ef4 ("bpf: Fix deadlock with rq_lock in bpf_send_signal()") Signed-off-by: Yuan Chen Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261009022427.968304-1-chenyuan@kylinos.cn [ sashal: Backport uses cmpxchg(&work->task, NULL, current) and a plain get_task_struct(current) because the older bpf_send_signal_common() has no task argument and no siginfo handling. ] Signed-off-by: Sasha Levin --- kernel/trace/bpf_trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 4b13ab0daa5f9..64898a0672006 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -821,6 +821,7 @@ static const struct bpf_func_proto bpf_current_task_under_cgroup_proto = { struct send_signal_irq_work { struct irq_work irq_work; + /* The claim: NULL marks the slot free for the next caller. */ struct task_struct *task; u32 sig; enum pid_type type; @@ -835,6 +836,8 @@ static void do_bpf_send_signal(struct irq_work *entry) work = container_of(entry, struct send_signal_irq_work, irq_work); group_send_sig_info(work->sig, SEND_SIG_PRIV, work->task, work->type); put_task_struct(work->task); + /* Release once the fields are consumed. */ + smp_store_release(&work->task, NULL); } static int bpf_send_signal_common(u32 sig, enum pid_type type) @@ -862,14 +865,14 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type) return -EINVAL; work = this_cpu_ptr(&send_signal_work); - if (irq_work_is_busy(&work->irq_work)) + if (cmpxchg(&work->task, NULL, current)) return -EBUSY; /* Add the current task, which is the target of sending signal, * to the irq_work. The current task may change when queued * irq works get executed. */ - work->task = get_task_struct(current); + get_task_struct(current); work->sig = sig; work->type = type; irq_work_queue(&work->irq_work); -- 2.53.0