]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: don't skip other information if xlated_prog_insns is skipped
authorAltgelt, Max (Nextron) <max.altgelt@nextron-systems.com>
Tue, 4 Nov 2025 14:26:56 +0000 (14:26 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 15 Nov 2025 02:55:06 +0000 (18:55 -0800)
If xlated_prog_insns should not be exposed, other information
(such as func_info) still can and should be filled in.
Therefore, instead of directly terminating in this case,
continue with the normal flow.

Signed-off-by: Max Altgelt <max.altgelt@nextron-systems.com>
Link: https://lore.kernel.org/r/efd00fcec5e3e247af551632726e2a90c105fbd8.camel@nextron-systems.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/syscall.c

index f62d61b6730a27bdd4e9eaccb70f5d61127d5ef1..a2a441185f8109398ec0f592e32e51041b53e915 100644 (file)
@@ -5056,19 +5056,19 @@ static int bpf_prog_get_info_by_fd(struct file *file,
                struct bpf_insn *insns_sanitized;
                bool fault;
 
-               if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) {
+               if (!prog->blinded || bpf_dump_raw_ok(file->f_cred)) {
+                       insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred);
+                       if (!insns_sanitized)
+                               return -ENOMEM;
+                       uinsns = u64_to_user_ptr(info.xlated_prog_insns);
+                       ulen = min_t(u32, info.xlated_prog_len, ulen);
+                       fault = copy_to_user(uinsns, insns_sanitized, ulen);
+                       kfree(insns_sanitized);
+                       if (fault)
+                               return -EFAULT;
+               } else {
                        info.xlated_prog_insns = 0;
-                       goto done;
                }
-               insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred);
-               if (!insns_sanitized)
-                       return -ENOMEM;
-               uinsns = u64_to_user_ptr(info.xlated_prog_insns);
-               ulen = min_t(u32, info.xlated_prog_len, ulen);
-               fault = copy_to_user(uinsns, insns_sanitized, ulen);
-               kfree(insns_sanitized);
-               if (fault)
-                       return -EFAULT;
        }
 
        if (bpf_prog_is_offloaded(prog->aux)) {