Skip to content

Commit 72a41f9

Browse files
committed
Merge branch 'ipv6-reply-icmp-error-if-fragment-doesn-t-contain-all-headers'
Hangbin Liu says: ==================== IPv6: reply ICMP error if fragment doesn't contain all headers When our Engineer run latest IPv6 Core Conformance test, test v6LC.1.3.6: First Fragment Doesn’t Contain All Headers[1] failed. The test purpose is to verify that the node (Linux for example) should properly process IPv6 packets that don’t include all the headers through the Upper-Layer header. Based on RFC 8200, Section 4.5 Fragment Header - If the first fragment does not include all headers through an Upper-Layer header, then that fragment should be discarded and an ICMP Parameter Problem, Code 3, message should be sent to the source of the fragment, with the Pointer field set to zero. The first patch add a definition for ICMPv6 Parameter Problem, code 3. The second patch add a check for the 1st fragment packet to make sure Upper-Layer header exist. [1] Page 68, v6LC.1.3.6: First Fragment Doesn’t Contain All Headers part A, B, C and D at https://ipv6ready.org/docs/Core_Conformance_5_0_0.pdf [2] My reproducer: import sys, os from scapy.all import * def send_frag_dst_opt(src_ip6, dst_ip6): ip6 = IPv6(src = src_ip6, dst = dst_ip6, nh = 44) frag_1 = IPv6ExtHdrFragment(nh = 60, m = 1) dst_opt = IPv6ExtHdrDestOpt(nh = 58) frag_2 = IPv6ExtHdrFragment(nh = 58, offset = 4, m = 1) icmp_echo = ICMPv6EchoRequest(seq = 1) pkt_1 = ip6/frag_1/dst_opt pkt_2 = ip6/frag_2/icmp_echo send(pkt_1) send(pkt_2) def send_frag_route_opt(src_ip6, dst_ip6): ip6 = IPv6(src = src_ip6, dst = dst_ip6, nh = 44) frag_1 = IPv6ExtHdrFragment(nh = 43, m = 1) route_opt = IPv6ExtHdrRouting(nh = 58) frag_2 = IPv6ExtHdrFragment(nh = 58, offset = 4, m = 1) icmp_echo = ICMPv6EchoRequest(seq = 2) pkt_1 = ip6/frag_1/route_opt pkt_2 = ip6/frag_2/icmp_echo send(pkt_1) send(pkt_2) if __name__ == '__main__': src = sys.argv[1] dst = sys.argv[2] conf.iface = sys.argv[3] send_frag_dst_opt(src, dst) send_frag_route_opt(src, dst) ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 2f71e00 + 2efdaaa commit 72a41f9

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

include/uapi/linux/icmpv6.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct icmp6hdr {
138138
#define ICMPV6_HDR_FIELD 0
139139
#define ICMPV6_UNK_NEXTHDR 1
140140
#define ICMPV6_UNK_OPTION 2
141+
#define ICMPV6_HDR_INCOMP 3
141142

142143
/*
143144
* constants for (set|get)sockopt

net/ipv6/icmp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ static bool is_ineligible(const struct sk_buff *skb)
158158
tp = skb_header_pointer(skb,
159159
ptr+offsetof(struct icmp6hdr, icmp6_type),
160160
sizeof(_type), &_type);
161-
if (!tp || !(*tp & ICMPV6_INFOMSG_MASK))
161+
162+
/* Based on RFC 8200, Section 4.5 Fragment Header, return
163+
* false if this is a fragment packet with no icmp header info.
164+
*/
165+
if (!tp && frag_off != 0)
166+
return false;
167+
else if (!tp || !(*tp & ICMPV6_INFOMSG_MASK))
162168
return true;
163169
}
164170
return false;

net/ipv6/reassembly.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <linux/skbuff.h>
4343
#include <linux/slab.h>
4444
#include <linux/export.h>
45+
#include <linux/tcp.h>
46+
#include <linux/udp.h>
4547

4648
#include <net/sock.h>
4749
#include <net/snmp.h>
@@ -322,7 +324,9 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
322324
struct frag_queue *fq;
323325
const struct ipv6hdr *hdr = ipv6_hdr(skb);
324326
struct net *net = dev_net(skb_dst(skb)->dev);
325-
int iif;
327+
__be16 frag_off;
328+
int iif, offset;
329+
u8 nexthdr;
326330

327331
if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
328332
goto fail_hdr;
@@ -351,6 +355,33 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
351355
return 1;
352356
}
353357

358+
/* RFC 8200, Section 4.5 Fragment Header:
359+
* If the first fragment does not include all headers through an
360+
* Upper-Layer header, then that fragment should be discarded and
361+
* an ICMP Parameter Problem, Code 3, message should be sent to
362+
* the source of the fragment, with the Pointer field set to zero.
363+
*/
364+
nexthdr = hdr->nexthdr;
365+
offset = ipv6_skip_exthdr(skb, skb_transport_offset(skb), &nexthdr, &frag_off);
366+
if (offset >= 0) {
367+
/* Check some common protocols' header */
368+
if (nexthdr == IPPROTO_TCP)
369+
offset += sizeof(struct tcphdr);
370+
else if (nexthdr == IPPROTO_UDP)
371+
offset += sizeof(struct udphdr);
372+
else if (nexthdr == IPPROTO_ICMPV6)
373+
offset += sizeof(struct icmp6hdr);
374+
else
375+
offset += 1;
376+
377+
if (!(frag_off & htons(IP6_OFFSET)) && offset > skb->len) {
378+
__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
379+
IPSTATS_MIB_INHDRERRORS);
380+
icmpv6_param_prob(skb, ICMPV6_HDR_INCOMP, 0);
381+
return -1;
382+
}
383+
}
384+
354385
iif = skb->dev ? skb->dev->ifindex : 0;
355386
fq = fq_find(net, fhdr->identification, hdr, iif);
356387
if (fq) {

0 commit comments

Comments
 (0)