2022-06-10 19:48:57

by Yosry Ahmed

[permalink] [raw]
Subject: [PATCH bpf-next v2 3/8] bpf, iter: Fix the condition on p when calling stop.

From: Hao Luo <[email protected]>

In bpf_seq_read, seq->op->next() could return an ERR and jump to
the label stop. However, the existing code in stop does not handle
the case when p (returned from next()) is an ERR. Adds the handling
of ERR of p by converting p into an error and jumping to done.

Because all the current implementations do not have a case that
returns ERR from next(), so this patch doesn't have behavior changes
right now.

Signed-off-by: Hao Luo <[email protected]>
Signed-off-by: Yosry Ahmed <[email protected]>
---
kernel/bpf/bpf_iter.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index d5d96ceca1058..1585caf7c7200 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -198,6 +198,11 @@ static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size,
}
stop:
offs = seq->count;
+ if (IS_ERR(p)) {
+ seq->op->stop(seq, NULL);
+ err = PTR_ERR(p);
+ goto done;
+ }
/* bpf program called if !p */
seq->op->stop(seq, p);
if (!p) {
--
2.36.1.476.g0c4daa206d-goog


2022-06-20 19:22:18

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 3/8] bpf, iter: Fix the condition on p when calling stop.



On 6/10/22 12:44 PM, Yosry Ahmed wrote:
> From: Hao Luo <[email protected]>
>
> In bpf_seq_read, seq->op->next() could return an ERR and jump to
> the label stop. However, the existing code in stop does not handle
> the case when p (returned from next()) is an ERR. Adds the handling
> of ERR of p by converting p into an error and jumping to done.
>
> Because all the current implementations do not have a case that
> returns ERR from next(), so this patch doesn't have behavior changes
> right now.
>
> Signed-off-by: Hao Luo <[email protected]>
> Signed-off-by: Yosry Ahmed <[email protected]>

Acked-by: Yonghong Song <[email protected]>

2022-06-21 08:09:59

by Hao Luo

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 3/8] bpf, iter: Fix the condition on p when calling stop.

On Mon, Jun 20, 2022 at 11:48 AM Yonghong Song <[email protected]> wrote:
>
> On 6/10/22 12:44 PM, Yosry Ahmed wrote:
> > From: Hao Luo <[email protected]>
> >
> > In bpf_seq_read, seq->op->next() could return an ERR and jump to
> > the label stop. However, the existing code in stop does not handle
> > the case when p (returned from next()) is an ERR. Adds the handling
> > of ERR of p by converting p into an error and jumping to done.
> >
> > Because all the current implementations do not have a case that
> > returns ERR from next(), so this patch doesn't have behavior changes
> > right now.
> >
> > Signed-off-by: Hao Luo <[email protected]>
> > Signed-off-by: Yosry Ahmed <[email protected]>
>
> Acked-by: Yonghong Song <[email protected]>

Yonghong, do you want to get this change in now, or you want to wait
for the whole patchset? This fix is straightforward and independent of
other parts. Yosry and I can rebase.

2022-06-24 18:04:29

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 3/8] bpf, iter: Fix the condition on p when calling stop.



On 6/21/22 12:25 AM, Hao Luo wrote:
> On Mon, Jun 20, 2022 at 11:48 AM Yonghong Song <[email protected]> wrote:
>>
>> On 6/10/22 12:44 PM, Yosry Ahmed wrote:
>>> From: Hao Luo <[email protected]>
>>>
>>> In bpf_seq_read, seq->op->next() could return an ERR and jump to
>>> the label stop. However, the existing code in stop does not handle
>>> the case when p (returned from next()) is an ERR. Adds the handling
>>> of ERR of p by converting p into an error and jumping to done.
>>>
>>> Because all the current implementations do not have a case that
>>> returns ERR from next(), so this patch doesn't have behavior changes
>>> right now.
>>>
>>> Signed-off-by: Hao Luo <[email protected]>
>>> Signed-off-by: Yosry Ahmed <[email protected]>
>>
>> Acked-by: Yonghong Song <[email protected]>
>
> Yonghong, do you want to get this change in now, or you want to wait
> for the whole patchset? This fix is straightforward and independent of
> other parts. Yosry and I can rebase.

Sorry for delay. Let me review other patches as well before your next
version.

BTW, I would be great if you just put the prerequisite patch

https://lore.kernel.org/bpf/[email protected]/
as the first patch so at least BPF CI will be able to test
your patch set. It looks like KP's bpf_getxattr patch set already did this.

https://lore.kernel.org/bpf/[email protected]/T/#u

2022-06-24 18:46:48

by Yosry Ahmed

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 3/8] bpf, iter: Fix the condition on p when calling stop.

On Fri, Jun 24, 2022 at 10:46 AM Yonghong Song <[email protected]> wrote:
>
>
>
> On 6/21/22 12:25 AM, Hao Luo wrote:
> > On Mon, Jun 20, 2022 at 11:48 AM Yonghong Song <[email protected]> wrote:
> >>
> >> On 6/10/22 12:44 PM, Yosry Ahmed wrote:
> >>> From: Hao Luo <[email protected]>
> >>>
> >>> In bpf_seq_read, seq->op->next() could return an ERR and jump to
> >>> the label stop. However, the existing code in stop does not handle
> >>> the case when p (returned from next()) is an ERR. Adds the handling
> >>> of ERR of p by converting p into an error and jumping to done.
> >>>
> >>> Because all the current implementations do not have a case that
> >>> returns ERR from next(), so this patch doesn't have behavior changes
> >>> right now.
> >>>
> >>> Signed-off-by: Hao Luo <[email protected]>
> >>> Signed-off-by: Yosry Ahmed <[email protected]>
> >>
> >> Acked-by: Yonghong Song <[email protected]>
> >
> > Yonghong, do you want to get this change in now, or you want to wait
> > for the whole patchset? This fix is straightforward and independent of
> > other parts. Yosry and I can rebase.
>
> Sorry for delay. Let me review other patches as well before your next
> version.

Thanks!

>
> BTW, I would be great if you just put the prerequisite patch

I am intending to do that in the next version if KP's patchset doesn't
land in bpf-next.

>
> https://lore.kernel.org/bpf/[email protected]/
> as the first patch so at least BPF CI will be able to test
> your patch set. It looks like KP's bpf_getxattr patch set already did this.
>
> https://lore.kernel.org/bpf/[email protected]/T/#u
>