diff mbox series

[bpf-next] use correct format string specifier for unsigned 32 bounds

Message ID 92abb6ec-84d9-6210-df13-ea563e0d1fa1@rub.de (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] use correct format string specifier for unsigned 32 bounds | expand

Checks

Context Check Description
netdev/apply fail Patch does not apply to bpf-next
netdev/tree_selection success Clearly marked for bpf-next

Commit Message

Benedict Schlueter June 4, 2021, 7:50 a.m. UTC
From fd076dc5f2bd5ec4e9cb49530e77cf2d3e4f42c2 Mon Sep 17 00:00:00 2001
From: Benedict Schlueter <benedict.schlueter@rub.de>
Date: Wed, 2 Jun 2021 21:42:39 +0200
Subject: [PATCH bpf-next]
  use correct format string specifier for unsigned 32 bounds

when printing an unsigned value, it should be a positive number

verifier log before the patch
([...],s32_max_value=-2,u32_min_value=-16,u32_max_value=-2)

verifier log after the patch
([...],s32_max_value=-2,u32_min_value=4294967280,u32_max_value=4294967294)


Fixes: 3f50f132d840 ("bpf: Verifier, do explicit ALU32 bounds tracking")
Signed-off-by: Benedict Schlueter <benedict.schlueter@rub.de>
---
  kernel/bpf/verifier.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

          }

Comments

Yonghong Song June 4, 2021, 3:44 p.m. UTC | #1
On 6/4/21 12:50 AM, Benedict Schlueter wrote:
>  From fd076dc5f2bd5ec4e9cb49530e77cf2d3e4f42c2 Mon Sep 17 00:00:00 2001
> From: Benedict Schlueter <benedict.schlueter@rub.de>
> Date: Wed, 2 Jun 2021 21:42:39 +0200
> Subject: [PATCH bpf-next]
>   use correct format string specifier for unsigned 32 bounds

The above email header is not needed.

> 
> when printing an unsigned value, it should be a positive number

when -> "When"

to be precise, "a non-negative number".

> 
> verifier log before the patch
> ([...],s32_max_value=-2,u32_min_value=-16,u32_max_value=-2)
> 
> verifier log after the patch
> ([...],s32_max_value=-2,u32_min_value=4294967280,u32_max_value=4294967294)
> 
> 
> Fixes: 3f50f132d840 ("bpf: Verifier, do explicit ALU32 bounds tracking")
> Signed-off-by: Benedict Schlueter <benedict.schlueter@rub.de>
> ---
>   kernel/bpf/verifier.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 1de4b8c6ee42..ea482ebaeb26 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -690,12 +690,12 @@ static void print_verifier_state(struct 
> bpf_verifier_env *env,
>                           (int)(reg->s32_max_value));
>                   if (reg->u32_min_value != reg->umin_value &&
>                       reg->u32_min_value != U32_MIN)
> -                    verbose(env, ",u32_min_value=%d",
> -                        (int)(reg->u32_min_value));
> +                    verbose(env, ",u32_min_value=%u",
> +                        (unsigned int)(reg->u32_min_value));

There is no need to cast to "unsigned int", reg->u32_min_value is u32 type.

>                   if (reg->u32_max_value != reg->umax_value &&
>                       reg->u32_max_value != U32_MAX)
> -                    verbose(env, ",u32_max_value=%d",
> -                        (int)(reg->u32_max_value));
> +                    verbose(env, ",u32_max_value=%u",
> +                        (unsigned int)(reg->u32_max_value));

The same as above, no need to cast for reg->u32_max_value.

>               }
>               verbose(env, ")");
>           }
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1de4b8c6ee42..ea482ebaeb26 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -690,12 +690,12 @@  static void print_verifier_state(struct 
bpf_verifier_env *env,
                          (int)(reg->s32_max_value));
                  if (reg->u32_min_value != reg->umin_value &&
                      reg->u32_min_value != U32_MIN)
-                    verbose(env, ",u32_min_value=%d",
-                        (int)(reg->u32_min_value));
+                    verbose(env, ",u32_min_value=%u",
+                        (unsigned int)(reg->u32_min_value));
                  if (reg->u32_max_value != reg->umax_value &&
                      reg->u32_max_value != U32_MAX)
-                    verbose(env, ",u32_max_value=%d",
-                        (int)(reg->u32_max_value));
+                    verbose(env, ",u32_max_value=%u",
+                        (unsigned int)(reg->u32_max_value));
              }
              verbose(env, ")");