Skip to contentSkip to conversation

tuntap: correctly handle error in tun_set_iff()

PATCH In review Jason Wang 3 participants 3 messages Sep 11, 2013 – Sep 12, 2013

Subsystems (3)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v2 1/1 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.

---
- Changes from V1: shift 1 space for label err_free_netdev and keep commit log under 70 chars per line.
- The patch were needed for stable kernel 3.8+.

---
 drivers/net/tun.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/tun.c +8 -3
index a639de8..807815f 100644
@@ -1641,11 +1641,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		INIT_LIST_HEAD(&tun->disabled);
 		err = tun_attach(tun, file, false);
 		if (err < 0)
-			goto err_free_dev;
+			goto err_free_flow;
 
 		err = register_netdevice(tun->dev);
 		if (err < 0)
-			goto err_free_dev;
+			goto err_detach;
 
 		if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
 		    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)
 	strcpy(ifr->ifr_name, tun->dev->name);
 	return 0;
 
- err_free_dev:
+err_detach:
+	tun_detach_all(dev);
+err_free_flow:
+	tun_flow_uninit(tun);
+	security_tun_dev_free_security(tun->security);
+err_free_dev:
 	free_netdev(dev);
 	return err;
 }
Signature · 1 line
1.7.1
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · Jason Wang

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

Quoted 5 lines

This patch solves the above issues.

Quoted 42 lines

---
- Changes from V1: shift 1 space for label err_free_netdev and keep commit log under 70 chars per line.
- The patch were needed for stable kernel 3.8+.

---
 drivers/net/tun.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/tun.c +8 -3
index a639de8..807815f 100644
@@ -1641,11 +1641,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		INIT_LIST_HEAD(&tun->disabled);
 		err = tun_attach(tun, file, false);
 		if (err < 0)
-			goto err_free_dev;
+			goto err_free_flow;
 
 		err = register_netdevice(tun->dev);
 		if (err < 0)
-			goto err_free_dev;
+			goto err_detach;
 
 		if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
 		    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)
 	strcpy(ifr->ifr_name, tun->dev->name);
 	return 0;
 
- err_free_dev:
+err_detach:
+	tun_detach_all(dev);
+err_free_flow:
+	tun_flow_uninit(tun);
+	security_tun_dev_free_security(tun->security);
+err_free_dev:
 	free_netdev(dev);
 	return err;
 }
Signature · 1 line
1.7.1
maintainer
#2 lore raw

From: "Michael S. Tsirkin" <[email protected]>
Date: Wed, 11 Sep 2013 13:43:50 +0300

Quoted 9 lines · Jason Wang
Quoted 8 lines

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

Quoted 7 lines
Quoted 5 lines

This patch solves the above issues.

Applied and queued up for -stable, thanks.