@@ -1094,6 +1094,59 @@ static struct bpf_test tests[] = {
1094
1094
.errstr = "invalid bpf_context access" ,
1095
1095
.result = REJECT ,
1096
1096
},
1097
+ {
1098
+ "check skb->hash byte load permitted" ,
1099
+ .insns = {
1100
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1101
+ #ifdef __LITTLE_ENDIAN
1102
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1103
+ offsetof(struct __sk_buff , hash )),
1104
+ #else
1105
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1106
+ offsetof(struct __sk_buff , hash ) + 3 ),
1107
+ #endif
1108
+ BPF_EXIT_INSN (),
1109
+ },
1110
+ .result = ACCEPT ,
1111
+ },
1112
+ {
1113
+ "check skb->hash byte load not permitted 1" ,
1114
+ .insns = {
1115
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1116
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1117
+ offsetof(struct __sk_buff , hash ) + 1 ),
1118
+ BPF_EXIT_INSN (),
1119
+ },
1120
+ .errstr = "invalid bpf_context access" ,
1121
+ .result = REJECT ,
1122
+ },
1123
+ {
1124
+ "check skb->hash byte load not permitted 2" ,
1125
+ .insns = {
1126
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1127
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1128
+ offsetof(struct __sk_buff , hash ) + 2 ),
1129
+ BPF_EXIT_INSN (),
1130
+ },
1131
+ .errstr = "invalid bpf_context access" ,
1132
+ .result = REJECT ,
1133
+ },
1134
+ {
1135
+ "check skb->hash byte load not permitted 3" ,
1136
+ .insns = {
1137
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1138
+ #ifdef __LITTLE_ENDIAN
1139
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1140
+ offsetof(struct __sk_buff , hash ) + 3 ),
1141
+ #else
1142
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
1143
+ offsetof(struct __sk_buff , hash )),
1144
+ #endif
1145
+ BPF_EXIT_INSN (),
1146
+ },
1147
+ .errstr = "invalid bpf_context access" ,
1148
+ .result = REJECT ,
1149
+ },
1097
1150
{
1098
1151
"check cb access: byte, wrong type" ,
1099
1152
.insns = {
@@ -1187,6 +1240,37 @@ static struct bpf_test tests[] = {
1187
1240
.errstr = "invalid bpf_context access" ,
1188
1241
.result = REJECT ,
1189
1242
},
1243
+ {
1244
+ "check skb->hash half load permitted" ,
1245
+ .insns = {
1246
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1247
+ #ifdef __LITTLE_ENDIAN
1248
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
1249
+ offsetof(struct __sk_buff , hash )),
1250
+ #else
1251
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
1252
+ offsetof(struct __sk_buff , hash ) + 2 ),
1253
+ #endif
1254
+ BPF_EXIT_INSN (),
1255
+ },
1256
+ .result = ACCEPT ,
1257
+ },
1258
+ {
1259
+ "check skb->hash half load not permitted" ,
1260
+ .insns = {
1261
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
1262
+ #ifdef __LITTLE_ENDIAN
1263
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
1264
+ offsetof(struct __sk_buff , hash ) + 2 ),
1265
+ #else
1266
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
1267
+ offsetof(struct __sk_buff , hash )),
1268
+ #endif
1269
+ BPF_EXIT_INSN (),
1270
+ },
1271
+ .errstr = "invalid bpf_context access" ,
1272
+ .result = REJECT ,
1273
+ },
1190
1274
{
1191
1275
"check cb access: half, wrong type" ,
1192
1276
.insns = {
@@ -5103,6 +5187,98 @@ static struct bpf_test tests[] = {
5103
5187
},
5104
5188
.result = ACCEPT ,
5105
5189
},
5190
+ {
5191
+ "check bpf_perf_event_data->sample_period byte load permitted" ,
5192
+ .insns = {
5193
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5194
+ #ifdef __LITTLE_ENDIAN
5195
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
5196
+ offsetof(struct bpf_perf_event_data , sample_period )),
5197
+ #else
5198
+ BPF_LDX_MEM (BPF_B , BPF_REG_0 , BPF_REG_1 ,
5199
+ offsetof(struct bpf_perf_event_data , sample_period ) + 7 ),
5200
+ #endif
5201
+ BPF_EXIT_INSN (),
5202
+ },
5203
+ .result = ACCEPT ,
5204
+ .prog_type = BPF_PROG_TYPE_PERF_EVENT ,
5205
+ },
5206
+ {
5207
+ "check bpf_perf_event_data->sample_period half load permitted" ,
5208
+ .insns = {
5209
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5210
+ #ifdef __LITTLE_ENDIAN
5211
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5212
+ offsetof(struct bpf_perf_event_data , sample_period )),
5213
+ #else
5214
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5215
+ offsetof(struct bpf_perf_event_data , sample_period ) + 6 ),
5216
+ #endif
5217
+ BPF_EXIT_INSN (),
5218
+ },
5219
+ .result = ACCEPT ,
5220
+ .prog_type = BPF_PROG_TYPE_PERF_EVENT ,
5221
+ },
5222
+ {
5223
+ "check bpf_perf_event_data->sample_period word load permitted" ,
5224
+ .insns = {
5225
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5226
+ #ifdef __LITTLE_ENDIAN
5227
+ BPF_LDX_MEM (BPF_W , BPF_REG_0 , BPF_REG_1 ,
5228
+ offsetof(struct bpf_perf_event_data , sample_period )),
5229
+ #else
5230
+ BPF_LDX_MEM (BPF_W , BPF_REG_0 , BPF_REG_1 ,
5231
+ offsetof(struct bpf_perf_event_data , sample_period ) + 4 ),
5232
+ #endif
5233
+ BPF_EXIT_INSN (),
5234
+ },
5235
+ .result = ACCEPT ,
5236
+ .prog_type = BPF_PROG_TYPE_PERF_EVENT ,
5237
+ },
5238
+ {
5239
+ "check bpf_perf_event_data->sample_period dword load permitted" ,
5240
+ .insns = {
5241
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5242
+ BPF_LDX_MEM (BPF_DW , BPF_REG_0 , BPF_REG_1 ,
5243
+ offsetof(struct bpf_perf_event_data , sample_period )),
5244
+ BPF_EXIT_INSN (),
5245
+ },
5246
+ .result = ACCEPT ,
5247
+ .prog_type = BPF_PROG_TYPE_PERF_EVENT ,
5248
+ },
5249
+ {
5250
+ "check skb->data half load not permitted" ,
5251
+ .insns = {
5252
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5253
+ #ifdef __LITTLE_ENDIAN
5254
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5255
+ offsetof(struct __sk_buff , data )),
5256
+ #else
5257
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5258
+ offsetof(struct __sk_buff , data ) + 2 ),
5259
+ #endif
5260
+ BPF_EXIT_INSN (),
5261
+ },
5262
+ .result = REJECT ,
5263
+ .errstr = "invalid bpf_context access" ,
5264
+ },
5265
+ {
5266
+ "check skb->tc_classid half load not permitted for lwt prog" ,
5267
+ .insns = {
5268
+ BPF_MOV64_IMM (BPF_REG_0 , 0 ),
5269
+ #ifdef __LITTLE_ENDIAN
5270
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5271
+ offsetof(struct __sk_buff , tc_classid )),
5272
+ #else
5273
+ BPF_LDX_MEM (BPF_H , BPF_REG_0 , BPF_REG_1 ,
5274
+ offsetof(struct __sk_buff , tc_classid ) + 2 ),
5275
+ #endif
5276
+ BPF_EXIT_INSN (),
5277
+ },
5278
+ .result = REJECT ,
5279
+ .errstr = "invalid bpf_context access" ,
5280
+ .prog_type = BPF_PROG_TYPE_LWT_IN ,
5281
+ },
5106
5282
};
5107
5283
5108
5284
static int probe_filter_length (const struct bpf_insn * fp )
0 commit comments