ipv6: check skb->protocol before lookup for nexthop
PATCH 1/1 ipv6: check skb->protocol before lookup for nexthop
From: WANG Cong <[email protected]>
[ Upstream commit 199ab00f3cdb6f154ea93fa76fd80192861a821d ]
Andrey reported a out-of-bound access in ip6_tnl_xmit(), this is because we use an ipv4 dst in ip6_tnl_xmit() and cast an IPv4 neigh key as an IPv6 address:
neigh = dst_neigh_lookup(skb_dst(skb),
&ipv6_hdr(skb)->daddr);
if (!neigh)
goto tx_err_link_failure;
addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE
addr_type = ipv6_addr_type(addr6);
if (addr_type == IPV6_ADDR_ANY)
addr6 = &ipv6_hdr(skb)->daddr;
memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if skb->protocol is ETH_P_IPV6: if it is, we are safe to do the nexthop lookup using skb_dst() and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall to ip6_route_output() to make the decision.
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
net/ipv6/ip6_tunnel.c +17 -15
@@ -972,26 +972,28 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,/* NBMA tunnel */ if (ipv6_addr_any (&t->parms.raddr)) { -struct in6_addr *addr6; -struct neighbour *neigh; -int addr_type; +if (skb->protocol ==htons (ETH_P_IPV6 )) { +struct in6_addr *addr6; +struct neighbour *neigh; +int addr_type; -if (!skb_dst (skb)) - goto tx_err_link_failure; +if (!skb_dst (skb)) + goto tx_err_link_failure; - neigh =dst_neigh_lookup (skb_dst (skb), - &ipv6_hdr (skb)->daddr); -if (!neigh) - goto tx_err_link_failure; + neigh =dst_neigh_lookup (skb_dst (skb), + &ipv6_hdr (skb)->daddr); +if (!neigh) + goto tx_err_link_failure; - addr6 = (struct in6_addr *)&neigh->primary_key; - addr_type =ipv6_addr_type (addr6); + addr6 = (struct in6_addr *)&neigh->primary_key; + addr_type =ipv6_addr_type (addr6); -if (addr_type ==IPV6_ADDR_ANY ) - addr6 = &ipv6_hdr (skb)->daddr; +if (addr_type ==IPV6_ADDR_ANY ) + addr6 = &ipv6_hdr (skb)->daddr; -memcpy (&fl6->daddr, addr6,sizeof (fl6->daddr)); -neigh_release (neigh); +memcpy (&fl6->daddr, addr6,sizeof (fl6->daddr)); +neigh_release (neigh); + } }else if (!fl6->flowi6_mark) dst =dst_cache_get (&t->dst_cache);
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
Greg KH
maintainerQuoted 40 lines · Alessio Balsini
From: WANG Cong <[email protected]>
[ Upstream commit
199ab00f3cdb6f154ea93fa76fd80192861a821d]Andrey reported a out-of-bound access in
ip6_tnl_xmit(), this is because we use an ipv4 dst inip6_tnl_xmit()and cast an IPv4 neigh key as an IPv6 address:neigh = dst_neigh_lookup(skb_dst(skb), &ipv6_hdr(skb)->daddr); if (!neigh) goto tx_err_link_failure; addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE addr_type = ipv6_addr_type(addr6); if (addr_type == IPV6_ADDR_ANY) addr6 = &ipv6_hdr(skb)->daddr; memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if
skb->protocolisETH_P_IPV6: if it is, we are safe to do the nexthop lookup usingskb_dst()and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall toip6_route_output()to make the decision.Fixes ea3dc9601bda ("ip6_tunnel: Add support for wildcard tunnel endpoints.")Reported-by Andrey Konovalov <[email protected]>Reported-by [email protected]Tested-by Andrey Konovalov <[email protected]>Cc Steffen Klassert <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Alessio Balsini <[email protected]>
Quoted 3 lines
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
This was already applied to the 4.4.66 kernel release
But this patch applies to the 4.4.y tree. Which is really really odd, what is going on here?
confused,
greg k-h
Quoted 45 lines · Greg KH
Quoted 40 lines · Alessio Balsini
From: WANG Cong <[email protected]>
[ Upstream commit
199ab00f3cdb6f154ea93fa76fd80192861a821d]Andrey reported a out-of-bound access in
ip6_tnl_xmit(), this is because we use an ipv4 dst inip6_tnl_xmit()and cast an IPv4 neigh key as an IPv6 address:neigh = dst_neigh_lookup(skb_dst(skb), &ipv6_hdr(skb)->daddr); if (!neigh) goto tx_err_link_failure; addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE addr_type = ipv6_addr_type(addr6); if (addr_type == IPV6_ADDR_ANY) addr6 = &ipv6_hdr(skb)->daddr; memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if
skb->protocolisETH_P_IPV6: if it is, we are safe to do the nexthop lookup usingskb_dst()and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall toip6_route_output()to make the decision.Fixes ea3dc9601bda ("ip6_tunnel: Add support for wildcard tunnel endpoints.")Reported-by Andrey Konovalov <[email protected]>Reported-by [email protected]Tested-by Andrey Konovalov <[email protected]>Cc Steffen Klassert <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Alessio Balsini <[email protected]>Quoted 3 lines
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
Quoted 8 lines
This was already applied to the 4.4.66 kernel release
But this patch applies to the 4.4.y tree. Which is really really odd, what is going on here?
confused,
greg k-h
Totally odd... Now that you gave me this heads up, I can see that the patch was applied to v4.4.66 and for some reason dropped since v4.4.118.
Can you please take a look? Thanks!
Alessio
Greg KH
maintainerQuoted 51 lines · Alessio Balsini
Quoted 50 lines · Greg KH
Quoted 40 lines · Alessio Balsini
From: WANG Cong <[email protected]>
[ Upstream commit
199ab00f3cdb6f154ea93fa76fd80192861a821d]Andrey reported a out-of-bound access in
ip6_tnl_xmit(), this is because we use an ipv4 dst inip6_tnl_xmit()and cast an IPv4 neigh key as an IPv6 address:neigh = dst_neigh_lookup(skb_dst(skb), &ipv6_hdr(skb)->daddr); if (!neigh) goto tx_err_link_failure; addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE addr_type = ipv6_addr_type(addr6); if (addr_type == IPV6_ADDR_ANY) addr6 = &ipv6_hdr(skb)->daddr; memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if
skb->protocolisETH_P_IPV6: if it is, we are safe to do the nexthop lookup usingskb_dst()and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall toip6_route_output()to make the decision.Fixes ea3dc9601bda ("ip6_tunnel: Add support for wildcard tunnel endpoints.")Reported-by Andrey Konovalov <[email protected]>Reported-by [email protected]Tested-by Andrey Konovalov <[email protected]>Cc Steffen Klassert <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Alessio Balsini <[email protected]>Quoted 3 lines
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)This was already applied to the 4.4.66 kernel release
But this patch applies to the 4.4.y tree. Which is really really odd, what is going on here?
Quoted 8 lines
Quoted 3 lines
confused,
greg k-h
Totally odd... Now that you gave me this heads up, I can see that the patch was applied to v4.4.66 and for some reason dropped since v4.4.118.
Can you please take a look? Thanks!
What dropped it? Fixes that resolved other things? Are you sure this is still needed?
That's all I can tell, you can see the kernel branch as well as I can :)
greg k-h
Quoted 59 lines · Greg KH
Quoted 58 lines · Alessio Balsini
Quoted 45 lines · Greg KH
Quoted 40 lines · Alessio Balsini
From: WANG Cong <[email protected]>
[ Upstream commit
199ab00f3cdb6f154ea93fa76fd80192861a821d]Andrey reported a out-of-bound access in
ip6_tnl_xmit(), this is because we use an ipv4 dst inip6_tnl_xmit()and cast an IPv4 neigh key as an IPv6 address:neigh = dst_neigh_lookup(skb_dst(skb), &ipv6_hdr(skb)->daddr); if (!neigh) goto tx_err_link_failure; addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE addr_type = ipv6_addr_type(addr6); if (addr_type == IPV6_ADDR_ANY) addr6 = &ipv6_hdr(skb)->daddr; memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if
skb->protocolisETH_P_IPV6: if it is, we are safe to do the nexthop lookup usingskb_dst()and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall toip6_route_output()to make the decision.Fixes ea3dc9601bda ("ip6_tunnel: Add support for wildcard tunnel endpoints.")Reported-by Andrey Konovalov <[email protected]>Reported-by [email protected]Tested-by Andrey Konovalov <[email protected]>Cc Steffen Klassert <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Alessio Balsini <[email protected]>Quoted 3 lines
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)Quoted 8 lines
This was already applied to the 4.4.66 kernel release
But this patch applies to the 4.4.y tree. Which is really really odd, what is going on here?
confused,
greg k-h
Totally odd... Now that you gave me this heads up, I can see that the patch was applied to v4.4.66 and for some reason dropped since v4.4.118.
Quoted 8 lines
Quoted 1 line
Can you please take a look? Thanks!
What dropped it? Fixes that resolved other things? Are you sure this is still needed?
That's all I can tell, you can see the kernel branch as well as I can :)
greg k-h
It looks like upstream 607f725f6f7d (net: replace dst_cache ip6_tunnel implementation with the generic one), had some extra code removed when backported as b8c7f80cbdcd in v4.4.118, resulting in a complete, hidden revert of the patch proposed in this thread.
Alessio
Greg KH
maintainerQuoted 65 lines · Alessio Balsini
Quoted 64 lines · Greg KH
Quoted 51 lines · Alessio Balsini
Quoted 50 lines · Greg KH
Quoted 40 lines · Alessio Balsini
From: WANG Cong <[email protected]>
[ Upstream commit
199ab00f3cdb6f154ea93fa76fd80192861a821d]Andrey reported a out-of-bound access in
ip6_tnl_xmit(), this is because we use an ipv4 dst inip6_tnl_xmit()and cast an IPv4 neigh key as an IPv6 address:neigh = dst_neigh_lookup(skb_dst(skb), &ipv6_hdr(skb)->daddr); if (!neigh) goto tx_err_link_failure; addr6 = (struct in6_addr *)&neigh->primary_key; // <=== HERE addr_type = ipv6_addr_type(addr6); if (addr_type == IPV6_ADDR_ANY) addr6 = &ipv6_hdr(skb)->daddr; memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));Also the network header of the skb at this point should be still IPv4 for 4in6 tunnels, we shold not just use it as IPv6 header.
This patch fixes it by checking if
skb->protocolisETH_P_IPV6: if it is, we are safe to do the nexthop lookup usingskb_dst()and ipv6_hdr(skb)->daddr; if not (aka IPv4), we have no clue about which dest address we can pick here, we have to rely on callers to fill it from tunnel config, so just fall toip6_route_output()to make the decision.Fixes ea3dc9601bda ("ip6_tunnel: Add support for wildcard tunnel endpoints.")Reported-by Andrey Konovalov <[email protected]>Reported-by [email protected]Tested-by Andrey Konovalov <[email protected]>Cc Steffen Klassert <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Alessio Balsini <[email protected]>Quoted 3 lines
--- net/ipv6/ip6_tunnel.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)This was already applied to the 4.4.66 kernel release
But this patch applies to the 4.4.y tree. Which is really really odd, what is going on here?
Quoted 8 lines
Quoted 3 lines
confused,
greg k-h
Totally odd... Now that you gave me this heads up, I can see that the patch was applied to v4.4.66 and for some reason dropped since v4.4.118.
Can you please take a look? Thanks!
What dropped it? Fixes that resolved other things? Are you sure this is still needed?
Quoted 8 lines
Quoted 3 lines
That's all I can tell, you can see the kernel branch as well as I can :)
greg k-h
It looks like upstream
607f725f6f7d(net: replacedst_cacheip6_tunnelimplementation with the generic one), had some extra code removed when backported asb8c7f80cbdcdin v4.4.118, resulting in a complete, hidden revert of the patch proposed in this thread.
Odd, ok, I've queued this up now, thanks!
greg k-h