aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/testing/selftests/bpf/test_align.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/tools/testing/selftests/bpf/test_align.c b/tools/testing/selftests/bpf/test_align.c
index e19b410125eb..ff8bd7e3e50c 100644
--- a/tools/testing/selftests/bpf/test_align.c
+++ b/tools/testing/selftests/bpf/test_align.c
@@ -446,11 +446,9 @@ static struct bpf_align_test tests[] = {
446 .insns = { 446 .insns = {
447 PREP_PKT_POINTERS, 447 PREP_PKT_POINTERS,
448 BPF_MOV64_IMM(BPF_REG_0, 0), 448 BPF_MOV64_IMM(BPF_REG_0, 0),
449 /* ptr & const => unknown & const */ 449 /* (ptr - ptr) << 2 */
450 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2), 450 BPF_MOV64_REG(BPF_REG_5, BPF_REG_3),
451 BPF_ALU64_IMM(BPF_AND, BPF_REG_5, 0x40), 451 BPF_ALU64_REG(BPF_SUB, BPF_REG_5, BPF_REG_2),
452 /* ptr << const => unknown << const */
453 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
454 BPF_ALU64_IMM(BPF_LSH, BPF_REG_5, 2), 452 BPF_ALU64_IMM(BPF_LSH, BPF_REG_5, 2),
455 /* We have a (4n) value. Let's make a packet offset 453 /* We have a (4n) value. Let's make a packet offset
456 * out of it. First add 14, to make it a (4n+2) 454 * out of it. First add 14, to make it a (4n+2)
@@ -473,8 +471,26 @@ static struct bpf_align_test tests[] = {
473 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 471 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
474 .result = REJECT, 472 .result = REJECT,
475 .matches = { 473 .matches = {
476 {4, "R5_w=pkt(id=0,off=0,r=0,imm=0)"}, 474 {4, "R5_w=pkt_end(id=0,off=0,imm=0)"},
477 /* R5 bitwise operator &= on pointer prohibited */ 475 /* (ptr - ptr) << 2 == unknown, (4n) */
476 {6, "R5_w=inv(id=0,smax_value=9223372036854775804,umax_value=18446744073709551612,var_off=(0x0; 0xfffffffffffffffc))"},
477 /* (4n) + 14 == (4n+2). We blow our bounds, because
478 * the add could overflow.
479 */
480 {7, "R5=inv(id=0,var_off=(0x2; 0xfffffffffffffffc))"},
481 /* Checked s>=0 */
482 {9, "R5=inv(id=0,umin_value=2,umax_value=9223372036854775806,var_off=(0x2; 0x7ffffffffffffffc))"},
483 /* packet pointer + nonnegative (4n+2) */
484 {11, "R6_w=pkt(id=1,off=0,r=0,umin_value=2,umax_value=9223372036854775806,var_off=(0x2; 0x7ffffffffffffffc))"},
485 {13, "R4=pkt(id=1,off=4,r=0,umin_value=2,umax_value=9223372036854775806,var_off=(0x2; 0x7ffffffffffffffc))"},
486 /* NET_IP_ALIGN + (4n+2) == (4n), alignment is fine.
487 * We checked the bounds, but it might have been able
488 * to overflow if the packet pointer started in the
489 * upper half of the address space.
490 * So we did not get a 'range' on R6, and the access
491 * attempt will fail.
492 */
493 {15, "R6=pkt(id=1,off=0,r=0,umin_value=2,umax_value=9223372036854775806,var_off=(0x2; 0x7ffffffffffffffc))"},
478 } 494 }
479 }, 495 },
480 { 496 {