* [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
@ 2023-08-03 23:12 thinker.li
2023-08-04 1:32 ` Yonghong Song
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: thinker.li @ 2023-08-03 23:12 UTC (permalink / raw)
To: bpf, ast, martin.lau, song, kernel-team, andrii
Cc: sinquersw, kuifeng, Kui-Feng Lee, Dan Carpenter,
Alexei Starovoitov
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))
return xdp_ptr;
if (!buffer__opt)
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
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
2 siblings, 1 reply; 7+ messages in thread
From: Yonghong Song @ 2023-08-04 1:32 UTC (permalink / raw)
To: thinker.li, bpf, ast, martin.lau, song, kernel-team, andrii
Cc: sinquersw, kuifeng, Dan Carpenter, Alexei Starovoitov
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>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
2023-08-04 1:32 ` Yonghong Song
@ 2023-08-04 17:25 ` Kui-Feng Lee
0 siblings, 0 replies; 7+ messages in thread
From: Kui-Feng Lee @ 2023-08-04 17:25 UTC (permalink / raw)
To: yonghong.song, thinker.li, bpf, ast, martin.lau, song,
kernel-team, andrii
Cc: kuifeng, Dan Carpenter, Alexei Starovoitov
On 8/3/23 18:32, Yonghong Song 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>
>
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
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 22:00 ` patchwork-bot+netdevbpf
2023-08-04 22:26 ` Martin KaFai Lau
2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-04 22:00 UTC (permalink / raw)
To: Kui-Feng Lee
Cc: bpf, ast, martin.lau, song, kernel-team, andrii, sinquersw,
kuifeng, dan.carpenter, alexei.starovoitov
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:
On Thu, 3 Aug 2023 16:12:06 -0700 you 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.
>
> [...]
Here is the summary with links:
- [bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
https://git.kernel.org/bpf/bpf-next/c/5426700e6841
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
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 22:00 ` patchwork-bot+netdevbpf
@ 2023-08-04 22:26 ` Martin KaFai Lau
2023-08-07 17:07 ` Kui-Feng Lee
2 siblings, 1 reply; 7+ messages in thread
From: Martin KaFai Lau @ 2023-08-04 22:26 UTC (permalink / raw)
To: thinker.li
Cc: sinquersw, kuifeng, Dan Carpenter, Alexei Starovoitov, bpf, ast,
song, kernel-team, andrii
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
2023-08-04 22:26 ` Martin KaFai Lau
@ 2023-08-07 17:07 ` Kui-Feng Lee
2023-08-07 19:49 ` Martin KaFai Lau
0 siblings, 1 reply; 7+ messages in thread
From: Kui-Feng Lee @ 2023-08-07 17:07 UTC (permalink / raw)
To: Martin KaFai Lau, thinker.li
Cc: kuifeng, Dan Carpenter, Alexei Starovoitov, bpf, ast, song,
kernel-team, andrii
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);
How do you think?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR.
2023-08-07 17:07 ` Kui-Feng Lee
@ 2023-08-07 19:49 ` Martin KaFai Lau
0 siblings, 0 replies; 7+ messages in thread
From: Martin KaFai Lau @ 2023-08-07 19:49 UTC (permalink / raw)
To: Kui-Feng Lee, thinker.li
Cc: kuifeng, Dan Carpenter, Alexei Starovoitov, bpf, ast, song,
kernel-team, andrii
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?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-07 19:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox