Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/bpf: Add verifier tests for 32bit pointer/scalar arithmetic

Added two test_verifier subtests for 32bit pointer/scalar arithmetic
with BPF_SUB operator. They are passing verifier now.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200618234632.3321367-1-yhs@fb.com

authored by

Yonghong Song and committed by
Daniel Borkmann
d56b74b9 6c693541

+38
+38
tools/testing/selftests/bpf/verifier/value_ptr_arith.c
··· 836 836 .errstr = "R0 invalid mem access 'inv'", 837 837 .errstr_unpriv = "R0 pointer -= pointer prohibited", 838 838 }, 839 + { 840 + "32bit pkt_ptr -= scalar", 841 + .insns = { 842 + BPF_LDX_MEM(BPF_W, BPF_REG_8, BPF_REG_1, 843 + offsetof(struct __sk_buff, data_end)), 844 + BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1, 845 + offsetof(struct __sk_buff, data)), 846 + BPF_MOV64_REG(BPF_REG_6, BPF_REG_7), 847 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 40), 848 + BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_8, 2), 849 + BPF_ALU32_REG(BPF_MOV, BPF_REG_4, BPF_REG_7), 850 + BPF_ALU32_REG(BPF_SUB, BPF_REG_6, BPF_REG_4), 851 + BPF_MOV64_IMM(BPF_REG_0, 0), 852 + BPF_EXIT_INSN(), 853 + }, 854 + .prog_type = BPF_PROG_TYPE_SCHED_CLS, 855 + .result = ACCEPT, 856 + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, 857 + }, 858 + { 859 + "32bit scalar -= pkt_ptr", 860 + .insns = { 861 + BPF_LDX_MEM(BPF_W, BPF_REG_8, BPF_REG_1, 862 + offsetof(struct __sk_buff, data_end)), 863 + BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1, 864 + offsetof(struct __sk_buff, data)), 865 + BPF_MOV64_REG(BPF_REG_6, BPF_REG_7), 866 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 40), 867 + BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_8, 2), 868 + BPF_ALU32_REG(BPF_MOV, BPF_REG_4, BPF_REG_6), 869 + BPF_ALU32_REG(BPF_SUB, BPF_REG_4, BPF_REG_7), 870 + BPF_MOV64_IMM(BPF_REG_0, 0), 871 + BPF_EXIT_INSN(), 872 + }, 873 + .prog_type = BPF_PROG_TYPE_SCHED_CLS, 874 + .result = ACCEPT, 875 + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, 876 + },