From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <sinquersw@gmail.com>, thinker.li@gmail.com
Cc: kuifeng@meta.com, Dan Carpenter <dan.carpenter@linaro.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, song@kernel.org,
kernel-team@meta.com, andrii@kernel.org
Subject: Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
Date: Mon, 7 Aug 2023 12:49:10 -0700 [thread overview]
Message-ID: <5a910ec7-ae16-6e8e-8236-db6f9e2fe1a8@linux.dev> (raw)
In-Reply-To: <5f4bbed7-e0d1-e848-d820-e74b551075b4@gmail.com>
On 8/7/23 10:07 AM, Kui-Feng Lee wrote:
>
>
> On 8/4/23 15:26, Martin KaFai Lau wrote:
>> On 8/3/23 4:12 PM, thinker.li@gmail.com wrote:
>>> From: Kui-Feng Lee <thinker.li@gmail.com>
>>>
>>> Verify if the pointer obtained from bpf_xdp_pointer() is either an error or
>>> NULL before returning it.
>>>
>>> The function bpf_dynptr_slice() mistakenly returned an ERR_PTR. Instead of
>>> solely checking for NULL, it should also verify if the pointer returned by
>>> bpf_xdp_pointer() is an error or NULL.
>>>
>>> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>>> Closes:
>>> https://lore.kernel.org/bpf/d1360219-85c3-4a03-9449-253ea905f9d1@moroto.mountain/
>>> Fixes: 66e3a13e7c2c ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr")
>>> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
>>> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
>>> ---
>>> kernel/bpf/helpers.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
>>> index 56ce5008aedd..eb91cae0612a 100644
>>> --- a/kernel/bpf/helpers.c
>>> +++ b/kernel/bpf/helpers.c
>>> @@ -2270,7 +2270,7 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct
>>> bpf_dynptr_kern *ptr, u32 offset
>>> case BPF_DYNPTR_TYPE_XDP:
>>> {
>>> void *xdp_ptr = bpf_xdp_pointer(ptr->data, ptr->offset + offset, len);
>>> - if (xdp_ptr)
>>> + if (!IS_ERR_OR_NULL(xdp_ptr))
>>
>> Considering the earlier bpf_dynptr_check_off_len() should have avoided the
>> IS_ERR() case here, I think targeting bpf-next makes sense. Applied.
>
> It is a good point. I think the bpf_dynptr_check_off_len() check is
> wrong as well. According to the behavior of the rest of the function,
> it should be
>
> err = bpf_dynptr_check_off_len(ptr, ptr->offset + offset, len);
Not sure why it is needed either.
The bpf_dynptr_adjust() has updated the size after updating the offset.
Did I missing other offset update places?
prev parent reply other threads:[~2023-08-07 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 23:12 [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR thinker.li
2023-08-04 1:32 ` Yonghong Song
2023-08-04 17:25 ` Kui-Feng Lee
2023-08-04 22:00 ` patchwork-bot+netdevbpf
2023-08-04 22:26 ` Martin KaFai Lau
2023-08-07 17:07 ` Kui-Feng Lee
2023-08-07 19:49 ` Martin KaFai Lau [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a910ec7-ae16-6e8e-8236-db6f9e2fe1a8@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=sinquersw@gmail.com \
--cc=song@kernel.org \
--cc=thinker.li@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox