]> git.baikalelectronics.ru Git - kernel.git/commit
tun: fix a crash bug and a memory leak
authorMikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Thu, 19 Jul 2012 06:13:36 +0000 (06:13 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Jul 2012 18:21:06 +0000 (11:21 -0700)
commit4bf0e162b7bde1cbea3aae22142b11a3836cf47e
treee4f12db01edc11d669f32a2d3d6832b22f57f656
parenta2de1e3b612f7b4b059cd10a473334326ea083fc
tun: fix a crash bug and a memory leak

This patch fixes a crash
tun_chr_close -> netdev_run_todo -> tun_free_netdev -> sk_release_kernel ->
sock_release -> iput(SOCK_INODE(sock))
introduced by commit 0e0dc63e592907070c373260d7a216efb823cf57

The problem is that this socket is embedded in struct tun_struct, it has
no inode, iput is called on invalid inode, which modifies invalid memory
and optionally causes a crash.

sock_release also decrements sockets_in_use, this causes a bug that
"sockets: used" field in /proc/*/net/sockstat keeps on decreasing when
creating and closing tun devices.

This patch introduces a flag SOCK_EXTERNALLY_ALLOCATED that instructs
sock_release to not free the inode and not decrement sockets_in_use,
fixing both memory corruption and sockets_in_use underflow.

It should be backported to 3.3 an 3.4 stabke.

Signed-off-by: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Cc: stable@kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c
include/linux/net.h
net/socket.c