diff options
| author | Jason Wang <jasowang@redhat.com> | 2013-09-11 06:09:48 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2013-09-12 17:21:42 -0400 |
| commit | 662ca437e714caaab855b12415d6ffd815985bc0 (patch) | |
| tree | c8b6eccc605fe52837e21d72bdecbf8e0c71b539 | |
| parent | a9677bc024dcaafcf36c1cc4b0706b87be26ee5f (diff) | |
tuntap: correctly handle error in tun_set_iff()
Commit c8d68e6be1c3b242f1c598595830890b65cea64a
(tuntap: multiqueue support) only call free_netdev() on error in
tun_set_iff(). This causes several issues:
- memory of tun security were leaked
- use after free since the flow gc timer was not deleted and the tfile
were not detached
This patch solves the above issues.
Reported-by: Wannes Rombouts <wannes.rombouts@epitech.eu>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | drivers/net/tun.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index a639de8401f8..807815fc9968 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
| @@ -1641,11 +1641,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
| 1641 | INIT_LIST_HEAD(&tun->disabled); | 1641 | INIT_LIST_HEAD(&tun->disabled); |
| 1642 | err = tun_attach(tun, file, false); | 1642 | err = tun_attach(tun, file, false); |
| 1643 | if (err < 0) | 1643 | if (err < 0) |
| 1644 | goto err_free_dev; | 1644 | goto err_free_flow; |
| 1645 | 1645 | ||
| 1646 | err = register_netdevice(tun->dev); | 1646 | err = register_netdevice(tun->dev); |
| 1647 | if (err < 0) | 1647 | if (err < 0) |
| 1648 | goto err_free_dev; | 1648 | goto err_detach; |
| 1649 | 1649 | ||
| 1650 | if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || | 1650 | if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || |
| 1651 | device_create_file(&tun->dev->dev, &dev_attr_owner) || | 1651 | device_create_file(&tun->dev->dev, &dev_attr_owner) || |
| @@ -1689,7 +1689,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
| 1689 | strcpy(ifr->ifr_name, tun->dev->name); | 1689 | strcpy(ifr->ifr_name, tun->dev->name); |
| 1690 | return 0; | 1690 | return 0; |
| 1691 | 1691 | ||
| 1692 | err_free_dev: | 1692 | err_detach: |
| 1693 | tun_detach_all(dev); | ||
| 1694 | err_free_flow: | ||
| 1695 | tun_flow_uninit(tun); | ||
| 1696 | security_tun_dev_free_security(tun->security); | ||
| 1697 | err_free_dev: | ||
| 1693 | free_netdev(dev); | 1698 | free_netdev(dev); |
| 1694 | return err; | 1699 | return err; |
| 1695 | } | 1700 | } |
