@@ -5123,6 +5123,17 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5123
5123
}
5124
5124
}
5125
5125
5126
+ static const struct bpf_func_proto *
5127
+ flow_dissector_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
5128
+ {
5129
+ switch (func_id ) {
5130
+ case BPF_FUNC_skb_load_bytes :
5131
+ return & bpf_skb_load_bytes_proto ;
5132
+ default :
5133
+ return bpf_base_func_proto (func_id );
5134
+ }
5135
+ }
5136
+
5126
5137
static const struct bpf_func_proto *
5127
5138
lwt_out_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
5128
5139
{
@@ -5241,6 +5252,10 @@ static bool bpf_skb_is_valid_access(int off, int size, enum bpf_access_type type
5241
5252
if (size != size_default )
5242
5253
return false;
5243
5254
break ;
5255
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5256
+ if (size != sizeof (struct bpf_flow_keys * ))
5257
+ return false;
5258
+ break ;
5244
5259
default :
5245
5260
/* Only narrow read access allowed for now. */
5246
5261
if (type == BPF_WRITE ) {
@@ -5266,6 +5281,7 @@ static bool sk_filter_is_valid_access(int off, int size,
5266
5281
case bpf_ctx_range (struct __sk_buff , data ):
5267
5282
case bpf_ctx_range (struct __sk_buff , data_meta ):
5268
5283
case bpf_ctx_range (struct __sk_buff , data_end ):
5284
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5269
5285
case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
5270
5286
return false;
5271
5287
}
@@ -5291,6 +5307,7 @@ static bool lwt_is_valid_access(int off, int size,
5291
5307
case bpf_ctx_range (struct __sk_buff , tc_classid ):
5292
5308
case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
5293
5309
case bpf_ctx_range (struct __sk_buff , data_meta ):
5310
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5294
5311
return false;
5295
5312
}
5296
5313
@@ -5501,6 +5518,7 @@ static bool tc_cls_act_is_valid_access(int off, int size,
5501
5518
case bpf_ctx_range (struct __sk_buff , data_end ):
5502
5519
info -> reg_type = PTR_TO_PACKET_END ;
5503
5520
break ;
5521
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5504
5522
case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
5505
5523
return false;
5506
5524
}
@@ -5702,6 +5720,7 @@ static bool sk_skb_is_valid_access(int off, int size,
5702
5720
switch (off ) {
5703
5721
case bpf_ctx_range (struct __sk_buff , tc_classid ):
5704
5722
case bpf_ctx_range (struct __sk_buff , data_meta ):
5723
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5705
5724
return false;
5706
5725
}
5707
5726
@@ -5761,6 +5780,39 @@ static bool sk_msg_is_valid_access(int off, int size,
5761
5780
return true;
5762
5781
}
5763
5782
5783
+ static bool flow_dissector_is_valid_access (int off , int size ,
5784
+ enum bpf_access_type type ,
5785
+ const struct bpf_prog * prog ,
5786
+ struct bpf_insn_access_aux * info )
5787
+ {
5788
+ if (type == BPF_WRITE ) {
5789
+ switch (off ) {
5790
+ case bpf_ctx_range_till (struct __sk_buff , cb [0 ], cb [4 ]):
5791
+ break ;
5792
+ default :
5793
+ return false;
5794
+ }
5795
+ }
5796
+
5797
+ switch (off ) {
5798
+ case bpf_ctx_range (struct __sk_buff , data ):
5799
+ info -> reg_type = PTR_TO_PACKET ;
5800
+ break ;
5801
+ case bpf_ctx_range (struct __sk_buff , data_end ):
5802
+ info -> reg_type = PTR_TO_PACKET_END ;
5803
+ break ;
5804
+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5805
+ info -> reg_type = PTR_TO_FLOW_KEYS ;
5806
+ break ;
5807
+ case bpf_ctx_range (struct __sk_buff , tc_classid ):
5808
+ case bpf_ctx_range (struct __sk_buff , data_meta ):
5809
+ case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
5810
+ return false;
5811
+ }
5812
+
5813
+ return bpf_skb_is_valid_access (off , size , type , prog , info );
5814
+ }
5815
+
5764
5816
static u32 bpf_convert_ctx_access (enum bpf_access_type type ,
5765
5817
const struct bpf_insn * si ,
5766
5818
struct bpf_insn * insn_buf ,
@@ -6055,6 +6107,15 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
6055
6107
bpf_target_off (struct sock_common ,
6056
6108
skc_num , 2 , target_size ));
6057
6109
break ;
6110
+
6111
+ case offsetof(struct __sk_buff , flow_keys ):
6112
+ off = si -> off ;
6113
+ off -= offsetof(struct __sk_buff , flow_keys );
6114
+ off += offsetof(struct sk_buff , cb );
6115
+ off += offsetof(struct qdisc_skb_cb , flow_keys );
6116
+ * insn ++ = BPF_LDX_MEM (BPF_SIZEOF (void * ), si -> dst_reg ,
6117
+ si -> src_reg , off );
6118
+ break ;
6058
6119
}
6059
6120
6060
6121
return insn - insn_buf ;
@@ -7018,6 +7079,15 @@ const struct bpf_verifier_ops sk_msg_verifier_ops = {
7018
7079
const struct bpf_prog_ops sk_msg_prog_ops = {
7019
7080
};
7020
7081
7082
+ const struct bpf_verifier_ops flow_dissector_verifier_ops = {
7083
+ .get_func_proto = flow_dissector_func_proto ,
7084
+ .is_valid_access = flow_dissector_is_valid_access ,
7085
+ .convert_ctx_access = bpf_convert_ctx_access ,
7086
+ };
7087
+
7088
+ const struct bpf_prog_ops flow_dissector_prog_ops = {
7089
+ };
7090
+
7021
7091
int sk_detach_filter (struct sock * sk )
7022
7092
{
7023
7093
int ret = - ENOENT ;
0 commit comments