]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
LoongArch: BPF: Make error handling robust in arch_prepare_bpf_trampoline()
authorHengqi Chen <hengqi.chen@gmail.com>
Thu, 2 Oct 2025 14:39:53 +0000 (22:39 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 2 Oct 2025 14:39:53 +0000 (22:39 +0800)
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 <vincent.mc.li@gmail.com>
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/net/bpf_jit.c

index a941a9f4c3379b1fa8db5c011a34f0e4c2d78e88..fa1a3234e9a60a3108f35e01fe77fff2a30deaa2 100644 (file)
@@ -1715,7 +1715,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;
        }