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=1796380490; b=xk2+PA/+fhsiYc/TlZZ30ZGhC/Pcbo9ZwPAfxM2Fi6ooaEpPLBm0YfOfeRvS36gbY5s8 Slf2+WN/hrbhJst7yMleU9ENwkO0q+78BOxq6fxmUqQAk0sDgPMiB09KkETekAH6AeTaz k6DtOMjbhzBd3qzLGqF7PbLA5fiInbGLHCUMsXkhQGWdHyzgTMb9O/u2Ij2rjYXCu2ALM HS/6omKYUzSisfExqxJldZU9dXVRuTKfsp+08roDvoMvc306Zdk726so8ZQvXoVn9+MHb CgYHFwe8WIQCIyAGY5Fo+6MijiJSff4v/VOICHYFwFbeW32z6qL3+0ComQ0a9d9KZBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380490; 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=OoG8WY4C0Eh5kTaQZQ9oxgZoKWYmih1sbXZtTmdDdZc=; b=pJVYuI0m+QkRrhY0PEVVInvac8hizOa0etAmFPeJ+KdyJEKLb3P3Z3L7yosrREo26HKD 6EfX8L36kkTvZGtZTcyETa0Ge1DulMDf4e0gI9i4eov4OnEZTSmkIl80537XA46IuwvAa e9L5akCXtBVVGu8I/e6jx7IwWROMJRvDwMYKUZTnPisQZha1PbLt33Qp5iQFTAgp0rNH0 5/LLKiVsxyaNjzknYV9cNhNNDvC6gRX0iSTXYUc6cyvkBtehLQoXfcuC6/zXODKnHYKqY rKyUdZlRz2kAtgZvpOUqyq6VJIWaqWOOowWuQSpMPrpyV9avPCNStHp6RTIR/PbF7Sw== 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=xB5FoPCm; 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 A21A1606A696; Fri, 4 Dec 2026 10:34:50 +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=xB5FoPCm Received: by smtp.kernel.org (Postfix) with ESMTPSA id D05E61F00931; Fri, 4 Dec 2026 10:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380490; bh=OoG8WY4C0Eh5kTaQZQ9oxgZoKWYmih1sbXZtTmdDdZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xB5FoPCmENSBq1UEsV7PZYaWdNRuLccBQ2dG5Dc0jMj/21azYADyiAFYxX0BZdV2r u/vqHMfL2iw/SUN6yQwlnAnRSIzGiwltbQUe9EhQh9I7xa7Zng8RewqNx85FDlR/cW 1xVOfyaCiXp1Gt8pWpQ8/FzJ/SYsl5GcCSKoVJRg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 295/742] bpf, arm64: Restore the shadow call stack pointer after an exception Date: Fri, 4 Dec 2026 19:02:39 +0900 Message-ID: <20261204100642.877259641@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 918bea2c6b682405b20cde0f44e76b0161dde912 ] bpf_throw() does not return, its return address stays on the shadow call stack. The caller of the program takes it for its own. test_progs -t exceptions crashes the kernel with CONFIG_SHADOW_CALL_STACK: Internal error: Oops - FPAC: 0000000072000000 [#1] SMP pc : bpf_test_run+0x410/0x968 JITed code puts nothing on the shadow call stack, and bpf_throw() skips only frames of JITed code. So that address is the only entry that is left behind. Pop it in the prologue of the exception callback. Fixes: 22fc0e80aeb5 ("bpf, arm64: support exceptions") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-38-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- arch/arm64/net/bpf_jit_comp.c | 7 +++++++ kernel/bpf/helpers.c | 1 + 2 files changed, 8 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index d393fa6bfbf4d..b96bf0126b8f2 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -599,6 +600,12 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf) * 12 registers are on the stack */ emit(A64_SUB_I(1, A64_SP, A64_FP, 96), ctx); + /* + * Pop the return address of bpf_throw() from the shadow call + * stack. The frames of the JIT put nothing there. + */ + if (scs_is_enabled()) + emit(A64_SUB_I(1, A64_R(18), A64_R(18), 8), ctx); /* The callback may use its own BPF stack, set up fp for it. */ ctx->fp_used = true; } diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index daef14d343aad..42d6b22edfcdf 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -3416,6 +3416,7 @@ __bpf_kfunc notrace __no_sanitize_address void bpf_throw(u64 cookie) WARN_ON_ONCE(!ctx.aux->exception_boundary); WARN_ON_ONCE(!ctx.bp); WARN_ON_ONCE(!ctx.cnt); + /* arm64 drops one entry of the shadow call stack, don't move the call to a callee */ ctx.aux->bpf_exception_cb(cookie, ctx.sp + ctx.aux->stack_arg_sp_adjust, ctx.bp, 0, 0); WARN(1, "A call to BPF exception callback should never return\n"); } -- 2.53.0