linux/net/bridge/netfilter
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
..
Kconfig [NETFILTER] ebtables: Support nf_log API from ebt_log and ebt_ulog 2006-01-03 13:10:30 -08:00
Makefile [NETFILTER]: Fix wrong option spelling in Makefile for CONFIG_BRIDGE_EBT_ULOG 2006-03-11 18:51:25 -08:00
ebt_802_3.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_among.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_arp.c [NETFILTER]: ebt_arp: add gratuitous arp filtering 2007-04-25 22:28:58 -07:00
ebt_arpreply.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_dnat.c [NETFILTER]: Rename init functions. 2006-03-28 17:02:48 -08:00
ebt_ip.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_limit.c [NETFILTER]: Rename init functions. 2006-03-28 17:02:48 -08:00
ebt_log.c [NETFILTER]: Clean up duplicate includes in net/bridge/ 2007-07-24 15:30:30 -07:00
ebt_mark.c [NETFILTER]: ebtables: add --snap-arp option 2006-12-02 21:31:32 -08:00
ebt_mark_m.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_pkttype.c [NETFILTER]: Rename init functions. 2006-03-28 17:02:48 -08:00
ebt_redirect.c [NETFILTER]: Rename init functions. 2006-03-28 17:02:48 -08:00
ebt_snat.c [NETFILTER]: ebtables: add --snap-arp option 2006-12-02 21:31:32 -08:00
ebt_stp.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebt_ulog.c [NETFILTER]: Clean up duplicate includes in net/bridge/ 2007-07-24 15:30:30 -07:00
ebt_vlan.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebtable_broute.c [EBTABLES]: Split ebt_replace into user and kernel variants, annotate. 2006-12-02 21:32:05 -08:00
ebtable_filter.c [NET] BRIDGE: Fix whitespace errors. 2007-02-10 23:19:23 -08:00
ebtable_nat.c [EBTABLES]: Split ebt_replace into user and kernel variants, annotate. 2006-12-02 21:32:05 -08:00
ebtables.c [NETFILTER]: Fix/improve deadlock condition on module removal netfilter 2007-09-11 11:28:26 +02:00