Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1429268

[PATCH 4.6 08/81] tuntap: correctly wake up process during uninit

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.6 08/81] tuntap: correctly wake up process during uninit
Date 2016-06-23 01:10 +0200
Message-ID <rMZrt-1su-71@gated-at.bofh.it> (permalink)
References <rMZ85-15H-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.6-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Jason Wang <jasowang@redhat.com>

[ Upstream commit addf8fc4acb1cf79492ac64966f07178793cb3d7 ]

We used to check dev->reg_state against NETREG_REGISTERED after each
time we are woke up. But after commit 9e641bdcfa4e ("net-tun:
restructure tun_do_read for better sleep/wakeup efficiency"), it uses
skb_recv_datagram() which does not check dev->reg_state. This will
result if we delete a tun/tap device after a process is blocked in the
reading. The device will wait for the reference count which was held
by that process for ever.

Fixes this by using RCV_SHUTDOWN which will be checked during
sk_recv_datagram() before trying to wake up the process during uninit.

Fixes: 9e641bdcfa4e ("net-tun: restructure tun_do_read for better
sleep/wakeup efficiency")
Cc: Eric Dumazet <edumazet@google.com>
Cc: Xi Wang <xii@google.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/tun.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -568,11 +568,13 @@ static void tun_detach_all(struct net_de
 	for (i = 0; i < n; i++) {
 		tfile = rtnl_dereference(tun->tfiles[i]);
 		BUG_ON(!tfile);
+		tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN;
 		tfile->socket.sk->sk_data_ready(tfile->socket.sk);
 		RCU_INIT_POINTER(tfile->tun, NULL);
 		--tun->numqueues;
 	}
 	list_for_each_entry(tfile, &tun->disabled, next) {
+		tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN;
 		tfile->socket.sk->sk_data_ready(tfile->socket.sk);
 		RCU_INIT_POINTER(tfile->tun, NULL);
 	}
@@ -628,6 +630,7 @@ static int tun_attach(struct tun_struct
 			goto out;
 	}
 	tfile->queue_index = tun->numqueues;
+	tfile->socket.sk->sk_shutdown &= ~RCV_SHUTDOWN;
 	rcu_assign_pointer(tfile->tun, tun);
 	rcu_assign_pointer(tun->tfiles[tun->numqueues], tfile);
 	tun->numqueues++;
@@ -1425,9 +1428,6 @@ static ssize_t tun_do_read(struct tun_st
 	if (!iov_iter_count(to))
 		return 0;
 
-	if (tun->dev->reg_state != NETREG_REGISTERED)
-		return -EIO;
-
 	/* Read frames from queue */
 	skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0,
 				  &peeked, &off, &err);

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.6 00/81] 4.6.3-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 12/81] ipv4: Fix non-initialized TTL when CONFIG_SYSCTL=n Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 25/81] l2tp: fix configuration passed to setup_udp_tunnel_sock() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 40/81] gpiolib: Fix NULL pointer deference Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 27/81] KVM: arm/arm64: vgic-v2: Clear all dirty LRs Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 13/81] bpf, inode: disallow userns mounts Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 45/81] crypto: public_key: select CRYPTO_AKCIPHER Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 09/81] bpf: Use mount_nodev not mount_ns to mount the bpf filesystem Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 19/81] net: stmmac: Fix incorrect memcpy source memory Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 23/81] tcp: record TLP and ER timer stats in v6 stats Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 02/81] scsi: Add QEMU CD-ROM to VPD Inquiry Blacklist Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 43/81] s390/bpf: reduce maximum program size to 64 KB Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 28/81] KVM: arm/arm64: vgic-v3: Clear all dirty LRs Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 15/81] net: hwbm: Fix unbalanced spinlock in error case Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 08/81] tuntap: correctly wake up process during uninit Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 01:10 +0200
  [PATCH 4.6 00/87] 4.6.3-stable review -rc2 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-06-23 07:00 +0200
  Re: [PATCH 4.6 38/81] gpio: bail out silently on NULL descriptors Linus Walleij <linus.walleij@linaro.org> - 2016-06-23 09:30 +0200
    Re: [PATCH 4.6 38/81] gpio: bail out silently on NULL descriptors Hans de Goede <hdegoede@redhat.com> - 2016-06-23 11:20 +0200

csiph-web