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=1796387733; b=q4MqISAjawBE+XZ6vDFZHPvv1qf/lO1QQcr4zhMkFcqEqUweAClOzevbdGahLHXwNTbb z9qutcctgp1/N4jDx8zIuOhRCgc92xbCgBdpw6+THKakcx4APkwf1k1WvaYQ0m6e+TYMZ YfP4/Jmp2WK9Ek2Z2FhRcNplhZGsi1HbFqfj6DEXlTXfuYmz6hKDyfYvMO6XdQrkCvI2i BCgA61l0yFl/UfRHMpmOPxQ5OeVMxlxSnTeCl2GDakxM5tIsAxC6BPmzOWTSewrpkGCXS gDcX7OUsbYNBORn6M0MCTS8X0h1Am7Ct3No3BEd81dKY7ETtlre12nCEJkoU0roUuzQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387733; 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=XV28mxe4x+YXPKCcV2Qpt9eCKoqgsbq6xB1Qj4embSc=; b=ex+gJhOb4dfc1WQtFvB9crQ+dleZs0POdPLl9rAQBxxm2xeOEBeLFJL3zwUX2OAFFWey gdvbW5Kj1EXAPM3ILdRNHkByzelS2PoTeScWajCmQ4y2t8i/WHjxnd6Ahfw43oh7zgEZt o2EqDBx4BfqL+lOUrodk+sp9jYqVkOijeouMkQtR1nyOZdCODCG/RIezUrbVA5geLSPli FTicA2B0hGT5R+bZGsXXtA6TorQS9nmOr9vO3XtOyaNcRePj/dyPYh2OQPl8oqW0EHmpx xb+jzsmmd8/+d3ll4rnDBLA9hmxlbhbSGqeAKFAjkruCYdHPdD+9SCfRrZBvpFQpNfw== 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="k/ehvwBQ"; 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 7EFDD606A322; Fri, 4 Dec 2026 12:35:33 +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=k/ehvwBQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADEF61F00897; Fri, 4 Dec 2026 12:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387733; bh=XV28mxe4x+YXPKCcV2Qpt9eCKoqgsbq6xB1Qj4embSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k/ehvwBQSmUA4JvlyV5VLkGaCYYycAV4ZNmGpJ+3MuxnaYSVDfLjQ1fWL9FEMQWRQ rFLnuG2nsjWLTyNrBszGx0VuLzAws+ntZcci8rJ2qJAdaKqaIPycmMaihDBFHIMyBn Azg063BMhHems4WG6xAlFfjt2o63sdda0GqDv4VQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Leon Hwang , Yuan Chen , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0326/1059] bpf: Roll back freplace link state when bpf_arch_text_poke() fails Date: Fri, 4 Dec 2026 18:57:37 +0900 Message-ID: <20261204100652.713657091@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: 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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuan Chen [ Upstream commit 5ec398d9ec8fe13f8058af9a2e5f5e8f46e0a35a ] A freplace attach claims the target prog by bumping tgt_prog->aux->freplace_link_cnt and setting tr->extension_prog. bpf_arch_text_poke() then makes the extension take effect. If the poke fails, the claims are never released: the attach unwinds through bpf_link_cleanup(), which clears link->prog, so bpf_trampoline_unlink_prog() never runs. Drop the link count under ext_mutex on the error path, and set tr->extension_prog only after the poke succeeded. The count is still bumped before the poke: it blocks prog_array updates while the entry is patched. Fixes: d6083f040d5d ("bpf: Prevent tailcall infinite loop caused by freplace") Fixes: be8704ff07d2 ("bpf: Introduce dynamic program extensions") Suggested-by: Leon Hwang Signed-off-by: Yuan Chen Signed-off-by: Alexei Starovoitov Acked-by: Leon Hwang Link: https://patch.msgid.link/20260928091121.219333-1-chenyuan_fl@163.com [ sashal: Adapted the freplace fix to use struct bpf_tramp_link (link->link.prog) and the older bpf_arch_text_poke() signature without the old-text-type argument. ] Signed-off-by: Sasha Levin --- kernel/bpf/trampoline.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 75f4173a0c24a..b509357019e70 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -590,9 +590,16 @@ static int __bpf_trampoline_link_prog(struct bpf_tramp_link *link, err = bpf_freplace_link_tgt_prog(tgt_prog); if (err) return err; + err = bpf_arch_text_poke(tr->func.addr, BPF_MOD_JUMP, NULL, + link->link.prog->bpf_func); + if (err) { + /* Undo the claim from bpf_freplace_link_tgt_prog(). */ + guard(mutex)(&tgt_prog->aux->ext_mutex); + tgt_prog->aux->freplace_link_cnt--; + return err; + } tr->extension_prog = link->link.prog; - return bpf_arch_text_poke(tr->func.addr, BPF_MOD_JUMP, NULL, - link->link.prog->bpf_func); + return 0; } if (cnt >= BPF_MAX_TRAMP_LINKS) return -E2BIG; -- 2.53.0