Skip to content

Commit 5098571

Browse files
committed
Refactored to ensure if udp payload is less than geneve header size packet will still be processed as non geneve udp packet
1 parent 9f073e0 commit 5098571

1 file changed

Lines changed: 34 additions & 37 deletions

File tree

src/zfw_tc_ingress.c

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,46 +1135,43 @@ static struct bpf_sock_tuple *get_tuple(struct __sk_buff *skb, __u64 nh_off,
11351135
/* read receive geneve version and header length */
11361136
__u8 *genhdr = NULL;
11371137
genhdr = (void *)(unsigned long)(skb->data + nh_off + sizeof(struct iphdr) + sizeof(struct udphdr));
1138-
if ((unsigned long)(genhdr + 1) > (unsigned long)skb->data_end){
1139-
event->error_code = GENEVE_HEADER_TOO_BIG;
1140-
send_event(event);
1141-
return NULL;
1142-
}
1143-
__u32 gen_ver = genhdr[0] & 0xC0 >> 6;
1144-
__u32 gen_hdr_len = genhdr[0] & 0x3F;
1145-
1146-
/* if the length is not equal to 32 bytes and version 0 */
1147-
if ((gen_hdr_len == AWS_GNV_HDR_OPT_LEN / 4) && (gen_ver == GENEVE_VER)){
1148-
/* Updating the skb to pop geneve header */
1149-
int ret = 0;
1150-
ret = bpf_skb_adjust_room(skb, -68, BPF_ADJ_ROOM_MAC, 0);
1151-
if (ret) {
1152-
event->error_code = SKB_ADJUST_ERROR;
1153-
send_event(event);
1154-
return NULL;
1155-
}
1156-
/* Initialize iph for after popping outer */
1157-
iph = (struct iphdr *)(skb->data + nh_off);
1158-
if((unsigned long)(iph + 1) > (unsigned long)skb->data_end){
1159-
event->error_code = IP_HEADER_TOO_BIG;
1160-
send_event(event);
1161-
return NULL;
1162-
}
1163-
unsigned char version = iph->version;
1164-
if(version == 6){
1165-
*ipv4 = false;
1166-
event->version = 6;
1167-
ip6h = (struct ipv6hdr *)(skb->data + nh_off);
1168-
/* ensure ip header is in packet bounds */
1169-
if ((unsigned long)(ip6h + 1) > (unsigned long)skb->data_end){
1170-
event->error_code = IP6_HEADER_TOO_BIG;
1138+
if ((unsigned long)(genhdr + 1) <= (unsigned long)skb->data_end){
1139+
__u32 gen_ver = genhdr[0] & 0xC0 >> 6;
1140+
__u32 gen_hdr_len = genhdr[0] & 0x3F;
1141+
1142+
/* if the length is not equal to 32 bytes and version 0 */
1143+
if ((gen_hdr_len == AWS_GNV_HDR_OPT_LEN / 4) && (gen_ver == GENEVE_VER)){
1144+
/* Updating the skb to pop geneve header */
1145+
int ret = 0;
1146+
ret = bpf_skb_adjust_room(skb, -68, BPF_ADJ_ROOM_MAC, 0);
1147+
if (ret) {
1148+
event->error_code = SKB_ADJUST_ERROR;
11711149
send_event(event);
11721150
return NULL;
11731151
}
1174-
*ipv6 = true;
1175-
proto = ip6h->nexthdr;
1176-
}else{
1177-
proto = iph->protocol;
1152+
/* Initialize iph for after popping outer */
1153+
iph = (struct iphdr *)(skb->data + nh_off);
1154+
if((unsigned long)(iph + 1) > (unsigned long)skb->data_end){
1155+
event->error_code = IP_HEADER_TOO_BIG;
1156+
send_event(event);
1157+
return NULL;
1158+
}
1159+
unsigned char version = iph->version;
1160+
if(version == 6){
1161+
*ipv4 = false;
1162+
event->version = 6;
1163+
ip6h = (struct ipv6hdr *)(skb->data + nh_off);
1164+
/* ensure ip header is in packet bounds */
1165+
if ((unsigned long)(ip6h + 1) > (unsigned long)skb->data_end){
1166+
event->error_code = IP6_HEADER_TOO_BIG;
1167+
send_event(event);
1168+
return NULL;
1169+
}
1170+
*ipv6 = true;
1171+
proto = ip6h->nexthdr;
1172+
}else{
1173+
proto = iph->protocol;
1174+
}
11781175
}
11791176
}
11801177

0 commit comments

Comments
 (0)