linux-stable/net/ipv6
Taehee Yoo b7e1a9cff6 ip6_gre: fix use-after-free in ip6gre_tunnel_lookup()
[ Upstream commit dafabb6590 ]

In the datapath, the ip6gre_tunnel_lookup() is used and it internally uses
fallback tunnel device pointer, which is fb_tunnel_dev.
This pointer variable should be set to NULL when a fb interface is deleted.
But there is no routine to set fb_tunnel_dev pointer to NULL.
So, this pointer will be still used after interface is deleted and
it eventually results in the use-after-free problem.

Test commands:
    ip netns add A
    ip netns add B
    ip link add eth0 type veth peer name eth1
    ip link set eth0 netns A
    ip link set eth1 netns B

    ip netns exec A ip link set lo up
    ip netns exec A ip link set eth0 up
    ip netns exec A ip link add ip6gre1 type ip6gre local fc:0::1 \
	    remote fc:0::2
    ip netns exec A ip -6 a a fc💯:1/64 dev ip6gre1
    ip netns exec A ip link set ip6gre1 up
    ip netns exec A ip -6 a a fc:0::1/64 dev eth0
    ip netns exec A ip link set ip6gre0 up

    ip netns exec B ip link set lo up
    ip netns exec B ip link set eth1 up
    ip netns exec B ip link add ip6gre1 type ip6gre local fc:0::2 \
	    remote fc:0::1
    ip netns exec B ip -6 a a fc💯:2/64 dev ip6gre1
    ip netns exec B ip link set ip6gre1 up
    ip netns exec B ip -6 a a fc:0::2/64 dev eth1
    ip netns exec B ip link set ip6gre0 up
    ip netns exec A ping fc💯:2 -s 60000 &
    ip netns del B

Splat looks like:
[   73.087285][    C1] BUG: KASAN: use-after-free in ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.088361][    C1] Read of size 4 at addr ffff888040559218 by task ping/1429
[   73.089317][    C1]
[   73.089638][    C1] CPU: 1 PID: 1429 Comm: ping Not tainted 5.7.0+ #602
[   73.090531][    C1] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[   73.091725][    C1] Call Trace:
[   73.092160][    C1]  <IRQ>
[   73.092556][    C1]  dump_stack+0x96/0xdb
[   73.093122][    C1]  print_address_description.constprop.6+0x2cc/0x450
[   73.094016][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.094894][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.095767][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.096619][    C1]  kasan_report+0x154/0x190
[   73.097209][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.097989][    C1]  ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.098750][    C1]  ? gre_del_protocol+0x60/0x60 [gre]
[   73.099500][    C1]  gre_rcv+0x1c5/0x1450 [ip6_gre]
[   73.100199][    C1]  ? ip6gre_header+0xf00/0xf00 [ip6_gre]
[   73.100985][    C1]  ? rcu_read_lock_sched_held+0xc0/0xc0
[   73.101830][    C1]  ? ip6_input_finish+0x5/0xf0
[   73.102483][    C1]  ip6_protocol_deliver_rcu+0xcbb/0x1510
[   73.103296][    C1]  ip6_input_finish+0x5b/0xf0
[   73.103920][    C1]  ip6_input+0xcd/0x2c0
[   73.104473][    C1]  ? ip6_input_finish+0xf0/0xf0
[   73.105115][    C1]  ? rcu_read_lock_held+0x90/0xa0
[   73.105783][    C1]  ? rcu_read_lock_sched_held+0xc0/0xc0
[   73.106548][    C1]  ipv6_rcv+0x1f1/0x300
[ ... ]

Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Fixes: c12b395a46 ("gre: Support GRE over IPv6")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-06-30 15:38:00 -04:00
..
ila License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
netfilter netfilter: masquerade: don't flush all conntracks if only one address deleted on device 2019-11-20 18:00:52 +01:00
addrconf.c ipv6: don't auto-add link-local address to lag ports 2020-04-13 10:34:28 +02:00
addrconf_core.c net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup 2020-05-20 08:17:02 +02:00
addrlabel.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
af_inet6.c net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup 2020-05-20 08:17:02 +02:00
ah6.c
anycast.c
calipso.c netlabel: cope with NULL catmap 2020-05-20 08:17:12 +02:00
datagram.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
esp6.c esp: Skip TX bytes accounting when sending from a request socket 2019-03-23 14:35:14 +01:00
esp6_offload.c esp6: get the right proto for transport mode in esp6_gso_encap 2020-06-03 08:18:09 +02:00
exthdrs.c ipv6: make ipv6_renew_options() interrupt/kernel safe 2018-08-24 13:09:13 +02:00
exthdrs_core.c
exthdrs_offload.c
fib6_notifier.c net: Add module reference to FIB notifiers 2017-09-01 20:33:42 -07:00
fib6_rules.c net: ipv6: avoid overhead when no custom FIB rules are installed 2017-08-08 21:40:08 -07:00
fou6.c
icmp.c net/ipv6: Fix linklocal to global address with VRF 2018-07-28 07:55:42 +02:00
inet6_connection_sock.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
inet6_hashtables.c tcp/dccp: fix possible race __inet_lookup_established() 2020-01-04 14:00:19 +01:00
ip6_checksum.c net: udp: fix handling of CHECKSUM_COMPLETE packets 2018-11-04 14:52:49 +01:00
ip6_fib.c ipv6: Fix route replacement with dev-only route 2020-03-11 18:02:47 +01:00
ip6_flowlabel.c ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero 2019-06-22 08:16:14 +02:00
ip6_gre.c ip6_gre: fix use-after-free in ip6gre_tunnel_lookup() 2020-06-30 15:38:00 -04:00
ip6_icmp.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ip6_input.c ipv6: drop incoming packets having a v4mapped source address 2019-10-07 18:55:16 +02:00
ip6_offload.c gso_segment: Reset skb->mac_len after modifying network header 2018-09-29 03:06:00 -07:00
ip6_offload.h
ip6_output.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
ip6_tunnel.c net, ip6_tunnel: fix namespaces move 2020-01-29 15:02:35 +01:00
ip6_udp_tunnel.c ipv6: explicitly initialize udp6_addr in udp_sock_create6() 2019-01-09 17:14:43 +01:00
ip6_vti.c vti6: Fix memory leak of skb if input policy check fails 2020-04-02 16:34:32 +02:00
ip6mr.c ip6mr: Do not call __IP6_INC_STATS() from preemptible context 2019-03-13 14:03:07 -07:00
ipcomp6.c
ipv6_sockglue.c ipv6: fix IPV6_ADDRFORM operation logic 2020-06-20 10:24:57 +02:00
Kconfig ipv6: ila: select CONFIG_DST_CACHE 2018-07-25 11:25:09 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mcast.c mld: fix memory leak in ipv6_mc_destroy_dev() 2020-06-30 15:37:58 -04:00
mcast_snoop.c
mip6.c
ndisc.c ipv6/ndisc: Preserve IPv6 control buffer if protocol error handlers are called 2018-11-04 14:52:48 +01:00
netfilter.c netfilter: ipv6: Don't preserve original oif for loopback address 2019-02-27 10:08:08 +01:00
output_core.c inet: switch IP ID generator to siphash 2019-06-09 09:18:10 +02:00
ping.c ipv6: Fix the link time qualifier of 'ping_v6_proc_exit_net()' 2019-09-19 09:08:00 +02:00
proc.c inet: frags: break the 2GB limit for frags storage 2018-09-19 22:43:46 +02:00
protocol.c
raw.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
reassembly.c inet: frags: call inet_frags_fini() after unregister_pernet_subsys() 2020-01-27 14:46:36 +01:00
route.c Revert "ipv6: add mtu lock check in __ip6_rt_update_pmtu" 2020-05-20 08:17:12 +02:00
seg6.c ipv6: propagate genlmsg_reply return code 2019-02-27 10:08:06 +01:00
seg6_hmac.c ipv6: sr: fix passing wrong flags to crypto_alloc_shash() 2018-07-22 14:28:43 +02:00
seg6_iptunnel.c ipv6: sr: clear IP6CB(skb) on SRH ip4ip6 encapsulation 2019-02-06 17:31:31 +01:00
seg6_local.c ipv6: sr: remove SKB_GSO_IPXIP6 on End.D* actions 2020-01-29 15:02:35 +01:00
sit.c sit: do not confirm neighbor when do pmtu update 2020-01-04 14:00:17 +01:00
syncookies.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
sysctl_net_ipv6.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tcp_ipv6.c net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
tcpv6_offload.c gso: validate gso_type in GSO handlers 2018-01-31 14:03:47 +01:00
tunnel6.c
udp.c net: annotate accesses to sk->sk_incoming_cpu 2019-11-10 11:25:23 +01:00
udp_impl.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
udp_offload.c gso: validate gso_type in GSO handlers 2018-01-31 14:03:47 +01:00
udplite.c
xfrm6_input.c xfrm: reset transport header back to network header after all input transforms ahave been applied 2018-11-04 14:52:37 +01:00
xfrm6_mode_beet.c
xfrm6_mode_ro.c
xfrm6_mode_transport.c xfrm: reset transport header back to network header after all input transforms ahave been applied 2018-11-04 14:52:37 +01:00
xfrm6_mode_tunnel.c
xfrm6_output.c xfrm: Always set XFRM_TRANSFORMED in xfrm{4,6}_output_finish 2020-05-02 17:24:18 +02:00
xfrm6_policy.c net: add bool confirm_neigh parameter for dst_ops.update_pmtu 2020-01-04 14:00:14 +01:00
xfrm6_protocol.c
xfrm6_state.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xfrm6_tunnel.c xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module 2019-05-25 18:25:34 +02:00