1
linux/net/ipv4/ipvs
Neil Horman 16fcec35e7 [NETFILTER]: Fix/improve deadlock condition on module removal netfilter
So I've had a deadlock reported to me.  I've found that the sequence of
events goes like this:

1) process A (modprobe) runs to remove ip_tables.ko

2) process B (iptables-restore) runs and calls setsockopt on a netfilter socket,
increasing the ip_tables socket_ops use count

3) process A acquires a file lock on the file ip_tables.ko, calls remove_module
in the kernel, which in turn executes the ip_tables module cleanup routine,
which calls nf_unregister_sockopt

4) nf_unregister_sockopt, seeing that the use count is non-zero, puts the
calling process into uninterruptible sleep, expecting the process using the
socket option code to wake it up when it exits the kernel

4) the user of the socket option code (process B) in do_ipt_get_ctl, calls
ipt_find_table_lock, which in this case calls request_module to load
ip_tables_nat.ko

5) request_module forks a copy of modprobe (process C) to load the module and
blocks until modprobe exits.

6) Process C. forked by request_module process the dependencies of
ip_tables_nat.ko, of which ip_tables.ko is one.

7) Process C attempts to lock the request module and all its dependencies, it
blocks when it attempts to lock ip_tables.ko (which was previously locked in
step 3)

Theres not really any great permanent solution to this that I can see, but I've
developed a two part solution that corrects the problem

Part 1) Modifies the nf_sockopt registration code so that, instead of using a
use counter internal to the nf_sockopt_ops structure, we instead use a pointer
to the registering modules owner to do module reference counting when nf_sockopt
calls a modules set/get routine.  This prevents the deadlock by preventing set 4
from happening.

Part 2) Enhances the modprobe utilty so that by default it preforms non-blocking
remove operations (the same way rmmod does), and add an option to explicity
request blocking operation.  So if you select blocking operation in modprobe you
can still cause the above deadlock, but only if you explicity try (and since
root can do any old stupid thing it would like....  :)  ).

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-09-11 11:28:26 +02:00
..
ip_vs_app.c [NET]: Make all initialized struct seq_operations const. 2007-07-10 23:07:31 -07:00
ip_vs_conn.c mm: Remove slab destructors from kmem_cache_create(). 2007-07-20 10:11:58 +09:00
ip_vs_core.c [NET]: Treat CHECKSUM_PARTIAL as CHECKSUM_UNNECESSARY 2007-04-25 22:28:43 -07:00
ip_vs_ctl.c [NETFILTER]: Fix/improve deadlock condition on module removal netfilter 2007-09-11 11:28:26 +02:00
ip_vs_dh.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_est.c [NET]: Conversions from kmalloc+memset to k(z|c)alloc. 2006-07-21 14:51:30 -07:00
ip_vs_ftp.c [SK_BUFF]: Convert skb->tail to sk_buff_data_t 2007-04-25 22:26:28 -07:00
ip_vs_lblc.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_lblcr.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_lc.c
ip_vs_nq.c
ip_vs_proto_ah.c [NET] IPV4: Use hton{s,l}() where appropriate. 2007-04-25 22:23:58 -07:00
ip_vs_proto_esp.c [INET_SOCK]: Move struct inet_sock & helper functions to net/inet_sock.h 2006-01-03 13:11:21 -08:00
ip_vs_proto_tcp.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_proto_udp.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_proto.c [IPVS]: Use kmemdup where appropriate 2006-12-02 21:30:16 -08:00
ip_vs_rr.c [NET] IPV4: Fix whitespace errors. 2007-02-10 23:19:39 -08:00
ip_vs_sched.c [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
ip_vs_sed.c Fix occurrences of "the the " 2007-05-09 08:57:56 +02:00
ip_vs_sh.c [SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph 2007-04-25 22:25:10 -07:00
ip_vs_sync.c [IPVS]: Fix state variable on failure to start ipvs threads 2007-06-18 22:33:20 -07:00
ip_vs_wlc.c
ip_vs_wrr.c
ip_vs_xmit.c [IPVS]: Use skb_forward_csum 2007-07-31 02:28:11 -07:00
Kconfig [IPVS]: Use menuconfig objects. 2007-05-24 16:36:47 -07:00
Makefile