]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: propagate kvmemdup_bpfptr errors from bpf_prog_verify_signature
authorWeixie Cui <cuiweixie@gmail.com>
Sat, 21 Mar 2026 06:08:00 +0000 (14:08 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 24 Mar 2026 15:48:51 +0000 (08:48 -0700)
kvmemdup_bpfptr() returns -EFAULT when the user pointer cannot be
copied, and -ENOMEM on allocation failure. The error path always
returned -ENOMEM, misreporting bad addresses as out-of-memory.

Return PTR_ERR(sig) so user space gets the correct errno.

Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/tencent_C9C5B2B28413D6303D505CD02BFEA4708C07@qq.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/syscall.c

index 274039e36465dfe4d79f20c3bb39a77a104ad36b..51ade3cde8bb3f4e1e63015a368277baacb2b61a 100644 (file)
@@ -2832,7 +2832,7 @@ static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr
        sig = kvmemdup_bpfptr(usig, attr->signature_size);
        if (IS_ERR(sig)) {
                bpf_key_put(key);
-               return -ENOMEM;
+               return PTR_ERR(sig);
        }
 
        bpf_dynptr_init(&sig_ptr, sig, BPF_DYNPTR_TYPE_LOCAL, 0,