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=1796380488; b=JdXnV+QAjfpH6KtBmBL3sufCftWtTTVBhdbTJzIVG6skCJS35qo6TCxCN78100Wm7Syp XxaQUM/F+II6bdfEZq413V7j9mChOFXTKWT7eDtt6gN1vvyPu6hhli/sn6AK4v9qQ7tns /xeOdM+ssfIf5gYMdqk7fr6IyU84T6iJ2oYQpvSkhCt++Xzje8KYZndtzSMvnQtQJu2S7 znCs/1x2DoW8oHhs7oCcTcizNRAlLH6NZXhdvuB1IseLYWpfBO4R7RFItD8J33bRuFYr/ y1COol2butmRD0y3g3Dblrfrzcac8N4BkzrW1yF5Y/oJEcGjAQcfhs41LU0tnXop+fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380488; 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=yjX9VPMV70TI6WJs25sJVRM/2dOKE/wevRiDu2MChEo=; b=nTbM8zlFqSSwFmFNVps7Sx5Szr9m6UaYW/HrOAua+D3BYOWGRc3tzdK0Fpgt4hiZpwKp YYBbfzGpRodmVFnXKL4/Mo74Yl+CE3VkIIu7yHyLEYzB6Kwk22AuxhJ1zgED7TlwFLgUB kwqZ5KWz7LFmCkYWtUkEFJtEAuTsABSPzXPBUytOWrUPPkbDB37w4RaSq79dv2YqbmSBl wXT9TARt31lPrtLtyL57VdClTggeX23QUTBCLjHcoYSMS4gwIaG4+YWbxzSP8R6Z/Ojqk Jg+dZ00mkpMxLxr5qurHo3qM2Jda0SJDgg+02JJAkZTvcfXvGWl/JBS2Lp7glU/Ug3Q== 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=mc4sU0FX; 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 29BC5606A69C; Fri, 4 Dec 2026 10:34:48 +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=mc4sU0FX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 997561F000C2; Fri, 4 Dec 2026 10:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380488; bh=yjX9VPMV70TI6WJs25sJVRM/2dOKE/wevRiDu2MChEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mc4sU0FXZ0LsfKygIrjjlTQwAsRrojs7dksdD54YntpPN9nRjVW3yJ+j7/TNH+1/R qUk8XIGYn7fcFUJxDEmV3IIxoeUylYU/IGurWIkReBZheYmFkadiRA1qNltSXGLXzP 6Xuyo2NiHKdPWW7RPQ1CpUserk0DIgxuGsNsdm70= 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 294/742] bpf, x86: Fix the range of BPF code that has a frame pointer Date: Fri, 4 Dec 2026 19:02:38 +0900 Message-ID: <20261204100642.852211967@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: 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 1c34522e8b78b3d91b75fd7bd2318c8e7e293a76 ] The ORC unwinder trusts rbp between ksym.fp_start and ksym.fp_end. The JIT sets fp_end to an offset in the code of the exit insn, and fp_start counts the CFI preamble, which is in front of the symbol. The main program of a program with subprogs and trampolines of struct_ops get neither. The range ends at the epilogue, compilers put blocks behind it. So stack traces with BPF code in them are not reliable, and livepatch waits for tasks that sleep there. Behind the prologue of a program only the return has no frame. Record its offset in fp_ret and take all the rest. Count from the start of the symbol, copy the offsets from func[0], and from a struct bpf_tramp_image that struct_ops passes for the time of the call. Fixes: ca45c84afb8c ("bpf: Add bpf_has_frame_pointer()") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-37-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- arch/x86/net/bpf_jit_comp.c | 11 +++++------ include/linux/bpf.h | 5 +++-- kernel/bpf/bpf_struct_ops.c | 12 +++++++++--- kernel/bpf/core.c | 2 +- kernel/bpf/fixups.c | 3 +++ net/bpf/bpf_dummy_struct_ops.c | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 1b56cb973d79e..0b95d84259cc5 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -1787,7 +1787,8 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int * bpf_prog_was_classic(bpf_prog), tail_call_reachable, bpf_is_subprog(bpf_prog), bpf_prog->aux->exception_cb); - bpf_prog->aux->ksym.fp_start = prog - temp; + bpf_prog->aux->ksym.fp_start = prog - temp - cfi_get_offset(); + bpf_prog->aux->ksym.fp_end = U32_MAX; /* Exception callback will clobber callee regs for its own use, and * restore the original callee regs from main prog's stack frame. @@ -2970,7 +2971,7 @@ st: insn_off = insn->off; pop_r12(&prog); } EMIT1(0xC9); /* leave */ - bpf_prog->aux->ksym.fp_end = prog - temp; + bpf_prog->aux->ksym.fp_ret = proglen + (prog - temp) - cfi_get_offset(); emit_return(&prog, image + addrs[i - 1] + (prog - temp)); break; @@ -3628,8 +3629,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im } EMIT1(0x55); /* push rbp */ EMIT3(0x48, 0x89, 0xE5); /* mov rbp, rsp */ - if (im) - im->ksym.fp_start = prog - (u8 *)rw_image; + im->ksym.fp_start = prog - (u8 *)rw_image; if (!is_imm8(stack_size)) { /* sub rsp, stack_size */ @@ -3775,8 +3775,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im emit_ldx(&prog, BPF_DW, BPF_REG_6, BPF_REG_FP, -rbx_off); EMIT1(0xC9); /* leave */ - if (im) - im->ksym.fp_end = prog - (u8 *)rw_image; + im->ksym.fp_end = prog - (u8 *)rw_image; if (flags & BPF_TRAMP_F_SKIP_FRAME) { /* skip our return address and return to parent */ diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 8a8c54cc3d862..4fcaf3d7f4720 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1367,6 +1367,7 @@ struct bpf_ksym { bool prog; u32 fp_start; u32 fp_end; + u32 fp_ret; /* a return in between, it has no frame */ }; enum bpf_tramp_prog_type { @@ -1411,7 +1412,7 @@ static inline void bpf_tramp_image_add_skip(struct bpf_tramp_image *im, struct b { struct bpf_tramp_skip *skip; - /* struct_ops trampolines and arch_bpf_trampoline_size() have no image */ + /* struct_ops trampolines and arch_bpf_trampoline_size() have none */ if (!im || !im->skips) return; skip = &im->skips[im->nr_skips++]; @@ -2295,7 +2296,7 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_nodes *tnodes, const struct btf_func_model *model, void *stub_func, void **image, u32 *image_off, - bool allow_alloc); + bool allow_alloc, struct bpf_ksym *ksym); void bpf_struct_ops_image_free(void *image); static inline bool bpf_try_module_get(const void *data, struct module *owner) { diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 3b747eb52aa3a..f374a5ccbfbd8 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -639,9 +639,10 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_nodes *tnodes, const struct btf_func_model *model, void *stub_func, void **_image, u32 *_image_off, - bool allow_alloc) + bool allow_alloc, struct bpf_ksym *ksym) { u32 image_off = *_image_off, flags = BPF_TRAMP_F_INDIRECT; + struct bpf_tramp_image im = {}; void *image = *_image; int size; @@ -666,7 +667,7 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_nodes *tnodes, image_off = 0; } - size = arch_prepare_bpf_trampoline(NULL, image + image_off, + size = arch_prepare_bpf_trampoline(&im, image + image_off, image + image_off + size, model, flags, tnodes, stub_func); if (size <= 0) { @@ -675,6 +676,10 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_nodes *tnodes, return size ? : -EFAULT; } + if (ksym) { + ksym->fp_start = im.ksym.fp_start; + ksym->fp_end = im.ksym.fp_end; + } *_image = image; *_image_off = image_off + size; return 0; @@ -878,7 +883,8 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, &st_ops->func_models[i], *(void **)(st_ops->cfi_stubs + moff), &image, &image_off, - st_map->image_pages_cnt < MAX_TRAMP_IMAGE_PAGES); + st_map->image_pages_cnt < MAX_TRAMP_IMAGE_PAGES, + ksym); if (err) goto reset_unlock; diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 44eb17428fbc3..90eba581fcef4 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -781,7 +781,7 @@ bool bpf_has_frame_pointer(unsigned long ip) offset = ip - ksym->start; - return offset >= ksym->fp_start && offset < ksym->fp_end; + return offset >= ksym->fp_start && offset < ksym->fp_end && offset != ksym->fp_ret; } const struct exception_table_entry *search_bpf_extables(unsigned long addr) diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c index 927078bda67be..2f53df08e7056 100644 --- a/kernel/bpf/fixups.c +++ b/kernel/bpf/fixups.c @@ -1373,6 +1373,9 @@ static int jit_subprogs(struct bpf_verifier_env *env) prog->jited_len = func[0]->jited_len; prog->aux->extable = func[0]->aux->extable; prog->aux->num_exentries = func[0]->aux->num_exentries; + prog->aux->ksym.fp_start = func[0]->aux->ksym.fp_start; + prog->aux->ksym.fp_end = func[0]->aux->ksym.fp_end; + prog->aux->ksym.fp_ret = func[0]->aux->ksym.fp_ret; prog->aux->func = func; prog->aux->func_cnt = env->subprog_cnt - env->hidden_subprog_cnt; prog->aux->real_func_cnt = env->subprog_cnt; diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index 191a6b3ee2541..c724a6bc7b807 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c @@ -179,7 +179,7 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, &st_ops->func_models[op_idx], &dummy_ops_test_ret_function, &image, &image_off, - true); + true, NULL); if (err < 0) goto out; -- 2.53.0