Commit eeb2b856 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by David S. Miller

[TWSK]: Grab the module refcount for timewait sockets

This is required to avoid unloading a module that has active timewait
sockets, such as DCCP.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2a9bc9bb
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
...@@ -193,11 +194,13 @@ static inline u32 inet_rcv_saddr(const struct sock *sk) ...@@ -193,11 +194,13 @@ static inline u32 inet_rcv_saddr(const struct sock *sk)
static inline void inet_twsk_put(struct inet_timewait_sock *tw) static inline void inet_twsk_put(struct inet_timewait_sock *tw)
{ {
if (atomic_dec_and_test(&tw->tw_refcnt)) { if (atomic_dec_and_test(&tw->tw_refcnt)) {
struct module *owner = tw->tw_prot->owner;
#ifdef SOCK_REFCNT_DEBUG #ifdef SOCK_REFCNT_DEBUG
printk(KERN_DEBUG "%s timewait_sock %p released\n", printk(KERN_DEBUG "%s timewait_sock %p released\n",
tw->tw_prot->name, tw); tw->tw_prot->name, tw);
#endif #endif
kmem_cache_free(tw->tw_prot->twsk_slab, tw); kmem_cache_free(tw->tw_prot->twsk_slab, tw);
module_put(owner);
} }
} }
......
...@@ -111,6 +111,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat ...@@ -111,6 +111,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
tw->tw_prot = sk->sk_prot_creator; tw->tw_prot = sk->sk_prot_creator;
atomic_set(&tw->tw_refcnt, 1); atomic_set(&tw->tw_refcnt, 1);
inet_twsk_dead_node_init(tw); inet_twsk_dead_node_init(tw);
__module_get(tw->tw_prot->owner);
} }
return tw; return tw;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment