net/route: remove ip route rtm_src_len, rtm_dst_len valid check
Subsystems (3)
PATCH 1/1 net/route: remove ip route rtm_src_len, rtm_dst_len valid check
In patch set e266afa9c7af ("Merge branch 'net-use-strict-checks-in-doit-handlers'") we added a check for rtm_src_len, rtm_dst_len, which will cause cmds like "ip route get 192.0.2.0/24" failed.
There is no sense to restrict rtm_src_len, rtm_dst_len to 32 for IPv4, or 128 for IPv6. Remove this check.
--- net/ipv4/ipmr.c | 10 +--------- net/ipv4/route.c | 10 +--------- net/ipv6/route.c | 10 +--------- 3 files changed, 3 insertions(+), 27 deletions(-)
net/ipv4/ipmr.c +1 -9
@@ -2500,9 +2500,7 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb, rtm_ipv4_policy, extack); rtm =nlmsg_data (nlh); -if ((rtm->rtm_src_len && rtm->rtm_src_len !=32 ) || - (rtm->rtm_dst_len && rtm->rtm_dst_len !=32 ) || - rtm->rtm_tos || rtm->rtm_table || rtm->rtm_protocol || +if (rtm->rtm_tos || rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || rtm->rtm_type || rtm->rtm_flags) {NL_SET_ERR_MSG (extack,"ipv4: Invalid values in header for multicast route get request" );return -EINVAL ;
@@ -2513,12 +2511,6 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb,if (err)return err; -if ((tb[RTA_SRC ] && !rtm->rtm_src_len) || - (tb[RTA_DST ] && !rtm->rtm_dst_len)) { -NL_SET_ERR_MSG (extack,"ipv4: rtm_src_len and rtm_dst_len must be 32 for IPv4" ); -return -EINVAL ; - } -for (i =0 ; i <=RTA_MAX ; i++) {if (!tb[i])continue ;
net/ipv4/route.c +1 -9
@@ -3063,9 +3063,7 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb, rtm_ipv4_policy, extack); rtm =nlmsg_data (nlh); -if ((rtm->rtm_src_len && rtm->rtm_src_len !=32 ) || - (rtm->rtm_dst_len && rtm->rtm_dst_len !=32 ) || - rtm->rtm_table || rtm->rtm_protocol || +if (rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || rtm->rtm_type) {NL_SET_ERR_MSG (extack,"ipv4: Invalid values in header for route get request" );return -EINVAL ;
@@ -3083,12 +3081,6 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,if (err)return err; -if ((tb[RTA_SRC ] && !rtm->rtm_src_len) || - (tb[RTA_DST ] && !rtm->rtm_dst_len)) { -NL_SET_ERR_MSG (extack,"ipv4: rtm_src_len and rtm_dst_len must be 32 for IPv4" ); -return -EINVAL ; - } -for (i =0 ; i <=RTA_MAX ; i++) {if (!tb[i])continue ;
net/ipv6/route.c +1 -9
@@ -5714,9 +5714,7 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb, rtm_ipv6_policy, extack); rtm =nlmsg_data (nlh); -if ((rtm->rtm_src_len && rtm->rtm_src_len !=128 ) || - (rtm->rtm_dst_len && rtm->rtm_dst_len !=128 ) || - rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || +if (rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || rtm->rtm_type) {NL_SET_ERR_MSG_MOD (extack,"Invalid values in header for get route request" );return -EINVAL ;
@@ -5732,12 +5730,6 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,if (err)return err; -if ((tb[RTA_SRC ] && !rtm->rtm_src_len) || - (tb[RTA_DST ] && !rtm->rtm_dst_len)) { -NL_SET_ERR_MSG_MOD (extack,"rtm_src_len and rtm_dst_len must be 128 for IPv6" ); -return -EINVAL ; - } -for (i =0 ; i <=RTA_MAX ; i++) {if (!tb[i])continue ;
Signature · 1 line
2.19.2
Quoted 4 lines · Hangbin Liu
In patch set
e266afa9c7af("Merge branch 'net-use-strict-checks-in-doit-handlers'") we added a check forrtm_src_len,rtm_dst_len, which will cause cmds like "ip route get 192.0.2.0/24" failed.
kernel does not handle route gets for a range. Any output is specific to the prefix (192.0.2.0 in your example) so it seems to me the /24 request should fail.
Quoted 10 lines · David Ahern
Quoted 4 lines · Hangbin Liu
In patch set
e266afa9c7af("Merge branch 'net-use-strict-checks-in-doit-handlers'") we added a check forrtm_src_len,rtm_dst_len, which will cause cmds like "ip route get 192.0.2.0/24" failed.kernel does not handle route gets for a range. Any output is specific to the prefix (192.0.2.0 in your example) so it seems to me the /24 request should fail.
OK, so we should check all the range field if NETLINK_F_STRICT_CHK supplied, like the following patch, right?
net/ipv4/route.c +1 -8
@@ -3063,8 +3063,7 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb, rtm_ipv4_policy, extack); rtm =nlmsg_data (nlh); -if ((rtm->rtm_src_len && rtm->rtm_src_len !=32 ) || - (rtm->rtm_dst_len && rtm->rtm_dst_len !=32 ) || +if (rtm->rtm_src_len || rtm->rtm_dst_len || rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || rtm->rtm_type) {NL_SET_ERR_MSG (extack,"ipv4: Invalid values in header for route get request" );
@@ -3083,12 +3082,6 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,if (err)return err; -if ((tb[RTA_SRC ] && !rtm->rtm_src_len) || - (tb[RTA_DST ] && !rtm->rtm_dst_len)) { -NL_SET_ERR_MSG (extack,"ipv4: rtm_src_len and rtm_dst_len must be 32 for IPv4" ); -return -EINVAL ; - } -for (i =0 ; i <=RTA_MAX ; i++) {if (!tb[i])continue ;
Thanks
Hangbin
Quoted 7 lines · Hangbin Liu
Quoted 6 lines · David Ahern
Quoted 4 lines · Hangbin Liu
In patch set
e266afa9c7af("Merge branch 'net-use-strict-checks-in-doit-handlers'") we added a check forrtm_src_len,rtm_dst_len, which will cause cmds like "ip route get 192.0.2.0/24" failed.
Quoted 7 lines
Quoted 4 lines
kernel does not handle route gets for a range. Any output is specific to the prefix (192.0.2.0 in your example) so it seems to me the /24 request should fail.
OK, so we should check all the range field if
NETLINK_F_STRICT_CHKsupplied, like the following patch, right?
a dst_len / src_len of 32 (or 128 for v6) is ok. It still means only the prefix is used for the route get. That's why it was coded this way as part of the change for stricter checking.
Quoted 13 lines · David Ahern
Quoted 12 lines · Hangbin Liu
Quoted 10 lines · David Ahern
Quoted 4 lines · Hangbin Liu
In patch set
e266afa9c7af("Merge branch 'net-use-strict-checks-in-doit-handlers'") we added a check forrtm_src_len,rtm_dst_len, which will cause cmds like "ip route get 192.0.2.0/24" failed.kernel does not handle route gets for a range. Any output is specific to the prefix (192.0.2.0 in your example) so it seems to me the /24 request should fail.
Quoted 7 lines
Quoted 2 lines
OK, so we should check all the range field if
NETLINK_F_STRICT_CHKsupplied, like the following patch, right?a
dst_len/src_lenof 32 (or 128 for v6) is ok. It still means only the prefix is used for the route get. That's why it was coded this way as part of the change for stricter checking.
Ah, I see now. Thanks for the interpretation.
Regards
Hangbin