Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: don't skip other information if xlated_prog_insns is skipped

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>

authored by

Altgelt, Max (Nextron) and committed by
Alexei Starovoitov
4722981c 6cc73f35

+11 -11
+11 -11
kernel/bpf/syscall.c
··· 5056 5056 struct bpf_insn *insns_sanitized; 5057 5057 bool fault; 5058 5058 5059 - if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { 5059 + if (!prog->blinded || bpf_dump_raw_ok(file->f_cred)) { 5060 + insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); 5061 + if (!insns_sanitized) 5062 + return -ENOMEM; 5063 + uinsns = u64_to_user_ptr(info.xlated_prog_insns); 5064 + ulen = min_t(u32, info.xlated_prog_len, ulen); 5065 + fault = copy_to_user(uinsns, insns_sanitized, ulen); 5066 + kfree(insns_sanitized); 5067 + if (fault) 5068 + return -EFAULT; 5069 + } else { 5060 5070 info.xlated_prog_insns = 0; 5061 - goto done; 5062 5071 } 5063 - insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); 5064 - if (!insns_sanitized) 5065 - return -ENOMEM; 5066 - uinsns = u64_to_user_ptr(info.xlated_prog_insns); 5067 - ulen = min_t(u32, info.xlated_prog_len, ulen); 5068 - fault = copy_to_user(uinsns, insns_sanitized, ulen); 5069 - kfree(insns_sanitized); 5070 - if (fault) 5071 - return -EFAULT; 5072 5072 } 5073 5073 5074 5074 if (bpf_prog_is_offloaded(prog->aux)) {