[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bza67tpBiquJr-+ZMTTa=+29iz6Ag2+vCKyhZQv4yj9m0w@mail.gmail.com>
Date: Wed, 6 Nov 2024 14:18:37 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Juntong Deng <juntong.deng@...look.com>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, John Fastabend <john.fastabend@...il.com>,
Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>, Eddy Z <eddyz87@...il.com>,
Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
Kumar Kartikeya Dwivedi <memxor@...il.com>, snorcht@...il.com,
Christian Brauner <brauner@...nel.org>, bpf <bpf@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
Linux-Fsdevel <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH bpf-next v3 1/4] bpf/crib: Introduce task_file open-coded
iterator kfuncs
On Wed, Nov 6, 2024 at 2:13 PM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> On Wed, Nov 6, 2024 at 2:10 PM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
> > > > +__bpf_kfunc int bpf_iter_task_file_new(struct bpf_iter_task_file *it,
> > > > + struct task_struct *task)
> > > > +{
> > > > + struct bpf_iter_task_file_kern *kit = (void *)it;
> > > > +
> > > > + BUILD_BUG_ON(sizeof(struct bpf_iter_task_file_kern) > sizeof(struct bpf_iter_task_file));
> > > > + BUILD_BUG_ON(__alignof__(struct bpf_iter_task_file_kern) !=
> > > > + __alignof__(struct bpf_iter_task_file));
> > > > +
> > > > + kit->task = task;
> > >
> > > This is broken, since task refcnt can drop while iter is running.
> >
> > I noticed this as well, but I thought that given KF_TRUSTED_ARGS we
> > should have a guarantee that the task survives the iteration? Am I
> > mistaken?
>
> KF_TRUSTED_ARGS will only guarantee that the task is valid when it's
> passed into this kfunc. Right after the prog can call
> bpf_task_release() to release the ref and kit->task will become
> dangling.
> If this object was RCU protected we could have marked this iter
> as KF_RCU_PROTECTED, then the verifier would make sure that
> RCU unlock doesn't happen between iter_new and iter_destroy.
I see, it makes sense. I guess we'll need tryget_task_struct() here
and just return an error if we failed to get it.
Powered by blists - more mailing lists