ipv6: Address ext hdr DoS vulnerabilities
Subsystems (6)
v10 cover ipv6: Address ext hdr DoS vulnerabilities
IPv6 extension headers are defined to be quite open ended with few limits. For instance, RFC8200 requires a receiver to process any number of extension headers in a packet in any order. This flexibility comes at the cost of a potential Denial of Service attack. The only thing that might mitigate the DoS attacks is the fact that packets with extension headers experience high drop rates on the Internet so that a DoS attack based on extension wouldn't be very effective at Internet scale.
This patch set addresses some of the more egregious vulnerabilities of extension headers to DoS attack.
- If sysctl.max_dst_opts_cnt or hbh_opts_cnt are set to 0 then that disallows packets with Destination Options or Hop-by-Hop Options even if the packet contain zero non-padding options
- Add a case for IPV6_TLV_TNL_ENCAP_LIMIT in the switch on TLV type in ip6_parse_tlv function. This TLV is handled in tunnel processing, however it needs to be detected in ip6_parse_tlv to properly account for it as recognized non-padding option
- Move IPV6_TLV_TNL_ENCAP_LIMIT to uapi/linux/in6.h so that all the TLV definitions are in one place
- Set the default limits of non-padding Hop-by-Hop and Destination options to 2. This means that if a packet contains more then two non-padding options then it will be dropped. The previous limit was 8, but that was too liberal considering that the stack only support two Destination Options and the most Hop-by-Hop options likely to ever be in the same packet are IOAM and JUMBO. The limit can be increased via sysctl for private use and experimentation
- Enforce RFC8200 recommended ordering of Extension Headers. This also enforces that any Extension Header occurs at most once in a packet except for Destination Options that may appear twice. The enforce_ext_hdr_order sysctl controls enforcement. If it's set to true then order is enforced, if it's set to false then neither order nor number of occurrences are enforced.
The enforced ordering is:
IPv6 header
Hop-by-Hop Options header
Destination Options before the Routing header
Routing header
Fragment header
Authentication header
Encapsulating Security Payload header
Destination Options header
Upper-Layer header
--- Background
We selected the default value of eight in RFC8504 based on an expectation that there might be new options defined and that the Internet would be fixed to reliably support extension headers including those with options. I do not believe either of those are going to happen.
Hop-by-Hop Options are ostensibly the right way to do network to host and host to network signaling.The only HBH options that might get any substantial deployment are Router Alert option and IOAM. The Router Alert option is being deprecated and IOAM is at best a "nice to have". The best use case of Hop-by-Hop options is congestion signaling, unfortunately the die was cast when CSIG authors decided to place the information in VLANs at L2 and cajole the information to be routable through a switch. IMO, the miss on CSIG pretty much is the nail in the coffin for Hop-by-Hop options to ever be widely deployed
(https://www.ietf.org/archive/id/draft-ravi-ippm-csig-01.txt).
Destination Options have proven even less useful than Hop-by-Hop Options. The only Destination Options supported by the stack is the Tunnel Encap Limit option and Home Address Options. The Tunnel Encap Option was buried in the v6 tunnel code which is why it wasn't obvious it was supported in the first version of the patch set. I'll assume that might be useful, so this patch set cleans up the code for it. I don't believe there's any use of Home Address Option.
A major problem with DestOpts, HBH, Routing Header, and Fragment header is that they have no inherent security. Their use presents a security risk especially when sent over untrusted networks including the Internet. Given that and that the high drop rates of extension headers on the Internet, I am proposing that Extension header except for ESP being deprecated on the Internet
(https://www.ietf.org/archive/id/draft-herbert-deprecate-eh-01.txt).
An update to RFC8200 is being proposed in IETF to allow enforcement of extension header ordering and number of occurences. An I-D is in
https://www.ietf.org/archive/id/draft-iurman-6man-eh-occurrences-00.txt
--- Testing
Add selftest eh_limits.sh. Tested by running:
$ sudo ./eh_limits.sh
TEST: EH-limits - default sysctls [ OK ]
TEST: EH-limits - modified sysctls [ OK ]Tests passed: 2 Tests failed: 0
$ sudo ./eh_limits.sh -v
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Default
TEST: Two non-padding options in HBH and DestOpts: Received as expected
TEST: Big destination option: Received as expected
TEST: Almost Big HBH option: Received as expected
TEST: Big HBH option: Received as expected
TEST: Too much HBH padding: Didn't receive as expected
TEST: Too much DestOpt padding: Didn't receive as expected
TEST: Too much DestOpt padding #2: Didn't receive as expected
TEST: Too much DestOpt padding #3: Didn't receive as expected
TEST: Almost too much DestOpt padding #2: Received as expected
TEST: Two Dest Ops: Didn't receive as expected
TEST: OOO Routing header: Didn't receive as expected
TEST: Two Routing headers: Didn't receive as expected
TEST: Two Destination options okay: Received as expected
TEST: Two Destination options: Didn't receive as expected
TEST: Two Destination options after RH: Didn't receive as expected
TEST: Many EH OOO: Didn't receive as expected
TEST: Two fragment Headers: Didn't receive as expected
TEST: EH-limits - default sysctls [ OK ]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
No order enforce, 8 options, 66 length limit
TEST: Two non-padding options in HBH and DestOpts: Received as expected
TEST: Big destination option: Didn't receive as expected
TEST: Almost Big HBH option: Received as expected
TEST: Big HBH option: Didn't receive as expected
TEST: Too much HBH padding: Didn't receive as expected
TEST: Too much DestOpt padding: Didn't receive as expected
TEST: Too much DestOpt padding #2: Didn't receive as expected
TEST: Too much DestOpt padding #3: Didn't receive as expected
TEST: Almost too much DestOpt padding #2: Received as expected
TEST: Two Dest Ops: Received as expected
TEST: OOO Routing header: Received as expected
TEST: Two Routing headers: Received as expected
TEST: Two Destination options okay: Received as expected
TEST: Two Destination options: Received as expected
TEST: Two Destination options after RH: Received as expected
TEST: Many EH OOO: Received as expected
TEST: Two fragment Headers: Didn't receive as expected
TEST: EH-limits - modified sysctls [ OK ]
Tests passed: 2 Tests failed: 0
V4: Switch order of patches to avoid transient build failure
V5: Allow Destination Options before the Routing header, fixes
suggested by Justin Iurman
v6: Fix a bug and create a test for extension header limits
v7: Run pylint on new Python file, run shellcheck on new bash file,
Make fixes as needed
v8: Repost
v9: Fix subject prefix
v10: Lint fixes in selftest scripts suggested by Simon Horman
Tom Herbert (10):
ipv6: Check of max HBH or DestOp sysctl is zero and drop if it is
ipv6: Cleanup IPv6 TLV definitions
ipv6: Add case for IPV6_TLV_TNL_ENCAP_LIMIT in EH TLV switch
ipv6: Set HBH and DestOpt limits to 2
ipv6: Document defaults for max_{dst|hbh}_opts_number sysctls
ipv6: Enforce Extension Header ordering
ipv6: Document enforce_ext_hdr_order sysctl
test: Add proto_nums.py in networking selftests
test: Add ext_hdr.py in networking selftests
test: Add networking selftest for eh limits
Documentation/networking/ip-sysctl.rst | 52 ++- include/net/ipv6.h | 9 +- include/net/netns/ipv6.h | 1 + include/net/protocol.h | 14 + include/uapi/linux/in6.h | 21 +- include/uapi/linux/ip6_tunnel.h | 1 - net/ipv6/af_inet6.c | 1 + net/ipv6/exthdrs.c | 32 +- net/ipv6/ip6_input.c | 42 +++ net/ipv6/reassembly.c | 1 + net/ipv6/sysctl_net_ipv6.c | 7 + net/ipv6/xfrm6_protocol.c | 2 + tools/testing/selftests/net/Makefile | 4 + tools/testing/selftests/net/eh_limits.py | 349 ++++++++++++++++++++ tools/testing/selftests/net/eh_limits.sh | 210 ++++++++++++ tools/testing/selftests/net/ext_hdr.py | 385 ++++++++++++++++++++++ tools/testing/selftests/net/proto_nums.py | 231 +++++++++++++ 17 files changed, 1334 insertions(+), 28 deletions(-) create mode 100755 tools/testing/selftests/net/eh_limits.py create mode 100755 tools/testing/selftests/net/eh_limits.sh create mode 100755 tools/testing/selftests/net/ext_hdr.py create mode 100644 tools/testing/selftests/net/proto_nums.py
Signature · 1 line
2.43.0
PATCH v10 1/10 ipv6: Check of max HBH or DestOp sysctl is zero and drop if it is
From: Tom Herbert <[email protected]>
In IPv6 Destination options processing function check if net->ipv6.sysctl.max_dst_opts_cnt is zero up front. If it is zero then drop the packet since Destination Options processing is disabled.
Similarly, in IPv6 hop-by-hop options processing function check if net->ipv6.sysctl.max_hbh_opts_cnt is zero up front. If it is zero then drop the packet since Hop-by-Hop Options processing is disabled.
--- net/ipv6/exthdrs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
net/ipv6/exthdrs.c +10 -8
@@ -301,9 +301,11 @@ static int ipv6_destopt_rcv(struct sk_buff *skb)#endif struct dst_entry *dst =skb_dst (skb);struct net *net =dev_net (skb->dev); -int extlen; +int extlen, max_opts_cnt; -if (!pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || + max_opts_cnt =READ_ONCE (net->ipv6.sysctl.max_dst_opts_cnt); +if (!max_opts_cnt || + !pskb_may_pull (skb,skb_transport_offset (skb) +8 ) || !pskb_may_pull (skb, (skb_transport_offset (skb) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { __IP6_INC_STATS(dev_net(dst_dev(dst)), idev,
@@ -322,8 +324,7 @@ static int ipv6_destopt_rcv(struct sk_buff *skb) dstbuf = opt->dst1;#endif -if (ip6_parse_tlv (false, skb, -READ_ONCE (net->ipv6.sysctl.max_dst_opts_cnt))) { +if (ip6_parse_tlv (false, skb, max_opts_cnt)) { skb->transport_header += extlen; opt =IP6CB (skb);#if IS_ENABLED (CONFIG_IPV6_MIP6 )
@@ -1045,7 +1046,7 @@ int ipv6_parse_hopopts(struct sk_buff *skb) {struct inet6_skb_parm *opt =IP6CB (skb);struct net *net =dev_net (skb->dev); -int extlen; +int extlen, max_opts_cnt;/* * skb_network_header(skb) is equal to skb->data, and
@@ -1053,7 +1054,9 @@ int ipv6_parse_hopopts(struct sk_buff *skb)* sizeof(struct ipv6hdr) by definition of * hop-by-hop options. */ -if (!pskb_may_pull (skb,sizeof (struct ipv6hdr ) +8 ) || + max_opts_cnt =READ_ONCE (net->ipv6.sysctl.max_hbh_opts_cnt); +if (!max_opts_cnt || + !pskb_may_pull (skb,sizeof (struct ipv6hdr ) +8 ) || !pskb_may_pull (skb, (sizeof (struct ipv6hdr ) + ((skb_transport_header (skb)[1 ] +1 ) <<3 )))) { fail_and_free:
@@ -1066,8 +1069,7 @@ int ipv6_parse_hopopts(struct sk_buff *skb) goto fail_and_free; opt->flags |=IP6SKB_HOPBYHOP ; -if (ip6_parse_tlv (true, skb, -READ_ONCE (net->ipv6.sysctl.max_hbh_opts_cnt))) { +if (ip6_parse_tlv (true, skb, max_opts_cnt)) { skb->transport_header += extlen; opt =IP6CB (skb); opt->nhoff =sizeof (struct ipv6hdr );
Signature · 1 line
2.43.0
PATCH v10 2/10 ipv6: Cleanup IPv6 TLV definitions
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Move IPV6_TLV_TNL_ENCAP_LIMIT to uapi/linux/in6.h to be with the rest of the TLV definitions. Label each of the TLV definitions as to whether they are a Hop-by-Hop option, Destination option, or both.
--- include/uapi/linux/in6.h | 21 ++++++++++++++------- include/uapi/linux/ip6_tunnel.h | 1 - 2 files changed, 14 insertions(+), 8 deletions(-)
include/uapi/linux/in6.h +14 -7
@@ -140,14 +140,21 @@ struct in6_flowlabel_req {/* * IPv6 TLV options. +* +* Hop-by-Hop and Destination options share the same number space. +* For each option below whether it is a Hop-by-Hop option or +* a Destination option is indicated by HBH or DestOpt. */ -#define IPV6_TLV_PAD1 0 -#define IPV6_TLV_PADN 1 -#define IPV6_TLV_ROUTERALERT 5 -#define IPV6_TLV_CALIPSO 7/* RFC 5570 */ -#define IPV6_TLV_IOAM 49/* RFC 9486 */ -#define IPV6_TLV_JUMBO 194 -#define IPV6_TLV_HAO 201/* home address option */ +#define IPV6_TLV_PAD1 0/* HBH or DestOpt */ +#define IPV6_TLV_PADN 1/* HBH or DestOpt */ +#define IPV6_TLV_TNL_ENCAP_LIMIT 4/* RFC 2473, DestOpt */ +#define IPV6_TLV_ROUTERALERT 5/* HBH */ +#define IPV6_TLV_CALIPSO 7/* RFC 5570, HBH */ +#define IPV6_TLV_IOAM 49/* RFC 9486, HBH or Destopt +* IOAM sent and rcvd as HBH +*/ +#define IPV6_TLV_JUMBO 194/* HBH */ +#define IPV6_TLV_HAO 201/* home address option, DestOpt */ /* * IPV6 socket options
include/uapi/linux/ip6_tunnel.h +0 -1
@@ -6,7 +6,6 @@#include <linux/if.h> /* For IFNAMSIZ. */ #include <linux/in6.h> /* For struct in6_addr. */ -#define IPV6_TLV_TNL_ENCAP_LIMIT 4#define IPV6_DEFAULT_TNL_ENCAP_LIMIT 4/* don't add encapsulation limit if one isn't present in inner packet */
Signature · 1 line
2.43.0
PATCH v10 3/10 ipv6: Add case for IPV6_TLV_TNL_ENCAP_LIMIT in EH TLV switch
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
IPV6_TLV_TNL_ENCAP_LIMIT is a recognized Destination option that is processed in ip6_tunnel.c. Add a case for it in the switch in ip6_parse_tlv so that it is recognized as a known option.
Also remove the unlikely around the check for max_count < 0 since the default limits for HBH and Destination options can be less than zero.
--- net/ipv6/exthdrs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/ipv6/exthdrs.c +11 -1
@@ -122,7 +122,7 @@ static bool ip6_parse_tlv(bool hopbyhop,int tlv_count =0 ;int padlen =0 ; -if (unlikely (max_count <0 )) { +if (max_count <0 ) { disallow_unknowns = true; max_count = -max_count; }
@@ -202,6 +202,16 @@ static bool ip6_parse_tlv(bool hopbyhop,if (!ipv6_dest_hao (skb, off))return false;break ; +#endif +#if IS_ENABLED (CONFIG_IPV6_TUNNEL ) +case IPV6_TLV_TNL_ENCAP_LIMIT : +/* The tunnel encapsulation option. +* This is handled in ip6_tunnel.c so +* we don't need to do anything here +* except to accept it as a recognized +* option +*/ +break ;#endif default : if (!ip6_tlvopt_unknown(skb, off,
Signature · 1 line
2.43.0
PATCH v10 4/10 ipv6: Set HBH and DestOpt limits to 2
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Set the default limits of non-padding Hop-by-Hop and Destination options to 2. This means that if a packet contains more than two non-padding options then it will be dropped. The previous limit was 8, but that was too liberal considering that the stack only support two Destination Options and the most Hop-by-Hop options likely to ever be in the same packet are IOAM and JUMBO. The limit can be increased via sysctl for private use and experimentation.
--- include/net/ipv6.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
include/net/ipv6.h +6 -3
@@ -84,9 +84,12 @@ struct ip_tunnel_info;* silently discarded. */ -/* Default limits for Hop-by-Hop and Destination options */ -#define IP6_DEFAULT_MAX_DST_OPTS_CNT 8 -#define IP6_DEFAULT_MAX_HBH_OPTS_CNT 8 +/* Default limits for Hop-by-Hop and Destination non-padding options. The +* default value for both is 2. This sets a limit at two non-padding options +* (see sysctl documentation) +*/ +#define IP6_DEFAULT_MAX_DST_OPTS_CNT 2 +#define IP6_DEFAULT_MAX_HBH_OPTS_CNT 2#define IP6_DEFAULT_MAX_DST_OPTS_LEN INT_MAX/* No limit */ #define IP6_DEFAULT_MAX_HBH_OPTS_LEN INT_MAX/* No limit */
Signature · 1 line
2.43.0
PATCH v10 5/10 ipv6: Document defaults for max_{dst|hbh}_opts_number sysctls
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
In the descriptions of max_dst_opts_number and max_hbh_opts_number sysctls add text about how a zero setting means that a packet with any Destination or Hop-by-Hop options is dropped.
Report the defaults for max_dst_opts_number and max_hbh_opts_number are 2 which means up to two options may be accepted.
--- Documentation/networking/ip-sysctl.rst | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
Documentation/networking/ip-sysctl.rst +14 -8
@@ -2511,19 +2511,25 @@ mld_qrv - INTEGER max_dst_opts_number - INTEGER Maximum number of non-padding TLVs allowed in a Destination - options extension header. If this value is less than zero - then unknown options are disallowed and the number of known - TLVs allowed is the absolute value of this number. + options extension header. If this value is zero then receive + Destination Options processing is disabled in which case packets + with the Destination Options extension header are dropped. If + this value is less than zero then unknown options are disallowed + and the number of known TLVs allowed is the absolute value of + this number. - Default: 8 + Default: 2 max_hbh_opts_number - INTEGER Maximum number of non-padding TLVs allowed in a Hop-by-Hop - options extension header. If this value is less than zero - then unknown options are disallowed and the number of known - TLVs allowed is the absolute value of this number. + options extension header. If this value is zero then receive + Hop-by-Hop Options processing is disabled in which case packets + with the Hop-by-Hop Options extension header are dropped. + If this value is less than zero then unknown options are disallowed + and the number of known TLVs allowed is the absolute value of this + number. - Default: 8 + Default: 2 max_dst_opts_length - INTEGER Maximum length allowed for a Destination options extension
Signature · 1 line
2.43.0
PATCH v10 6/10 ipv6: Enforce Extension Header ordering
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
RFC8200 highly recommends that different Extension Headers be sent in a prescribed order and all Extension Header types occur at most once in a packet with the exception of Destination Options that may occur twice. This patch enforces the ordering be followed in received packets.
The allowed order of Extension Headers is:
IPv6 header
Hop-by-Hop Options header
Destination Options before the Routing Header
Routing header
Fragment header
Authentication header
Encapsulating Security Payload header
Destination Options header
Upper-Layer header
Each Extension Header may be present only once in a packet expect for Destination Options that may occur twice.
net.ipv6.enforce_ext_hdr_order is a sysctl to enable or disable enforcement of extension Header order. If it is set to zero then Extension Header order and number of occurrences is not checked in receive processing (except for Hop-by-Hop Options that must be the first Extension Header and can only occur once in a packet).
--- include/net/netns/ipv6.h | 1 + include/net/protocol.h | 14 +++++++++++++ net/ipv6/af_inet6.c | 1 + net/ipv6/exthdrs.c | 2 ++ net/ipv6/ip6_input.c | 42 ++++++++++++++++++++++++++++++++++++++ net/ipv6/reassembly.c | 1 + net/ipv6/sysctl_net_ipv6.c | 7 +++++++ net/ipv6/xfrm6_protocol.c | 2 ++ 8 files changed, 70 insertions(+)
include/net/netns/ipv6.h +1 -0
@@ -61,6 +61,7 @@ struct netns_sysctl_ipv6 {u8 fib_notify_on_flag_change;u8 icmpv6_error_anycast_as_unicast;u8 icmpv6_errors_extension_mask; +u8 enforce_ext_hdr_order; };struct netns_ipv6 {
include/net/protocol.h +14 -0
@@ -50,6 +50,19 @@ struct net_protocol { }; #if IS_ENABLED(CONFIG_IPV6) + +/* Order of extension headers as prescribed in RFC8200. The ordering and + * number of extension headers in a packet can be enforced in IPv6 receive + * processing. + */ +#define IPV6_EXT_HDR_ORDER_HOP BIT(0) +#define IPV6_EXT_HDR_ORDER_DEST_BEFORE_RH BIT(1) +#define IPV6_EXT_HDR_ORDER_ROUTING BIT(2) +#define IPV6_EXT_HDR_ORDER_FRAGMENT BIT(3) +#define IPV6_EXT_HDR_ORDER_AUTH BIT(4) +#define IPV6_EXT_HDR_ORDER_ESP BIT(5) +#define IPV6_EXT_HDR_ORDER_DEST BIT(6) + struct inet6_protocol { int (*handler)(struct sk_buff *skb);
@@ -61,6 +74,7 @@ struct inet6_protocol {unsigned int flags;/* INET6_PROTO_xxx */ u32 secret; +u32 ext_hdr_order; };#define INET6_PROTO_NOPOLICY 0x1
net/ipv6/af_inet6.c +1 -0
@@ -948,6 +948,7 @@ static int __net_init inet6_net_init(struct net *net) net->ipv6.sysctl.max_dst_opts_len =IP6_DEFAULT_MAX_DST_OPTS_LEN ; net->ipv6.sysctl.max_hbh_opts_len =IP6_DEFAULT_MAX_HBH_OPTS_LEN ; net->ipv6.sysctl.fib_notify_on_flag_change =0 ; + net->ipv6.sysctl.enforce_ext_hdr_order =1 ;atomic_set (&net->ipv6.fib6_sernum,1 ); net->ipv6.sysctl.ioam6_id =IOAM6_DEFAULT_ID ;
net/ipv6/exthdrs.c +2 -0
@@ -852,11 +852,13 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb)static const struct inet6_protocol rthdr_protocol = { .handler = ipv6_rthdr_rcv, .flags =INET6_PROTO_NOPOLICY , + .ext_hdr_order =IPV6_EXT_HDR_ORDER_ROUTING , };static const struct inet6_protocol destopt_protocol = { .handler = ipv6_destopt_rcv, .flags =INET6_PROTO_NOPOLICY , + .ext_hdr_order =IPV6_EXT_HDR_ORDER_DEST , };static const struct inet6_protocol nodata_protocol = {
net/ipv6/ip6_input.c +42 -0
60 lines not on this page · raw message
net/ipv6/reassembly.c +1 -0
@@ -420,6 +420,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)static const struct inet6_protocol frag_protocol = { .handler = ipv6_frag_rcv, .flags =INET6_PROTO_NOPOLICY , + .ext_hdr_order =IPV6_EXT_HDR_ORDER_FRAGMENT , };#ifdef CONFIG_SYSCTL
net/ipv6/sysctl_net_ipv6.c +7 -0
@@ -213,6 +213,13 @@ static struct ctl_table ipv6_table_template[] = { .proc_handler = proc_doulongvec_minmax, .extra2 = &ioam6_id_wide_max, }, + { + .procname = "enforce_ext_hdr_order", + .data = &init_net.ipv6.sysctl.enforce_ext_hdr_order, + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + }, };static struct ctl_table ipv6_rotable[] = {
net/ipv6/xfrm6_protocol.c +2 -0
@@ -197,12 +197,14 @@ static const struct inet6_protocol esp6_protocol = { .handler = xfrm6_esp_rcv, .err_handler = xfrm6_esp_err, .flags = INET6_PROTO_NOPOLICY, + .ext_hdr_order = IPV6_EXT_HDR_ORDER_ESP, };static const struct inet6_protocol ah6_protocol = { .handler = xfrm6_ah_rcv, .err_handler = xfrm6_ah_err, .flags =INET6_PROTO_NOPOLICY , + .ext_hdr_order =IPV6_EXT_HDR_ORDER_AUTH };static const struct inet6_protocol ipcomp6_protocol = {
Signature · 1 line
2.43.0
PATCH v10 7/10 ipv6: Document enforce_ext_hdr_order sysctl
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Document the enforce_ext_hdr_order sysctl that controls whether Extension Header order is enforced on receive.
--- Documentation/networking/ip-sysctl.rst | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
Documentation/networking/ip-sysctl.rst +30 -0
@@ -2617,6 +2617,36 @@ ioam6_id_wide - LONG INTEGER Default: 0xFFFFFFFFFFFFFF +enforce_ext_hdr_order - BOOLEAN + Enforce recommended Extension Header ordering in RFC8200. + If the sysctl is set to 1 then the ordering is enforced in + received packets and each Extension Header may be present + at most once per packet (except for Destination Options that + may occur twice). If the sysctl is set to 0 then ordering is + not enforced and Extension Headers may be present in any + order and have any number of occurrences per packet (except + for Hop-by-Hop Options that must always be the first Extension + Header and occur at most once in a packet)). + + The Extension Header order is: + + IPv6 header + Hop-by-Hop Options header + Destination Options before the Routing header + Routing header + Fragment header + Authentication header + Encapsulating Security Payload header + Destination Options header + Upper-Layer header + + Possible values: + + - 0 (disabled) + - 1 (enabled) + + Default: 1 (enabled) + IPv6 Fragmentation: ip6frag_high_thresh - INTEGER
Signature · 1 line
2.43.0
PATCH v10 8/10 test: Add proto_nums.py in networking selftests
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Add proto_nums.py that contains various python definitions of common protocol constants
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/proto_nums.py | 231 ++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 tools/testing/selftests/net/proto_nums.py
tools/testing/selftests/net/Makefile +1 -0
@@ -69,6 +69,7 @@ TEST_PROGS := \ nl_netdev.py \ nl_nlctrl.py \ pmtu.sh \ + proto_nums.py \ psock_snd.sh \ reuseaddr_ports_exhausted.sh \ reuseport_addr_any.sh \
tools/testing/selftests/net/proto_nums.py new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v10 9/10 test: Add ext_hdr.py in networking selftests
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Add ext_hdr.py that contains various Extension Header format definitions and related helper functions.
This includes the Make_EH_Chain function that creates an Extension Header chain based on an input list. The input list has the format:
[(<type>, <args>), (<type>, <args>), ... (<type>, <args>)]
where <type> is "H" for Hop-by-Hop Options, "D" for Destination Options, "R" for Routing Header, "F" for Fragment header, "A" for Authentication Header, and "E" for ESP header.
<args> is specific to the type of extension header. For Hop-by-Hop and Destination Options <args> is a list of options in the format:
[(<opt_type>, <opt_length>), (<opt_type>, <opt_length>), ...
(<opt_type>, <opt_length>)]
For the Routing Header, <args> is a list of SIDs in the format:
[IPv6_address, IPv6_address, ... IPv6_address]
For the Fragment Header, <args> is the identifier number
Authentication and ESP are not currently supported by Make_EH_Chain
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ext_hdr.py | 385 +++++++++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100755 tools/testing/selftests/net/ext_hdr.py
tools/testing/selftests/net/Makefile +1 -0
@@ -26,6 +26,7 @@ TEST_PROGS := \ cmsg_time.sh \ double_udp_encap.sh \ drop_monitor_tests.sh \ + ext_hdr.py \ fcnal-ipv4.sh \ fcnal-ipv6.sh \ fcnal-other.sh \
tools/testing/selftests/net/ext_hdr.py new file +385 -0
385 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v10 10/10 test: Add networking selftest for eh limits
In reply to Tom HerbertFrom: Tom Herbert <[email protected]>
Add a networking selftest for Extension Header limits. The limits to test are in systcls:
net.ipv6.enforce_ext_hdr_order
net.ipv6.max_dst_opts_number
net.ipv6.max_hbh_opts_number
net.ipv6.max_hbh_length
net.ipv6.max_dst_opts_length
The basic idea of the test is to fabricate ICMPv6 Echo Request packets with various combinations of Extension Headers. The packets are sent to a host in another namespace. If a an ICMPv6 Echo Reply is received then the packet wasn't dropped due to a limit being exceeded, and if it was dropped then we assume that a limit was exceeded. For each test packet we derive an expectation as to whether the packet will be dropped or not. Test success depends on whether our expectation is matched. i.e. if we expect a reply then the test succeeds if we see a reply, and if we don't expect a reply then the test succeeds if we don't see a reply.
The test is divided into a frontend bash script (eh_limits.sh) and a backend Python script (eh_limits.py).
The frontend sets up two network namespaces with IPv6 addresses configured on veth's. We then invoke the backend to send the test packets. This first pass is done with default sysctl settings. On a second pass we change the various sysctl settings and run again.
The backend runs through the various test cases described in the Make_Test_Packets function. This function calls Make_Packet for a test case where arguments provide the Extension Header chain to be tested. The Run_Test function loops through the various packets and tests if a reply is received versus the expectation. If a test case fails then an error status is returned by the backend.
The backend script can also be run with the "-w <pcap_file>" to write the created packets to a pcap file instead of running the test.
--- tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/eh_limits.py | 349 +++++++++++++++++++++++ tools/testing/selftests/net/eh_limits.sh | 210 ++++++++++++++ 3 files changed, 561 insertions(+) create mode 100755 tools/testing/selftests/net/eh_limits.py create mode 100755 tools/testing/selftests/net/eh_limits.sh
tools/testing/selftests/net/Makefile +2 -0
@@ -26,6 +26,8 @@ TEST_PROGS := \ cmsg_time.sh \ double_udp_encap.sh \ drop_monitor_tests.sh \ + eh_limits.py \ + eh_limits.sh \ ext_hdr.py \ fcnal-ipv4.sh \ fcnal-ipv6.sh \
tools/testing/selftests/net/eh_limits.py new file +349 -0
349 lines not on this page · raw message
tools/testing/selftests/net/eh_limits.sh new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 10 lines · On Mon, 4 May 2026 11:51:12 -0700 Tom Herbert wrote:
--- Testing
Add selftest
eh_limits.sh. Tested by running:$ sudo ./eh_limits.sh TEST: EH-limits - default sysctls [ OK ] TEST: EH-limits - modified sysctls [ OK ]Tests passed: 2 Tests failed: 0
The python files need to be in TEST_FILES not TEST_PROGS (AFAIU they are helpers not tests themselves). They must pass ruff check and pylint --disable=R cleanly
The bash currently passes but prints a FAIL making our CI mark it as FAIL:
# selftests: net: eh_limits.sh
# 2.50 [+2.50] WARNING: Could not retrieve the OS's nameserver ! # 4.54 [+2.04] WARNING: Could not retrieve the OS's nameserver !
# 6.29 [+1.74] TEST: EH-limits - default sysctls [ OK ]
# 6.54 [+0.25] WARNING: Could not retrieve the OS's nameserver !
# 7.90 [+1.36] FAIL: Expected to receive for Many EH OOO <<<< here <<<
# 8.00 [+0.10] TEST: EH-limits - modified sysctls [ OK ]
# 8.02 [+0.02]
# 8.02 [+0.00] Tests passed: 2
# 8.02 [+0.00] Tests failed: 0
Definitely does not look like your results.. Note that we run the tests with
make -C tools/testing/selftests run_tests TEST_PROGS="eh_limits.sh" TEST_GEN_PROGS=""
Quoted 186 lines · Tom Herbert
IPv6 extension headers are defined to be quite open ended with few limits. For instance, RFC8200 requires a receiver to process any number of extension headers in a packet in any order. This flexibility comes at the cost of a potential Denial of Service attack. The only thing that might mitigate the DoS attacks is the fact that packets with extension headers experience high drop rates on the Internet so that a DoS attack based on extension wouldn't be very effective at Internet scale.
This patch set addresses some of the more egregious vulnerabilities of extension headers to DoS attack.
- If sysctl.max_dst_opts_cnt or
hbh_opts_cntare set to 0 then that disallows packets with Destination Options or Hop-by-Hop Options even if the packet contain zero non-padding options- Add a case for
IPV6_TLV_TNL_ENCAP_LIMITin the switch on TLV type inip6_parse_tlvfunction. This TLV is handled in tunnel processing, however it needs to be detected inip6_parse_tlvto properly account for it as recognized non-padding option- Move
IPV6_TLV_TNL_ENCAP_LIMITtouapi/linux/in6.hso that all the TLV definitions are in one place- Set the default limits of non-padding Hop-by-Hop and Destination options to 2. This means that if a packet contains more then two non-padding options then it will be dropped. The previous limit was 8, but that was too liberal considering that the stack only support two Destination Options and the most Hop-by-Hop options likely to ever be in the same packet are IOAM and JUMBO. The limit can be increased via sysctl for private use and experimentation
- Enforce RFC8200 recommended ordering of Extension Headers. This also enforces that any Extension Header occurs at most once in a packet except for Destination Options that may appear twice. The
enforce_ext_hdr_ordersysctl controls enforcement. If it's set to true then order is enforced, if it's set to false then neither order nor number of occurrences are enforced.The enforced ordering is:
IPv6 header
Hop-by-Hop Options header
Destination Options before the Routing header Routing header
Fragment header
Authentication header
Encapsulating Security Payload header Destination Options header Upper-Layer header--- Background
We selected the default value of eight in RFC8504 based on an expectation that there might be new options defined and that the Internet would be fixed to reliably support extension headers including those with options. I do not believe either of those are going to happen.
Hop-by-Hop Options are ostensibly the right way to do network to host and host to network signaling.The only HBH options that might get any substantial deployment are Router Alert option and IOAM. The Router Alert option is being deprecated and IOAM is at best a "nice to have". The best use case of Hop-by-Hop options is congestion signaling, unfortunately the die was cast when CSIG authors decided to place the information in VLANs at L2 and cajole the information to be routable through a switch. IMO, the miss on CSIG pretty much is the nail in the coffin for Hop-by-Hop options to ever be widely deployed
(https://www.ietf.org/archive/id/draft-ravi-ippm-csig-01.txt).Destination Options have proven even less useful than Hop-by-Hop Options. The only Destination Options supported by the stack is the Tunnel Encap Limit option and Home Address Options. The Tunnel Encap Option was buried in the v6 tunnel code which is why it wasn't obvious it was supported in the first version of the patch set. I'll assume that might be useful, so this patch set cleans up the code for it. I don't believe there's any use of Home Address Option.
A major problem with DestOpts, HBH, Routing Header, and Fragment header is that they have no inherent security. Their use presents a security risk especially when sent over untrusted networks including the Internet. Given that and that the high drop rates of extension headers on the Internet, I am proposing that Extension header except for ESP being deprecated on the Internet
(https://www.ietf.org/archive/id/draft-herbert-deprecate-eh-01.txt).An update to RFC8200 is being proposed in IETF to allow enforcement of extension header ordering and number of occurences. An I-D is in
https://www.ietf.org/archive/id/draft-iurman-6man-eh-occurrences-00.txt--- Testing
Add selftest
eh_limits.sh. Tested by running:$ sudo ./eh_limits.sh TEST: EH-limits - default sysctls [ OK ] TEST: EH-limits - modified sysctls [ OK ]Tests passed: 2 Tests failed: 0$ sudo ./eh_limits.sh -vQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Default
TEST: Two non-padding options in HBH and DestOpts: Received as expected
TEST: Big destination option: Received as expected
TEST: Almost Big HBH option: Received as expected
TEST: Big HBH option: Received as expected
TEST: Too much HBH padding: Didn't receive as expected
TEST: Too much DestOpt padding: Didn't receive as expected
TEST: Too much DestOpt padding #2: Didn't receive as expected
TEST: Too much DestOpt padding #3: Didn't receive as expected
TEST: Almost too much DestOpt padding #2: Received as expected
TEST: Two Dest Ops: Didn't receive as expected
TEST: OOO Routing header: Didn't receive as expected
TEST: Two Routing headers: Didn't receive as expected
TEST: Two Destination options okay: Received as expected
TEST: Two Destination options: Didn't receive as expected
TEST: Two Destination options after RH: Didn't receive as expected
TEST: Many EH OOO: Didn't receive as expected
TEST: Two fragment Headers: Didn't receive as expectedTEST: EH-limits - default sysctls [ OK ]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
No order enforce, 8 options, 66 length limit
TEST: Two non-padding options in HBH and DestOpts: Received as expected
TEST: Big destination option: Didn't receive as expected
TEST: Almost Big HBH option: Received as expected
TEST: Big HBH option: Didn't receive as expected
TEST: Too much HBH padding: Didn't receive as expected
TEST: Too much DestOpt padding: Didn't receive as expected
TEST: Too much DestOpt padding #2: Didn't receive as expected
TEST: Too much DestOpt padding #3: Didn't receive as expected
TEST: Almost too much DestOpt padding #2: Received as expected
TEST: Two Dest Ops: Received as expected
TEST: OOO Routing header: Received as expected
TEST: Two Routing headers: Received as expected
TEST: Two Destination options okay: Received as expected
TEST: Two Destination options: Received as expected
TEST: Two Destination options after RH: Received as expected
TEST: Many EH OOO: Received as expected
TEST: Two fragment Headers: Didn't receive as expectedTEST: EH-limits - modified sysctls [ OK ]
Tests passed: 2 Tests failed: 0V4: Switch order of patches to avoid transient build failure
V5: Allow Destination Options before the Routing header, fixes
suggested by Justin Iurman
v6: Fix a bug and create a test for extension header limits
v7: Run pylint on new Python file, run shellcheck on new bash file,
Make fixes as needed
v8: Repost
v9: Fix subject prefix
v10: Lint fixes in selftest scripts suggested by Simon HormanTom Herbert (10):
ipv6: Check of max HBH or DestOp sysctl is zero and drop if it is
ipv6: Cleanup IPv6 TLV definitions
ipv6: Add case forIPV6_TLV_TNL_ENCAP_LIMITin EH TLV switch
ipv6: Set HBH and DestOpt limits to 2
ipv6: Document defaults for max_{dst|hbh}_opts_number sysctls
ipv6: Enforce Extension Header ordering
ipv6: Documentenforce_ext_hdr_ordersysctl
test: Addproto_nums.pyin networking selftests
test: Addext_hdr.pyin networking selftests
test: Add networking selftest for eh limitsDocumentation/networking/ip-sysctl.rst | 52 ++- include/net/ipv6.h | 9 +- include/net/netns/ipv6.h | 1 + include/net/protocol.h | 14 + include/uapi/linux/in6.h | 21 +- include/uapi/linux/ip6_tunnel.h | 1 - net/ipv6/af_inet6.c | 1 + net/ipv6/exthdrs.c | 32 +- net/ipv6/ip6_input.c | 42 +++ net/ipv6/reassembly.c | 1 + net/ipv6/sysctl_net_ipv6.c | 7 + net/ipv6/xfrm6_protocol.c | 2 + tools/testing/selftests/net/Makefile | 4 + tools/testing/selftests/net/eh_limits.py | 349 ++++++++++++++++++++ tools/testing/selftests/net/eh_limits.sh | 210 ++++++++++++ tools/testing/selftests/net/ext_hdr.py | 385 ++++++++++++++++++++++ tools/testing/selftests/net/proto_nums.py | 231 +++++++++++++ 17 files changed, 1334 insertions(+), 28 deletions(-)
Quoted 5 lines
create mode 100755
tools/testing/selftests/net/eh_limits.pycreate mode 100755tools/testing/selftests/net/eh_limits.shcreate mode 100755tools/testing/selftests/net/ext_hdr.pycreate mode 100644tools/testing/selftests/net/proto_nums.py
Hi Tom,
While at it, should we also take care of ip6_tnl_parse_tlv_enc_lim(), ipv6_skip_exthdr(), and ipv6_find_hdr(), so that we remain consistent with recent merged fixes 3744b0964d52 and 076b8cad77aa ?
Cheers,
Justin