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=1796387975; b=a9FDJvum5z5gPEcEEozlApZQGvpQgw3ZlCElGnKGy8/CcrB2Iy7un9XcOKSTLQlM+J3j 6zf3AISjsQ1x1ohwqxHY+cEAC7u72RqVn3JT6gPmM+re9PJuzQL77utl9JF5rbbOKtgEP X5rVb/KA37/PVGUa3NiOq08Pjt/OepIqD4XPOLjro6seKZl5s5e1fFzjQa3nyZCvAxjfy uk05tQF5HexQh/C/DJ0axwewYPREltsNbQdrqpuKSkjCoRCsbZ0jyYmTPQ6h78HptrzoY iaHCCT7rX34fk1t4EuQNKZkrW0y8yN0x8EuwpQ/je0JUGSgSP6CbWqDBAaiQ1Hj89Ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387975; 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=KAWs5fyFUNbOqXWdn4OH2TukoigiQBedHaWzX3CPubg=; b=VVr+i83ZCsLPK+lpFSMPtK2boPZpgND6KfUjA4M6h3YacIqYSuyE2ur2X1G3DRkaxZLd y7lvUVM2bXvXyJEvQifH2kcQXoShTDomZvqlvDQ08GjW02HPJZXDk6boUANULHT6XLHqB UvoTsr6EKx43XPcnt6lKvMOo6M2cayAZ532Yscbo4koqn7c8Gxq4NyOmw9I5mSeM7dfbE HLI5M5BCldu41+c0uqMocYX+fF3IfXcgcUQqADBf7YWWaILF8z9eOpWttSmMqihUWyhhO +KS9h26bwfIAyFyyqpEBlVy13D95IPD3eE51XIcheqG3jMnElkPrL0ILqcHMZpqeLuw== 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="x+zRMH/H"; 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 49BAB606A322; Fri, 4 Dec 2026 12:39:35 +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=x+zRMH/H Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EA361F000C2; Fri, 4 Dec 2026 12:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387975; bh=KAWs5fyFUNbOqXWdn4OH2TukoigiQBedHaWzX3CPubg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=x+zRMH/H6P/u7T6gjQSJ3pemmETAwFIHwH8gy9NHL46qFCetFsaXUhDx70bKHC+7V jrC+OYgIBKFMHhMyFFk2QyBrb+JbTQXe/LwWXZd3i1fkuIrTHJWrYZ+ZrrhLo7w0y3 V5ZL2/bhl84n3QKZVndVLIVAnbsPu9H5RT18xTp4= 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.1 0408/1059] bpf: Claim the per-CPU send_signal irq_work before filling it Date: Fri, 4 Dec 2026 18:58:59 +0900 Message-ID: <20261204100654.905952426@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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: Replaced task with current in the cmpxchg claim and get_task_struct() because this tree's bpf_send_signal_common() has no task parameter, and dropped the siginfo lines. ] 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 db5484a1dbd31..aecce50519d56 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -825,6 +825,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; @@ -839,6 +840,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) @@ -866,14 +869,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