Skip to content

Commit 8d9f13d

Browse files
Wei Yongjungregkh
authored andcommitted
ip6_gre: fix null-ptr-deref in ip6gre_init_net()
[ Upstream commit 46ef5b8 ] KASAN report null-ptr-deref error when register_netdev() failed: KASAN: null-ptr-deref in range [0x00000000000003c0-0x00000000000003c7] CPU: 2 PID: 422 Comm: ip Not tainted 5.8.0-rc4+ #12 Call Trace: ip6gre_init_net+0x4ab/0x580 ? ip6gre_tunnel_uninit+0x3f0/0x3f0 ops_init+0xa8/0x3c0 setup_net+0x2de/0x7e0 ? rcu_read_lock_bh_held+0xb0/0xb0 ? ops_init+0x3c0/0x3c0 ? kasan_unpoison_shadow+0x33/0x40 ? __kasan_kmalloc.constprop.0+0xc2/0xd0 copy_net_ns+0x27d/0x530 create_new_namespaces+0x382/0xa30 unshare_nsproxy_namespaces+0xa1/0x1d0 ksys_unshare+0x39c/0x780 ? walk_process_tree+0x2a0/0x2a0 ? trace_hardirqs_on+0x4a/0x1b0 ? _raw_spin_unlock_irq+0x1f/0x30 ? syscall_trace_enter+0x1a7/0x330 ? do_syscall_64+0x1c/0xa0 __x64_sys_unshare+0x2d/0x40 do_syscall_64+0x56/0xa0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ip6gre_tunnel_uninit() has set 'ign->fb_tunnel_dev' to NULL, later access to ign->fb_tunnel_dev cause null-ptr-deref. Fix it by saving 'ign->fb_tunnel_dev' to local variable ndev. Fixes: dafabb6 ("ip6_gre: fix use-after-free in ip6gre_tunnel_lookup()") Reported-by: Hulk Robot <[email protected]> Signed-off-by: Wei Yongjun <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fbcd85c commit 8d9f13d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/ipv6/ip6_gre.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,17 +1560,18 @@ static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head)
15601560
static int __net_init ip6gre_init_net(struct net *net)
15611561
{
15621562
struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1563+
struct net_device *ndev;
15631564
int err;
15641565

15651566
if (!net_has_fallback_tunnels(net))
15661567
return 0;
1567-
ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0",
1568-
NET_NAME_UNKNOWN,
1569-
ip6gre_tunnel_setup);
1570-
if (!ign->fb_tunnel_dev) {
1568+
ndev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0",
1569+
NET_NAME_UNKNOWN, ip6gre_tunnel_setup);
1570+
if (!ndev) {
15711571
err = -ENOMEM;
15721572
goto err_alloc_dev;
15731573
}
1574+
ign->fb_tunnel_dev = ndev;
15741575
dev_net_set(ign->fb_tunnel_dev, net);
15751576
/* FB netdevice is special: we have one, and only one per netns.
15761577
* Allowing to move it to another netns is clearly unsafe.
@@ -1590,7 +1591,7 @@ static int __net_init ip6gre_init_net(struct net *net)
15901591
return 0;
15911592

15921593
err_reg_dev:
1593-
free_netdev(ign->fb_tunnel_dev);
1594+
free_netdev(ndev);
15941595
err_alloc_dev:
15951596
return err;
15961597
}

0 commit comments

Comments
 (0)