aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/tun.c3
-rw-r--r--include/linux/net.h1
-rw-r--r--net/socket.c3
3 files changed, 7 insertions, 0 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 961fad1f7053..f3a454c3295a 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -358,6 +358,8 @@ static void tun_free_netdev(struct net_device *dev)
358{ 358{
359 struct tun_struct *tun = netdev_priv(dev); 359 struct tun_struct *tun = netdev_priv(dev);
360 360
361 BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags));
362
361 sk_release_kernel(tun->socket.sk); 363 sk_release_kernel(tun->socket.sk);
362} 364}
363 365
@@ -1115,6 +1117,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1115 tun->flags = flags; 1117 tun->flags = flags;
1116 tun->txflt.count = 0; 1118 tun->txflt.count = 0;
1117 tun->vnet_hdr_sz = sizeof(struct virtio_net_hdr); 1119 tun->vnet_hdr_sz = sizeof(struct virtio_net_hdr);
1120 set_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags);
1118 1121
1119 err = -ENOMEM; 1122 err = -ENOMEM;
1120 sk = sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, &tun_proto); 1123 sk = sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, &tun_proto);
diff --git a/include/linux/net.h b/include/linux/net.h
index e9ac2df079ba..dc95700de5df 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -72,6 +72,7 @@ struct net;
72#define SOCK_NOSPACE 2 72#define SOCK_NOSPACE 2
73#define SOCK_PASSCRED 3 73#define SOCK_PASSCRED 3
74#define SOCK_PASSSEC 4 74#define SOCK_PASSSEC 4
75#define SOCK_EXTERNALLY_ALLOCATED 5
75 76
76#ifndef ARCH_HAS_SOCKET_TYPES 77#ifndef ARCH_HAS_SOCKET_TYPES
77/** 78/**
diff --git a/net/socket.c b/net/socket.c
index 6e0ccc09b313..0452dca4cd24 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -522,6 +522,9 @@ void sock_release(struct socket *sock)
522 if (rcu_dereference_protected(sock->wq, 1)->fasync_list) 522 if (rcu_dereference_protected(sock->wq, 1)->fasync_list)
523 printk(KERN_ERR "sock_release: fasync list not empty!\n"); 523 printk(KERN_ERR "sock_release: fasync list not empty!\n");
524 524
525 if (test_bit(SOCK_EXTERNALLY_ALLOCATED, &sock->flags))
526 return;
527
525 this_cpu_sub(sockets_in_use, 1); 528 this_cpu_sub(sockets_in_use, 1);
526 if (!sock->file) { 529 if (!sock->file) {
527 iput(SOCK_INODE(sock)); 530 iput(SOCK_INODE(sock));