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

bpf: more SK_SKB selftests

Tests packet read/writes and additional skb fields.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

John Fastabend and committed by
David S. Miller
ed85054d 6fd28865

+98
+98
tools/testing/selftests/bpf/test_verifier.c
··· 1119 1119 .prog_type = BPF_PROG_TYPE_SK_SKB, 1120 1120 }, 1121 1121 { 1122 + "invalid access of tc_classid for SK_SKB", 1123 + .insns = { 1124 + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 1125 + offsetof(struct __sk_buff, tc_classid)), 1126 + BPF_EXIT_INSN(), 1127 + }, 1128 + .result = REJECT, 1129 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1130 + .errstr = "invalid bpf_context access", 1131 + }, 1132 + { 1133 + "check skb->mark is writeable by SK_SKB", 1134 + .insns = { 1135 + BPF_MOV64_IMM(BPF_REG_0, 0), 1136 + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 1137 + offsetof(struct __sk_buff, mark)), 1138 + BPF_EXIT_INSN(), 1139 + }, 1140 + .result = ACCEPT, 1141 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1142 + }, 1143 + { 1144 + "check skb->tc_index is writeable by SK_SKB", 1145 + .insns = { 1146 + BPF_MOV64_IMM(BPF_REG_0, 0), 1147 + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 1148 + offsetof(struct __sk_buff, tc_index)), 1149 + BPF_EXIT_INSN(), 1150 + }, 1151 + .result = ACCEPT, 1152 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1153 + }, 1154 + { 1155 + "check skb->priority is writeable by SK_SKB", 1156 + .insns = { 1157 + BPF_MOV64_IMM(BPF_REG_0, 0), 1158 + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 1159 + offsetof(struct __sk_buff, priority)), 1160 + BPF_EXIT_INSN(), 1161 + }, 1162 + .result = ACCEPT, 1163 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1164 + }, 1165 + { 1166 + "direct packet read for SK_SKB", 1167 + .insns = { 1168 + BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 1169 + offsetof(struct __sk_buff, data)), 1170 + BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, 1171 + offsetof(struct __sk_buff, data_end)), 1172 + BPF_MOV64_REG(BPF_REG_0, BPF_REG_2), 1173 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8), 1174 + BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1), 1175 + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0), 1176 + BPF_MOV64_IMM(BPF_REG_0, 0), 1177 + BPF_EXIT_INSN(), 1178 + }, 1179 + .result = ACCEPT, 1180 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1181 + }, 1182 + { 1183 + "direct packet write for SK_SKB", 1184 + .insns = { 1185 + BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 1186 + offsetof(struct __sk_buff, data)), 1187 + BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, 1188 + offsetof(struct __sk_buff, data_end)), 1189 + BPF_MOV64_REG(BPF_REG_0, BPF_REG_2), 1190 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8), 1191 + BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1), 1192 + BPF_STX_MEM(BPF_B, BPF_REG_2, BPF_REG_2, 0), 1193 + BPF_MOV64_IMM(BPF_REG_0, 0), 1194 + BPF_EXIT_INSN(), 1195 + }, 1196 + .result = ACCEPT, 1197 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1198 + }, 1199 + { 1200 + "overlapping checks for direct packet access SK_SKB", 1201 + .insns = { 1202 + BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 1203 + offsetof(struct __sk_buff, data)), 1204 + BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, 1205 + offsetof(struct __sk_buff, data_end)), 1206 + BPF_MOV64_REG(BPF_REG_0, BPF_REG_2), 1207 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8), 1208 + BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 4), 1209 + BPF_MOV64_REG(BPF_REG_1, BPF_REG_2), 1210 + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 6), 1211 + BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1), 1212 + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_2, 6), 1213 + BPF_MOV64_IMM(BPF_REG_0, 0), 1214 + BPF_EXIT_INSN(), 1215 + }, 1216 + .result = ACCEPT, 1217 + .prog_type = BPF_PROG_TYPE_SK_SKB, 1218 + }, 1219 + { 1122 1220 "check skb->mark is not writeable by sockets", 1123 1221 .insns = { 1124 1222 BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_1,