Re: [PATCH bpf-next 1/2] bpf: Make the pointer returned by iter next method valid
From: Alexei Starovoitov
Date: Tue Aug 20 2024 - 02:29:17 EST
On Mon, Aug 19, 2024 at 6:24 PM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
>
> > >
> > > [0]:
> > > https://lore.kernel.org/bpf/CAP01T75na=fz7EhrP4Aw0WZ33R7jTbZ4BcmY56S1xTWczxHXWw@xxxxxxxxxxxxxx/
> > >
> > > Maybe we can have more discussion?
> > >
> > > (This email has been CC Kumar)
> >
> > +1
> > pointer from iterator should always be trusted except
> > the case of KF_RCU_PROTECTED iterators.
> > Those iters clear iter itself outside of RCU CS,
> > so a pointer returned from iter_next should probably be
> > PTR_TO_BTF_ID | MEM_RCU | PTR_MAYBE_NULL.
> >
> > For all other iters it should be safe to return
> > PTR_TO_BTF_ID | PTR_TRUSTED | PTR_MAYBE_NULL
> >
>
> Ok, but we at some point might need to return a non-RCU/non-trusted
> pointer, so I guess we'll have to add yet another flag to opt-out of
> "trustedness"?
If such case ever happens then yes, we'd need a new flag,
but I don't see it's happening