Re: [PATCHv4 bpf-next 1/4] bpf: Mark vma objects as trusted for task_vma iter and find_vma callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 28, 2022 at 11:04 AM Yonghong Song <yhs@xxxxxxxx> wrote:
>
>
>
> On 11/28/22 10:43 AM, Alexei Starovoitov wrote:
> > On Mon, Nov 28, 2022 at 5:29 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> >>
> >> Marking following vma objects as trusted so they can be used
> >> as arguments for kfunc function added in following changes:
> >>
> >>    - vma object argument in find_vma callback function
> >>    - vma object in context of task_vma iterator program
> >>
> >> Both places lock vma object so it can't go away while running
> >> the bpf program.
> >>
> >> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> >> ---
> >>   kernel/bpf/task_iter.c | 2 +-
> >>   kernel/bpf/verifier.c  | 2 +-
> >>   2 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
> >> index c2a2182ce570..cd67b3cadd91 100644
> >> --- a/kernel/bpf/task_iter.c
> >> +++ b/kernel/bpf/task_iter.c
> >> @@ -755,7 +755,7 @@ static struct bpf_iter_reg task_vma_reg_info = {
> >>                  { offsetof(struct bpf_iter__task_vma, task),
> >>                    PTR_TO_BTF_ID_OR_NULL },
> >>                  { offsetof(struct bpf_iter__task_vma, vma),
> >> -                 PTR_TO_BTF_ID_OR_NULL },
> >> +                 PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED },
> >
> > Yonghong, Song,
> >
> > Do you remember when task or vma is NULL here?
> > Maybe we can do: if (!task || !vma) skip prog run
> > in __task_vma_seq_show()
> > and make both pointers as PTR_TO_BTF_ID | PTR_TRUSTED?
>
> The 'NULL' is to indicate the last bpf prog run before iteration
> ends. It is to provide an opportunity for bpf program to know
> all regular iterations are done and the bpf program can do
> end aggregation or print a footer if the prog link is cat'able.

Ahh. Right. Now I remember :)
I think we're fine with PTR_TRUSTED here.
The pointer still has to be checked for != NULL before
being dereferenced or passed into kfunc.



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux