> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 1eb15a51c7dc..06aea4e499a1 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c

[ ... ]

> @@ -6317,7 +6317,12 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, 
> unsigned int size,
>               err = bpf_raw_tracepoint_open(&attr);
>               break;
>       case BPF_BTF_LOAD:
> -             err = bpf_btf_load(&attr, uattr, size);
> +             if (size >= offsetofend(union bpf_attr, btf_log_true_size))
> +                     offsetof_log_true_size = offsetof(union bpf_attr, 
> btf_log_true_size);
> +             err = bpf_log_attr_init(&attr_log, attr.btf_log_buf, 
> attr.btf_log_size,
> +                                     attr.btf_log_level, 
> offsetof_log_true_size, uattr,
> +                                     &attr_common, uattr_common, 
> size_common);
> +             err = err ?: bpf_btf_load(&attr, uattr, &attr_log);

Should the log_true_size offset be set only for user space calls? In v10
review, Andrii Nakryiko noted that log_true_size should only be set for
user space, not kernel space calls.

https://lore.kernel.org/bpf/caef4bzy3ga+860rodlaxqqo3j5agj24pmku1yv3+ghjpy0d...@mail.gmail.com/

The current code does not check uattr.is_kernel before setting
offsetof_log_true_size. This could cause issues when bpf_sys_bpf() calls
__sys_bpf() with KERNEL_BPFPTR, as it would attempt to write log_true_size
to a kernel pointer instead of a user space pointer.

>               break;
>       case BPF_BTF_GET_FD_BY_ID:
>               err = bpf_btf_get_fd_by_id(&attr);


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/24672239158

Reply via email to