Skip to content

Commit

Permalink
bpf: Fix signed_{sub,add32}_overflows type handling
Browse files Browse the repository at this point in the history
Fix incorrect signed_{sub,add32}_overflows() input types (and a related buggy
comment). It looks like this might have slipped in via copy/paste issue, also
given prior to 3f50f13 ("bpf: Verifier, do explicit ALU32 bounds tracking")
the signature of signed_sub_overflows() had s64 a and s64 b as its input args
whereas now they are truncated to s32. Thus restore proper types. Also, the case
of signed_add32_overflows() is not consistent to signed_sub32_overflows(). Both
have s32 as inputs, therefore align the former.

Fixes: 3f50f13 ("bpf: Verifier, do explicit ALU32 bounds tracking")
Reported-by: De4dCr0w <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: John Fastabend <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
borkmann committed Jan 20, 2021
1 parent b425e24 commit bc895e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -5313,7 +5313,7 @@ static bool signed_add_overflows(s64 a, s64 b)
return res < a;
}

static bool signed_add32_overflows(s64 a, s64 b)
static bool signed_add32_overflows(s32 a, s32 b)
{
/* Do the add in u32, where overflow is well-defined */
s32 res = (s32)((u32)a + (u32)b);
Expand All @@ -5323,7 +5323,7 @@ static bool signed_add32_overflows(s64 a, s64 b)
return res < a;
}

static bool signed_sub_overflows(s32 a, s32 b)
static bool signed_sub_overflows(s64 a, s64 b)
{
/* Do the sub in u64, where overflow is well-defined */
s64 res = (s64)((u64)a - (u64)b);
Expand All @@ -5335,7 +5335,7 @@ static bool signed_sub_overflows(s32 a, s32 b)

static bool signed_sub32_overflows(s32 a, s32 b)
{
/* Do the sub in u64, where overflow is well-defined */
/* Do the sub in u32, where overflow is well-defined */
s32 res = (s32)((u32)a - (u32)b);

if (b < 0)
Expand Down

0 comments on commit bc895e8

Please sign in to comment.