Skip to content

Commit

Permalink
Fix overflow in immediate operand to 'and'
Browse files Browse the repository at this point in the history
ALU instructions take a signed 32-bit IMM.  Strictly speaking,
0xffffffff overflows it.  Switch to -1 to be safe.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Aug 28, 2023
1 parent 42f15d3 commit 362b93a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bpf/index.S
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* // perfect match any mismatches
* // == 0 != 0
* r0 |= (r0 >> 32); // == 0 != 0
* r0 &= 0xffffffff; // == 0 > 0
* r0 &= -1; // == 0 > 0
* r0 -= 1; // < 0 >= 0
* r0 >>= 63; // == 1 == 0
*
Expand Down Expand Up @@ -69,7 +69,7 @@ dt_index_match:
mov %r4, %r0
rsh %r4, 32
or %r0, %r4
and %r0, 0xffffffff
and %r0, -1
sub %r0, 1
rsh %r0, 63

Expand Down

0 comments on commit 362b93a

Please sign in to comment.