inet: defrag: drop non-last frags smaller than min mtu
Subsystems (4)
Florian Westphal
maintainerPATCH 1/1 inet: defrag: drop non-last frags smaller than min mtu
don't bother with pathological cases, they only waste cycles. IPv6 requires a minimum MTU of 1280 so we should never see fragments smaller than this (except last frag).
For IPv4, in practice, we could probably also adopt a higher limit, but for now use ipv4 min mtu (68).
--- net/ipv4/ip_fragment.c | 5 +++++ net/ipv6/netfilter/nf_conntrack_reasm.c | 4 ++++ net/ipv6/reassembly.c | 4 ++++ 3 files changed, 13 insertions(+)
net/ipv4/ip_fragment.c +5 -0
@@ -605,6 +605,10 @@ int ip_defrag(struct net *net, struct sk_buff *skb, u32 user)int vif =l3mdev_master_ifindex_rcu (dev);struct ipq *qp; +if (-skb_network_offset (skb) + skb->len <IPV4_MIN_MTU && +ip_hdr (skb)->frag_off &htons (IP_MF )) + goto drop; +__IP_INC_STATS (net,IPSTATS_MIB_REASMREQDS );skb_orphan (skb);
@@ -622,6 +626,7 @@ int ip_defrag(struct net *net, struct sk_buff *skb, u32 user)return ret; } +drop:__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS );kfree_skb (skb);return -ENOMEM ;
net/ipv6/netfilter/nf_conntrack_reasm.c +4 -0
@@ -557,6 +557,10 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user) hdr =ipv6_hdr (skb); fhdr = (struct frag_hdr *)skb_transport_header (skb); +if (-skb_network_offset (skb) + skb->len <IPV6_MIN_MTU && + fhdr->frag_off &htons (IP6_MF )) +return -EINVAL ; +skb_orphan (skb); fq =fq_find (net, fhdr->identification, user, hdr, skb->dev ? skb->dev->ifindex :0 );
net/ipv6/reassembly.c +4 -0
@@ -455,6 +455,10 @@ static int ipv6_frag_rcv(struct sk_buff *skb)return 1 ; } +if (-skb_network_offset (skb) + skb->len <IPV6_MIN_MTU && + fhdr->frag_off &htons (IP6_MF )) + goto fail_hdr; + iif = skb->dev ? skb->dev->ifindex :0 ; fq =fq_find (net, fhdr->identification, hdr, iif);if (fq) {
Signature · 1 line
2.16.4
Quoted 6 lines · Florian Westphal
don't bother with pathological cases, they only waste cycles. IPv6 requires a minimum MTU of 1280 so we should never see fragments smaller than this (except last frag).
For IPv4, in practice, we could probably also adopt a higher limit, but for now use ipv4 min mtu (68).
...
net/ipv4/ip_fragment.c int ip_defrag(struct net *net, struct sk_buff *skb, u32 user) · line 611
Quoted 5 lines
net/ipv4/ip_fragment.c +4
-0+if (-skb_network_offset (skb) + skb->len <IPV4_MIN_MTU && +ip_hdr (skb)->frag_off &htons (IP_MF )) + goto drop; +
I am not totally sure this is legit for IPv4.
Some intermediate nodes can try to be smart and could decide to further split fragments.
I am pretty sure I have seen this behavior on some radio environments :/
Eventually we could add a sysctl to allow an admin to set the threshold ?