]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
sit: proper dev_{hold|put} in ndo_[un]init methods
authorEric Dumazet <edumazet@google.com>
Mon, 29 Mar 2021 19:25:22 +0000 (12:25 -0700)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 29 Jun 2021 14:02:54 +0000 (16:02 +0200)
BugLink: https://bugs.launchpad.net/bugs/1933969
commit 6289a98f0817a4a457750d6345e754838eae9439 upstream.

After adopting CONFIG_PCPU_DEV_REFCNT=n option, syzbot was able to trigger
a warning [1]

Issue here is that:

- all dev_put() should be paired with a corresponding prior dev_hold().

- A driver doing a dev_put() in its ndo_uninit() MUST also
  do a dev_hold() in its ndo_init(), only when ndo_init()
  is returning 0.

Otherwise, register_netdevice() would call ndo_uninit()
in its error path and release a refcount too soon.

Fixes: 919067cc845f ("net: add CONFIG_PCPU_DEV_REFCNT")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
net/ipv6/sit.c

index 9fdccf0718b59ccb91a8d72341bb3f5cd122f06f..d9ac881b2baacd56e608d0abd6aaa45f513552dc 100644 (file)
@@ -218,8 +218,6 @@ static int ipip6_tunnel_create(struct net_device *dev)
 
        ipip6_tunnel_clone_6rd(dev, sitn);
 
-       dev_hold(dev);
-
        ipip6_tunnel_link(sitn, t);
        return 0;
 
@@ -1456,7 +1454,7 @@ static int ipip6_tunnel_init(struct net_device *dev)
                dev->tstats = NULL;
                return err;
        }
-
+       dev_hold(dev);
        return 0;
 }