]> git.itanic.dy.fi Git - linux-stable/commit
tun: fix a memory leak for tfile->tx_array
authorCong Wang <xiyou.wangcong@gmail.com>
Mon, 15 Jan 2018 19:37:29 +0000 (11:37 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jan 2018 13:03:47 +0000 (14:03 +0100)
commit51c1f513fe965c5136be85d8af46d99166e0b121
tree10b7c51296eb22921a13da9e7397515041ffd023
parent8496f7dbb1e5210e272b3a0e6f1fd20c28c8890e
tun: fix a memory leak for tfile->tx_array

[ 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.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: 1576d9860599 ("tun: switch to use skb array for tx")
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/tun.c