linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf/verifier: fix control flow issues in __reg64_bound_u32()
@ 2022-07-29  5:49 Zeng Jingxiang
  2022-07-29 17:15 ` Yonghong Song
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng Jingxiang @ 2022-07-29  5:49 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, song, yhs,
	kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, Zeng Jingxiang

From: Zeng Jingxiang <linuszeng@tencent.com>

This greater-than-or-equal-to-zero comparison of an unsigned value
is always true. "a >= U32_MIN".
1632	return a >= U32_MIN && a <= U32_MAX;

Fixes: b9979db83401 ("bpf: Fix propagation of bounds from 64-bit min/max into 32-bit and var_off.")
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
---
 kernel/bpf/verifier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 0efbac0fd126..dd67108fb1d7 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1629,7 +1629,7 @@ static bool __reg64_bound_s32(s64 a)
 
 static bool __reg64_bound_u32(u64 a)
 {
-	return a >= U32_MIN && a <= U32_MAX;
+	return a <= U32_MAX;
 }
 
 static void __reg_combine_64_into_32(struct bpf_reg_state *reg)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf/verifier: fix control flow issues in __reg64_bound_u32()
  2022-07-29  5:49 [PATCH] bpf/verifier: fix control flow issues in __reg64_bound_u32() Zeng Jingxiang
@ 2022-07-29 17:15 ` Yonghong Song
  2022-07-29 17:17   ` Hao Luo
  0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2022-07-29 17:15 UTC (permalink / raw)
  To: Zeng Jingxiang, ast, daniel, john.fastabend, andrii, martin.lau,
	song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, Zeng Jingxiang



On 7/28/22 10:49 PM, Zeng Jingxiang wrote:
> From: Zeng Jingxiang <linuszeng@tencent.com>
> 
> This greater-than-or-equal-to-zero comparison of an unsigned value
> is always true. "a >= U32_MIN".
> 1632	return a >= U32_MIN && a <= U32_MAX;
> 
> Fixes: b9979db83401 ("bpf: Fix propagation of bounds from 64-bit min/max into 32-bit and var_off.")
> Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
> ---
>   kernel/bpf/verifier.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 0efbac0fd126..dd67108fb1d7 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -1629,7 +1629,7 @@ static bool __reg64_bound_s32(s64 a)
>   
>   static bool __reg64_bound_u32(u64 a)
>   {
> -	return a >= U32_MIN && a <= U32_MAX;
> +	return a <= U32_MAX;
>   }

I cannot find the related link. But IIRC, Alexei commented that
the code is written this way to express the intention (within
32bit bounds) so this patch is unnecessary...

>   
>   static void __reg_combine_64_into_32(struct bpf_reg_state *reg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf/verifier: fix control flow issues in __reg64_bound_u32()
  2022-07-29 17:15 ` Yonghong Song
@ 2022-07-29 17:17   ` Hao Luo
  0 siblings, 0 replies; 3+ messages in thread
From: Hao Luo @ 2022-07-29 17:17 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Zeng Jingxiang, ast, daniel, john.fastabend, andrii, martin.lau,
	song, kpsingh, sdf, jolsa, bpf, linux-kernel, Zeng Jingxiang

On Fri, Jul 29, 2022 at 10:15 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 7/28/22 10:49 PM, Zeng Jingxiang wrote:
> > From: Zeng Jingxiang <linuszeng@tencent.com>
> >
> > This greater-than-or-equal-to-zero comparison of an unsigned value
> > is always true. "a >= U32_MIN".
> > 1632  return a >= U32_MIN && a <= U32_MAX;
> >
> > Fixes: b9979db83401 ("bpf: Fix propagation of bounds from 64-bit min/max into 32-bit and var_off.")
> > Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
> > ---
> >   kernel/bpf/verifier.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 0efbac0fd126..dd67108fb1d7 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -1629,7 +1629,7 @@ static bool __reg64_bound_s32(s64 a)
> >
> >   static bool __reg64_bound_u32(u64 a)
> >   {
> > -     return a >= U32_MIN && a <= U32_MAX;
> > +     return a <= U32_MAX;
> >   }
>
> I cannot find the related link. But IIRC, Alexei commented that
> the code is written this way to express the intention (within
> 32bit bounds) so this patch is unnecessary...
>

Yeah, I agree with Yonghong. I was about to reply.

Jingxiang, you are absolutely correct that a <= U32_MAX is redundant,
but I feel having both sides checked explicitly makes code more
readable.

> >
> >   static void __reg_combine_64_into_32(struct bpf_reg_state *reg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-29 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29  5:49 [PATCH] bpf/verifier: fix control flow issues in __reg64_bound_u32() Zeng Jingxiang
2022-07-29 17:15 ` Yonghong Song
2022-07-29 17:17   ` Hao Luo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).