Patch "tun: fix a memory leak for tfile->tx_array" has been added to the 4.14-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
tun: fix a memory leak for tfile->tx_array
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
tun-fix-a-memory-leak-for-tfile-tx_array.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Sun Jan 28 17:35:08 CET 2018
From: Cong Wang <[email protected]>
Date: Mon, 15 Jan 2018 11:37:29 -0800
Subject: tun: fix a memory leak for tfile->tx_array
From: Cong Wang <[email protected]>
[ Upstream commit 4df0bfc79904b7169dc77dcce44598b1545721f9 ]
tfile->tun could be detached before we close the tun fd, via tun_detach_all(), so it should not be used to check for tfile->tx_array.
As Jason suggested, we probably have to clean it up unconditionally both in __tun_deatch() and tun_detach_all(), but this requires to check if it is initialized or not. Currently skb_array_cleanup() doesn't have such a check, so I check it in the caller and introduce a helper function, it is a bit ugly but we can always improve it in net-next.
--- drivers/net/tun.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/tun.c +13 -2
@@ -534,6 +534,14 @@ static void tun_queue_purge(struct tun_fskb_queue_purge (&tfile->sk.sk_error_queue); } +static void tun_cleanup_tx_array (struct tun_file *tfile) +{ +if (tfile->tx_array.ring.queue) { +skb_array_cleanup (&tfile->tx_array); +memset (&tfile->tx_array,0 ,sizeof (tfile->tx_array)); + } +} +static void __tun_detach (struct tun_file *tfile,bool clean) {struct tun_file *ntfile;
@@ -575,8 +583,7 @@ static void __tun_detach(struct tun_file tun->dev->reg_state == NETREG_REGISTERED)unregister_netdevice (tun->dev); } -if (tun) -skb_array_cleanup (&tfile->tx_array); +tun_cleanup_tx_array (tfile);sock_put (&tfile->sk); } }
@@ -616,11 +623,13 @@ static void tun_detach_all(struct net_de/* Drop read queue */ tun_queue_purge (tfile);sock_put (&tfile->sk); +tun_cleanup_tx_array (tfile); }list_for_each_entry_safe (tfile, tmp, &tun->disabled, next) {tun_enable_queue (tfile);tun_queue_purge (tfile);sock_put (&tfile->sk); +tun_cleanup_tx_array (tfile); }BUG_ON (tun->numdisabled !=0 );
@@ -2624,6 +2633,8 @@ static int tun_chr_open(struct inode *insock_set_flag (&tfile->sk,SOCK_ZEROCOPY ); +memset (&tfile->tx_array,0 ,sizeof (tfile->tx_array)); +return 0 ; }
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/tipc-fix-a-memory-leak-in-tipc_nl_node_get_link.patch queue-4.14/tun-fix-a-memory-leak-for-tfile-tx_array.patch