netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f_flower: Remove always zero checks
@ 2024-07-07 17:27 Maks Mishin
  2024-07-10 23:11 ` Stephen Hemminger
  2024-07-18  0:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Maks Mishin @ 2024-07-07 17:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
has 8 trailing zero bits, which is greater or equal than the size
of the left operand == 8 bits.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 tc/f_flower.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tc/f_flower.c b/tc/f_flower.c
index 08c1001a..244f0f7e 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -1523,7 +1523,7 @@ static int flower_parse_mpls_lse(int *argc_p, char ***argv_p,
 
 			NEXT_ARG();
 			ret = get_u8(&ttl, *argv, 10);
-			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
+			if (ret < 0) {
 				fprintf(stderr, "Illegal \"ttl\"\n");
 				return -1;
 			}
@@ -1936,7 +1936,7 @@ static int flower_parse_opt(const struct filter_util *qu, char *handle,
 			}
 			mpls_format_old = true;
 			ret = get_u8(&ttl, *argv, 10);
-			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
+			if (ret < 0) {
 				fprintf(stderr, "Illegal \"mpls_ttl\"\n");
 				return -1;
 			}
-- 
2.30.2


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

* Re: [PATCH] f_flower: Remove always zero checks
  2024-07-07 17:27 [PATCH] f_flower: Remove always zero checks Maks Mishin
@ 2024-07-10 23:11 ` Stephen Hemminger
  2024-07-17 17:21   ` Guillaume Nault
  2024-07-18  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2024-07-10 23:11 UTC (permalink / raw)
  To: Maks Mishin, Guillaume Nault; +Cc: netdev

On Sun,  7 Jul 2024 20:27:41 +0300
Maks Mishin <maks.mishinfz@gmail.com> wrote:

> Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
> has 8 trailing zero bits, which is greater or equal than the size
> of the left operand == 8 bits.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  tc/f_flower.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tc/f_flower.c b/tc/f_flower.c
> index 08c1001a..244f0f7e 100644
> --- a/tc/f_flower.c
> +++ b/tc/f_flower.c
> @@ -1523,7 +1523,7 @@ static int flower_parse_mpls_lse(int *argc_p, char ***argv_p,
>  
>  			NEXT_ARG();
>  			ret = get_u8(&ttl, *argv, 10);
> -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> +			if (ret < 0) {
>  				fprintf(stderr, "Illegal \"ttl\"\n");
>  				return -1;
>  			}
> @@ -1936,7 +1936,7 @@ static int flower_parse_opt(const struct filter_util *qu, char *handle,
>  			}
>  			mpls_format_old = true;
>  			ret = get_u8(&ttl, *argv, 10);
> -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> +			if (ret < 0) {
>  				fprintf(stderr, "Illegal \"mpls_ttl\"\n");
>  				return -1;
>  			}

That is correct mathematically, but perhaps the original author had different idea.
Could we have review from someone familiar with MPLS support please.

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

* Re: [PATCH] f_flower: Remove always zero checks
  2024-07-10 23:11 ` Stephen Hemminger
@ 2024-07-17 17:21   ` Guillaume Nault
  2024-07-17 18:27     ` Simon Horman
  0 siblings, 1 reply; 5+ messages in thread
From: Guillaume Nault @ 2024-07-17 17:21 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

On Wed, Jul 10, 2024 at 04:11:39PM -0700, Stephen Hemminger wrote:
> On Sun,  7 Jul 2024 20:27:41 +0300
> Maks Mishin <maks.mishinfz@gmail.com> wrote:
> 
> > Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
> > has 8 trailing zero bits, which is greater or equal than the size
> > of the left operand == 8 bits.
> > 
> > Found by RASU JSC.
> > 
> > Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> > ---
> >  tc/f_flower.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tc/f_flower.c b/tc/f_flower.c
> > index 08c1001a..244f0f7e 100644
> > --- a/tc/f_flower.c
> > +++ b/tc/f_flower.c
> > @@ -1523,7 +1523,7 @@ static int flower_parse_mpls_lse(int *argc_p, char ***argv_p,
> >  
> >  			NEXT_ARG();
> >  			ret = get_u8(&ttl, *argv, 10);
> > -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> > +			if (ret < 0) {
> >  				fprintf(stderr, "Illegal \"ttl\"\n");
> >  				return -1;
> >  			}
> > @@ -1936,7 +1936,7 @@ static int flower_parse_opt(const struct filter_util *qu, char *handle,
> >  			}
> >  			mpls_format_old = true;
> >  			ret = get_u8(&ttl, *argv, 10);
> > -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> > +			if (ret < 0) {
> >  				fprintf(stderr, "Illegal \"mpls_ttl\"\n");
> >  				return -1;
> >  			}
> 
> That is correct mathematically, but perhaps the original author had different idea.
> Could we have review from someone familiar with MPLS support please.

The MPLS TTL field is an 8 bits value. Therefore any successful return
of get_u8() should be valid and this test is indeed not needed.

I guess the original intent was to keep consistency with how the other
MPLS parameters are validated. But TTL is indeed a special case as it's
the only parameter with a "common" length.

Reviewed-by: Guillaume Nault <gnault@redhat.com>


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

* Re: [PATCH] f_flower: Remove always zero checks
  2024-07-17 17:21   ` Guillaume Nault
@ 2024-07-17 18:27     ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2024-07-17 18:27 UTC (permalink / raw)
  To: Guillaume Nault; +Cc: Stephen Hemminger, Maks Mishin, netdev

On Wed, Jul 17, 2024 at 07:21:30PM +0200, Guillaume Nault wrote:
> On Wed, Jul 10, 2024 at 04:11:39PM -0700, Stephen Hemminger wrote:
> > On Sun,  7 Jul 2024 20:27:41 +0300
> > Maks Mishin <maks.mishinfz@gmail.com> wrote:
> > 
> > > Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
> > > has 8 trailing zero bits, which is greater or equal than the size
> > > of the left operand == 8 bits.
> > > 
> > > Found by RASU JSC.
> > > 
> > > Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> > > ---
> > >  tc/f_flower.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/tc/f_flower.c b/tc/f_flower.c
> > > index 08c1001a..244f0f7e 100644
> > > --- a/tc/f_flower.c
> > > +++ b/tc/f_flower.c
> > > @@ -1523,7 +1523,7 @@ static int flower_parse_mpls_lse(int *argc_p, char ***argv_p,
> > >  
> > >  			NEXT_ARG();
> > >  			ret = get_u8(&ttl, *argv, 10);
> > > -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> > > +			if (ret < 0) {
> > >  				fprintf(stderr, "Illegal \"ttl\"\n");
> > >  				return -1;
> > >  			}
> > > @@ -1936,7 +1936,7 @@ static int flower_parse_opt(const struct filter_util *qu, char *handle,
> > >  			}
> > >  			mpls_format_old = true;
> > >  			ret = get_u8(&ttl, *argv, 10);
> > > -			if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) {
> > > +			if (ret < 0) {
> > >  				fprintf(stderr, "Illegal \"mpls_ttl\"\n");
> > >  				return -1;
> > >  			}
> > 
> > That is correct mathematically, but perhaps the original author had different idea.
> > Could we have review from someone familiar with MPLS support please.
> 
> The MPLS TTL field is an 8 bits value. Therefore any successful return
> of get_u8() should be valid and this test is indeed not needed.
> 
> I guess the original intent was to keep consistency with how the other
> MPLS parameters are validated. But TTL is indeed a special case as it's
> the only parameter with a "common" length.
> 
> Reviewed-by: Guillaume Nault <gnault@redhat.com>

Thanks Guillaume,

Yes, I agree that was very likely the intent.

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH] f_flower: Remove always zero checks
  2024-07-07 17:27 [PATCH] f_flower: Remove always zero checks Maks Mishin
  2024-07-10 23:11 ` Stephen Hemminger
@ 2024-07-18  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-07-18  0:00 UTC (permalink / raw)
  To: Maks Mishin; +Cc: stephen, maks.mishinFZ, netdev

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Sun,  7 Jul 2024 20:27:41 +0300 you wrote:
> Expression 'ttl & ~(255 >> 0)' is always zero, because right operand
> has 8 trailing zero bits, which is greater or equal than the size
> of the left operand == 8 bits.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> 
> [...]

Here is the summary with links:
  - f_flower: Remove always zero checks
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=b06341a252a8

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] 5+ messages in thread

end of thread, other threads:[~2024-07-18  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-07 17:27 [PATCH] f_flower: Remove always zero checks Maks Mishin
2024-07-10 23:11 ` Stephen Hemminger
2024-07-17 17:21   ` Guillaume Nault
2024-07-17 18:27     ` Simon Horman
2024-07-18  0:00 ` patchwork-bot+netdevbpf

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).