netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3.8-rc] tuntap: refuse to re-attach to different tun_struct
@ 2013-01-10  7:59 Stefan Hajnoczi
  2013-01-10  9:25 ` Jason Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stefan Hajnoczi @ 2013-01-10  7:59 UTC (permalink / raw)
  To: David S. Miller
  Cc: Jason Wang, Michael S. Tsirkin, netdev, linux-kernel,
	Stefan Hajnoczi

Multiqueue tun devices support detaching a tun_file from its tun_struct
and re-attaching at a later point in time.  This allows users to disable
a specific queue temporarily.

ioctl(TUNSETIFF) allows the user to specify the network interface to
attach by name.  This means the user can attempt to attach to interface
"B" after detaching from interface "A".

The driver is not designed to support this so check we are re-attaching
to the right tun_struct.  Failure to do so may lead to oops.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
This fix is for 3.8-rc.

 drivers/net/tun.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index fbd106e..cf6da6e 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -491,6 +491,8 @@ static int tun_attach(struct tun_struct *tun, struct file *file)
 	err = -EINVAL;
 	if (rcu_dereference_protected(tfile->tun, lockdep_rtnl_is_held()))
 		goto out;
+	if (tfile->detached && tun != tfile->detached)
+		goto out;
 
 	err = -EBUSY;
 	if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1)
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-01-11  8:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10  7:59 [PATCH 3.8-rc] tuntap: refuse to re-attach to different tun_struct Stefan Hajnoczi
2013-01-10  9:25 ` Jason Wang
2013-01-10 10:23 ` Michael S. Tsirkin
2013-01-10 10:43   ` Jason Wang
2013-01-10 11:07     ` Michael S. Tsirkin
2013-01-10 13:53       ` Jason Wang
2013-01-10 11:53   ` Stefan Hajnoczi
2013-01-10 22:39 ` David Miller
2013-01-11  1:29   ` Jason Wang
2013-01-11  5:12     ` David Miller
2013-01-11  8:38       ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).