ipv4: Add ICMPv6 support when parse route ipproto
Subsystems (3)
PATCH 1/1 ipv4: Add ICMPv6 support when parse route ipproto
For ip rules, we need to use 'ipproto ipv6-icmp' to match ICMPv6 headers. But for ip -6 route, currently we only support tcp, udp and icmp.
Add ICMPv6 support so we can match ipv6-icmp rules for route lookup.
--- net/ipv4/netlink.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/netlink.c +2 -0
@@ -3,6 +3,7 @@#include <linux/types.h> #include <net/net_namespace.h> #include <net/netlink.h> +#include <linux/in6.h> #include <net/ip.h> int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,
@@ -14,6 +15,7 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,case IPPROTO_TCP :case IPPROTO_UDP :case IPPROTO_ICMP : +case IPPROTO_ICMPV6 :return 0 ;default :NL_SET_ERR_MSG (extack,"Unsupported ip proto" );
Signature · 1 line
2.19.2
net/ipv4/netlink.c int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, · line 18
Quoted 5 lines · Hangbin Liu
net/ipv4/netlink.c +1
-0@@ -14,6 +15,7 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,case IPPROTO_TCP :case IPPROTO_UDP :case IPPROTO_ICMP : +case IPPROTO_ICMPV6 :
Is IPPROTO_ICMPV6 supposed to be valid in the IPv4 code path calling this function? inet_rtm_getroute_build_skb() doesn't seem to handle it. Likewise, userspace could pass IPPROTO_ICMP from the IPv6 caller.
Also, should that be guarded by #if IS_ENABLED(CONFIG_IPV6) ?
Quoted 6 lines
net/ipv4/netlink.c +0
-0return 0 ;default :NL_SET_ERR_MSG (extack,"Unsupported ip proto" );Signature · 1 line
2.19.2
Signature · 1 line
Sabrina
Quoted 9 lines · Sabrina Dubroca
net/ipv4/netlink.c int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, · line 18
Quoted 5 lines · Hangbin Liu
net/ipv4/netlink.c +1
-0@@ -14,6 +15,7 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,case IPPROTO_TCP :case IPPROTO_UDP :case IPPROTO_ICMP : +case IPPROTO_ICMPV6 :Is
IPPROTO_ICMPV6supposed to be valid in the IPv4 code path calling this function?
no. I do not see how that makes sense.
Quoted 11 lines · David Ahern
Quoted 9 lines · Sabrina Dubroca
net/ipv4/netlink.c int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, · line 18
Quoted 5 lines · Hangbin Liu
net/ipv4/netlink.c +1
-0@@ -14,6 +15,7 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,case IPPROTO_TCP :case IPPROTO_UDP :case IPPROTO_ICMP : +case IPPROTO_ICMPV6 :Is
IPPROTO_ICMPV6supposed to be valid in the IPv4 code path calling this function?
Quoted 1 line
no. I do not see how that makes sense.
I also thought about this issue. Currently we didn't check the ipproto in both IPv4 and IPv6. You can set icmp in ip6 rules or icmpv6 in ipv4 rules. This looks don't make any serious problem. It's just a user mis-configuration, the kernel check the proto number and won't match normal IP/IPv6 headers.
But yes, we should make it more strict, do you think if I should add a new rtm_getroute_parse_ip6_proto() function, or just add a family parameter in previous function?
The #if IS_ENABLED(CONFIG_IPV6) guardian makes sense. I will fix it.
Thanks
Hangbin
Quoted 8 lines · Hangbin Liu
I also thought about this issue. Currently we didn't check the ipproto in both IPv4 and IPv6. You can set icmp in ip6 rules or icmpv6 in ipv4 rules. This looks don't make any serious problem. It's just a user mis-configuration, the kernel check the proto number and won't match normal IP/IPv6 headers.
But yes, we should make it more strict, do you think if I should add a new
rtm_getroute_parse_ip6_proto()function, or just add a family parameter in previous function?
I see now. rtm_getroute_parse_ip_proto is used for ipv4 and ipv6. For v4 IPPROTO_ICMPV6 should not be allowed and for v6 IPPROTO_ICMP should fail. You could a version argument to rtm_getroute_parse_ip_proto and fail as needed.
Hi David,
Quoted 6 lines · David Ahern
Quoted 5 lines · Hangbin Liu
I also thought about this issue. Currently we didn't check the ipproto in both IPv4 and IPv6. You can set icmp in ip6 rules or icmpv6 in ipv4 rules. This looks don't make any serious problem. It's just a user mis-configuration, the kernel check the proto number and won't match normal IP/IPv6 headers.
Quoted 8 lines
Quoted 3 lines
But yes, we should make it more strict, do you think if I should add a new
rtm_getroute_parse_ip6_proto()function, or just add a family parameter in previous function?I see now.
rtm_getroute_parse_ip_protois used for ipv4 and ipv6. For v4IPPROTO_ICMPV6should not be allowed and for v6IPPROTO_ICMPshould fail. You could a version argument tortm_getroute_parse_ip_protoand fail as needed.
Sorry I didn't get here. Do you mean add an IPv6 version of rtm_getroute_parse_ip_proto?
Thanks
Hangbin
Quoted 12 lines · Hangbin Liu
Hi David,
Quoted 10 lines · David Ahern
Quoted 8 lines · Hangbin Liu
I also thought about this issue. Currently we didn't check the ipproto in both IPv4 and IPv6. You can set icmp in ip6 rules or icmpv6 in ipv4 rules. This looks don't make any serious problem. It's just a user mis-configuration, the kernel check the proto number and won't match normal IP/IPv6 headers.
But yes, we should make it more strict, do you think if I should add a new
rtm_getroute_parse_ip6_proto()function, or just add a family parameter in previous function?
Quoted 7 lines
Quoted 4 lines
I see now.
rtm_getroute_parse_ip_protois used for ipv4 and ipv6. For v4IPPROTO_ICMPV6should not be allowed and for v6IPPROTO_ICMPshould fail. You could a version argument tortm_getroute_parse_ip_protoand fail as needed.Sorry I didn't get here. Do you mean add an IPv6 version of
rtm_getroute_parse_ip_proto?
Add an argument to rtm_getroute_parse_ip_proto that tells what IP version to use, and then handle IPPROTO_ICMP/IPPROTO_ICMPV6 depending on that.
For example:
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,
bool ipv6, struct netlink_ext_ack *extack)
And pass false from ipv4/true from ipv6.
Signature · 1 line
Sabrina
PATCH v2 1/1 ipv4: Add ICMPv6 support when parse route ipproto
In reply to Hangbin LiuFor ip rules, we need to use 'ipproto ipv6-icmp' to match ICMPv6 headers. But for ip -6 route, currently we only support tcp, udp and icmp.
Add ICMPv6 support so we can match ipv6-icmp rules for route lookup.
v2: As David Ahern and Sabrina Dubroca suggested, Add an argument to rtm_getroute_parse_ip_proto() to handle ICMP/ICMPv6 with different family.
--- include/net/ip.h | 2 +- net/ipv4/netlink.c | 17 +++++++++++++---- net/ipv4/route.c | 2 +- net/ipv6/route.c | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-)
include/net/ip.h +1 -1
@@ -716,7 +716,7 @@ extern int sysctl_icmp_msgs_burst;int ip_misc_proc_init (void );#endif -int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto, +int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto,u8 family,struct netlink_ext_ack *extack);#endif /* _IP_H */
net/ipv4/netlink.c +13 -4
@@ -3,9 +3,10 @@#include <linux/types.h> #include <net/net_namespace.h> #include <net/netlink.h> +#include <linux/in6.h> #include <net/ip.h> -int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto, +int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto,u8 family,struct netlink_ext_ack *extack) { *ip_proto =nla_get_u8 (attr);
@@ -13,11 +14,19 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,switch (*ip_proto) {case IPPROTO_TCP :case IPPROTO_UDP : +return 0 ;case IPPROTO_ICMP : +if (family !=AF_INET ) +break ; +return 0 ; +#if IS_ENABLED (CONFIG_IPV6 ) +case IPPROTO_ICMPV6 : +if (family !=AF_INET6 ) +break ;return 0 ; -default : -NL_SET_ERR_MSG (extack,"Unsupported ip proto" ); -return -EOPNOTSUPP ; +#endif } +NL_SET_ERR_MSG (extack,"Unsupported ip proto" ); +return -EOPNOTSUPP ; }EXPORT_SYMBOL_GPL (rtm_getroute_parse_ip_proto);
net/ipv4/route.c +1 -1
@@ -2803,7 +2803,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,if (tb[RTA_IP_PROTO ]) { err =rtm_getroute_parse_ip_proto (tb[RTA_IP_PROTO ], - &ip_proto, extack); + &ip_proto,AF_INET , extack);if (err)return err; }
net/ipv6/route.c +2 -1
@@ -4889,7 +4889,8 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,if (tb[RTA_IP_PROTO ]) { err =rtm_getroute_parse_ip_proto (tb[RTA_IP_PROTO ], - &fl6.flowi6_proto, extack); + &fl6.flowi6_proto,AF_INET6 , + extack);if (err) goto errout; }
Signature · 1 line
2.19.2
David Miller
maintainerFrom: Hangbin Liu <[email protected]>
Date: Wed, 27 Feb 2019 16:15:29 +0800
Quoted 11 lines
For ip rules, we need to use 'ipproto ipv6-icmp' to match ICMPv6 headers. But for ip -6 route, currently we only support tcp, udp and icmp.
Add ICMPv6 support so we can match ipv6-icmp rules for route lookup.
v2: As David Ahern and Sabrina Dubroca suggested, Add an argument to
rtm_getroute_parse_ip_proto()to handle ICMP/ICMPv6 with different family.Reported-by Jianlin Shi <[email protected]>Fixes eacb9384a3fe ("ipv6: support sport, dport and ip_proto in RTM_GETROUTE")Signed-off-by Hangbin Liu <[email protected]>
Applied and queued up for -stable, thanks.