From: Daniel Borkmann <daniel@iogearbox.net>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: bpf@vger.kernel.org, john.fastabend@gmail.com
Subject: Re: [bug report] bpf: Make 32->64 bounds propagation slightly more robust
Date: Tue, 11 Jan 2022 14:48:29 +0100 [thread overview]
Message-ID: <1941b7b2-beb7-ff3f-ee55-70b5d4e028df@iogearbox.net> (raw)
In-Reply-To: <20220111082054.GA20305@kili>
On 1/11/22 9:20 AM, Dan Carpenter wrote:
> Hello Daniel Borkmann,
[+John]
> The patch e572ff80f05c: "bpf: Make 32->64 bounds propagation slightly
> more robust" from Dec 15, 2021, leads to the following Smatch static
> checker warning:
>
> kernel/bpf/verifier.c:1412 __reg32_bound_s64()
> warn: always true condition '(a <= (((~0) >> 1))) => (s32min-s32max <= s32max)'
>
> kernel/bpf/verifier.c
> 1410 static bool __reg32_bound_s64(s32 a)
> 1411 {
> 1412 return a >= 0 && a <= S32_MAX;
>
> Obviously an s32 is going to be <= S32_MAX
It's aligned with similar helpers such as __reg64_bound_u32() / __reg64_bound_s32() and
when discussing we went for leaving this explicitly documented in here (aside being true).
> 1413 }
> 1414
> 1415 static void __reg_assign_32_into_64(struct bpf_reg_state *reg)
> 1416 {
> 1417 reg->umin_value = reg->u32_min_value;
> 1418 reg->umax_value = reg->u32_max_value;
> 1419
> 1420 /* Attempt to pull 32-bit signed bounds into 64-bit bounds but must
> 1421 * be positive otherwise set to worse case bounds and refine later
> 1422 * from tnum.
> 1423 */
> 1424 if (__reg32_bound_s64(reg->s32_min_value) &&
> 1425 __reg32_bound_s64(reg->s32_max_value)) {
> 1426 reg->smin_value = reg->s32_min_value;
> 1427 reg->smax_value = reg->s32_max_value;
> 1428 } else {
> 1429 reg->smin_value = 0;
> 1430 reg->smax_value = U32_MAX;
>
> Should this be S32_MAX instead of U32_MAX?
U32_MAX is correct here.
> 1431 }
> 1432 }
>
> regards,
> dan carpenter
>
prev parent reply other threads:[~2022-01-11 13:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 8:20 [bug report] bpf: Make 32->64 bounds propagation slightly more robust Dan Carpenter
2022-01-11 13:48 ` Daniel Borkmann [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=1941b7b2-beb7-ff3f-ee55-70b5d4e028df@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=john.fastabend@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