Skip to content

[connection-limit] XDP program assumes IPv4 and does not handle IPv6 packets #114

@alwaysanimesh

Description

@alwaysanimesh

Source code: eBPF-Package-Repository/connection-limit/connection_limit.bpf.c

Description:
While reviewing the XDP program (_xdp_limit_conn), I noticed that the code directly parses the packet as an IPv4 header without checking the Ethernet protocol type. This can lead to misparsing non-IPv4 packets.

    /* Check if its valid ethernet packet */
    if (data + sizeof(struct ethhdr)+ 1 > data_end)
        return XDP_PASS;

    /* Check if its valid ip packet */
    struct iphdr *iph = (struct iphdr *)(data + sizeof(struct ethhdr));

There is no validation of eth->h_proto before this cast.

Question:

  1. Would it be appropriate to add an explicit EtherType check before parsing, for example:
if (ethhdr->h_proto != ETH_P_IP)
    return XDP_PASS;

to ensure that only IPv4 packets are interpreted as struct iphdr, and non-IPv4 are passed right away?

  1. Whether the program is designed to run in an environment where only IPv4 packets reach this stage

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions