From: Cong Wang Subject: [Patch net] tun: fix a memory leak for tfile->tx_array Date: Tue, 9 Jan 2018 16:07:54 -0800 Message-ID: <20180110000754.13545-1-xiyou.wangcong@gmail.com> Cc: dvyukov@google.com, Cong Wang , Jason Wang To: netdev@vger.kernel.org Return-path: Received: from mail-pg0-f68.google.com ([74.125.83.68]:36876 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752066AbeAJAIE (ORCPT ); Tue, 9 Jan 2018 19:08:04 -0500 Received: by mail-pg0-f68.google.com with SMTP id z17so3353624pgc.4 for ; Tue, 09 Jan 2018 16:08:04 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: 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. Use the same logic as in tun_attach(), just test !tfile->deatched. Reported-by: Dmitry Vyukov Fixes: 1576d9860599 ("tun: switch to use skb array for tx") Cc: Jason Wang Signed-off-by: Cong Wang --- drivers/net/tun.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 4f4a842a1c9c..1a1f834440a6 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -613,6 +613,7 @@ static void tun_queue_purge(struct tun_file *tfile) static void __tun_detach(struct tun_file *tfile, bool clean) { + bool clean_tx_array = !tfile->detached; struct tun_file *ntfile; struct tun_struct *tun; @@ -657,7 +658,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean) tun->dev->reg_state == NETREG_REGISTERED) unregister_netdevice(tun->dev); } - if (tun) + if (clean_tx_array) skb_array_cleanup(&tfile->tx_array); sock_put(&tfile->sk); } -- 2.13.0