mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: rusty@rustcorp.com.au, adam@yggdrasil.com, jcm@jonmasters.org,
	kaber@trash.net, netfilter-devel@lists.netfilter.org,
	linux-kernel@vger.kernel.org
Cc: nhorman@tuxdriver.com
Subject: [PATCH 0/2] Fix (improve) deadlock condition on module removal netfilter socket option removal
Date: Tue, 4 Sep 2007 16:24:33 -0400	[thread overview]
Message-ID: <20070904202433.GA19083@hmsreliant.think-freely.org> (raw)

Hey all-
	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.... :) ).

The following 2 patches have been tested out by me.

Thanks & Regards
Neil

-- 
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *nhorman@tuxdriver.com
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/

             reply	other threads:[~2007-09-04 20:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-04 20:24 Neil Horman [this message]
2007-09-05 15:22 ` Patrick McHardy
2007-09-05 16:13   ` Rusty Russell
2007-09-05 17:08     ` Neil Horman
2007-09-05 17:41       ` Rusty Russell
2007-09-05 18:19         ` Jon Masters
2007-09-05 19:27         ` Neil Horman
2007-09-05 20:17           ` Jon Masters
2007-09-05 20:51           ` Rusty Russell
2007-09-05 20:59             ` Jon Masters
2007-09-05 21:39           ` Jon Masters
2007-09-06  0:17             ` Neil Horman
2007-09-06 12:55             ` Neil Horman
2007-09-06 13:35               ` Jon Masters
2007-09-06 15:40                 ` Neil Horman
2007-09-06 10:33       ` Patrick McHardy
2007-09-06 11:08         ` Neil Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070904202433.GA19083@hmsreliant.think-freely.org \
    --to=nhorman@tuxdriver.com \
    --cc=adam@yggdrasil.com \
    --cc=jcm@jonmasters.org \
    --cc=kaber@trash.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®