tun/tap: Fix crashes if open() /dev/net/tun and then poll() it.
authorMariusz Kozlowski <m.kozlowski@tuxland.pl>
Sun, 5 Jul 2009 19:48:35 +0000 (19:48 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 6 Jul 2009 19:47:07 +0000 (12:47 -0700)
Fix NULL pointer dereference in tun_chr_pool() introduced by commit
33dccbb050bbe35b88ca8cf1228dcf3e4d4b3554 ("tun: Limit amount of queued
packets per device") and triggered by this code:

int fd;
struct pollfd pfd;
fd = open("/dev/net/tun", O_RDWR);
pfd.fd = fd;
pfd.events = POLLIN | POLLOUT;
poll(&pfd, 1, 0);

Reported-by: Eugene Kapun <abacabadabacaba@gmail.com>
Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c

index b393536012fb3c90282c492f4f50f346cbbbc1e6..027f7aba26af1d339dad5081a1ae8167b34c3d8c 100644 (file)
@@ -486,12 +486,14 @@ static unsigned int tun_chr_poll(struct file *file, poll_table * wait)
 {
        struct tun_file *tfile = file->private_data;
        struct tun_struct *tun = __tun_get(tfile);
-       struct sock *sk = tun->sk;
+       struct sock *sk;
        unsigned int mask = 0;
 
        if (!tun)
                return POLLERR;
 
+       sk = tun->sk;
+
        DBG(KERN_INFO "%s: tun_chr_poll\n", tun->dev->name);
 
        poll_wait(file, &tun->socket.wait, wait);