From: Hengqi Chen Date: Thu, 2 Oct 2025 14:39:53 +0000 (+0800) Subject: LoongArch: BPF: Make error handling robust in arch_prepare_bpf_trampoline() X-Git-Tag: v6.17.3~37 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=5c3fc72bf4715c30b3762e5009f4999813035626;p=thirdparty%2Fkernel%2Fstable.git LoongArch: BPF: Make error handling robust in arch_prepare_bpf_trampoline() commit de2c0b7788648850b68b75f7cc8698b2749dd31e upstream. Bail out instead of trying to perform a bpf_arch_text_copy() if __arch_prepare_bpf_trampoline() failed. Cc: stable@vger.kernel.org Tested-by: Vincent Li Signed-off-by: Hengqi Chen Signed-off-by: Huacai Chen Signed-off-by: Greg Kroah-Hartman --- diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 8d534a0dad87c..a81a5d28a8213 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -1756,7 +1756,10 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image, jit_fill_hole(image, (unsigned int)(ro_image_end - ro_image)); ret = __arch_prepare_bpf_trampoline(&ctx, im, m, tlinks, func_addr, flags); - if (ret > 0 && validate_code(&ctx) < 0) { + if (ret < 0) + goto out; + + if (validate_code(&ctx) < 0) { ret = -EINVAL; goto out; }