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=1796384955; b=BOTpeBsCAzpqx0Mr2YcF4Z6BNMYcrzlpY8eaGBrdQTOf+V80lTrSOqzG9k9G70IxVJyI mfjRTNQlhO7msO700vAds0oUEuliu9VutmivHm5VLuw1A2bfZFl1qAQhTp1n+vm6OLsAw 5lonYQ+4MGW0QNISzQONN/9iJYtpXcmgNSsPmJ75KIHYNyE+6LjtgUPBgFksVKf6lxBqw PiypcNjTNBE4QkPTRrhJk3fkBVvbIxZ6+vHCEGiZ4cgH5q56uxMb2p0ZEsPclQlJdF5Dy 39BrOtVic4X4xaHdS4EqmDS6w6VoP4w5frFUhmMhUvBRS536vbnbptGLnrQAUVu5BfA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384955; 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=uPlU3qYSKQYNMgVnMSHSCdEThSHouLA4lErOtc2KLMo=; b=p5VgSa+kvCmZf9GaDVcHwFtEoH38Ot/KoGCwEcvYrzJBH/kL7aKR9fz6alMFrf2/amFj DxWAoGUYjElOD9IRvqx1VOw+u70tDlIdL6Q/blUag78QIjxk6F0u8RECXwY2OBPRhCgBR gtWBzDZhSogdupdR98UiQGzGDhGzRSiytHecdbPuiBm6fZNXiREK3br7GetjsAMGnzRNJ b5vMp51sl6IIDrTTbEqJu+e9f6SwDvC8BD7Pjzp2TZyGnU8q3DoYwGG7+JeMpjOlLCpAe xpl43xKlo+Xjet9AByWRMyErMcVC4kLoEdSQokdqYFLZ+KeA8CDc2NNH6pj+2CG9LpQ== 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=a+kYHmBD; 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 BE1C6606A322; Fri, 4 Dec 2026 11:49:15 +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=a+kYHmBD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BE421F0092C; Fri, 4 Dec 2026 11:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384955; bh=uPlU3qYSKQYNMgVnMSHSCdEThSHouLA4lErOtc2KLMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a+kYHmBDB/1/1P4bUaJ1b6Oih/FoFTRB/7URX8DKQLGgegQtzdDoDFyQv022KqGYj J88c5siURcytu6lNXmMZa8u2jvGlTTkX3lQ/n0JEKaFVpjxVcd1wM6obLTBWqkYfO4 vrixTRNzPpSN838Ng/fPcBRBcN+kT2ivw4PjgRdE= 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.6 0361/1167] bpf: Roll back freplace link state when bpf_arch_text_poke() fails Date: Fri, 4 Dec 2026 18:56:28 +0900 Message-ID: <20261204100711.385123680@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 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 to older API: link->link.prog and four-argument bpf_arch_text_poke() without BPF_MOD_NOP, with the surrounding context kept as is. ] 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 7747708f13a63..64972e44af6dc 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -559,9 +559,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