netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: David Miller <davem@davemloft.net>
Cc: jarkao2@gmail.com, marcel@holtmann.org, netdev@vger.kernel.org,
	mingo@elte.hu, tgraf@suug.ch
Subject: Re: netlink circular locking dependency
Date: Wed, 18 Jun 2008 10:52:30 +0200	[thread overview]
Message-ID: <4858CCCE.7060404@trash.net> (raw)
In-Reply-To: <20080617.213012.132043917.davem@davemloft.net>

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

David Miller wrote:
> In the meantime should I apply Patrick's current patch
> from this thread?

I think that makes sense, the module unload race is present anyway.
>
> If so I'd like a proper commit message and signoff, thanks!

Attached the patch with a proper changelog.






[-- Attachment #2: x --]
[-- Type: text/plain, Size: 2251 bytes --]

netlink: genl: fix circular locking

genetlink has a circular locking dependency when dumping the registered
families:

- dump start:
genl_rcv()            : take genl_mutex
genl_rcv_msg()        : call netlink_dump_start() while holding genl_mutex
netlink_dump_start(),
netlink_dump()        : take nlk->cb_mutex
ctrl_dumpfamily()     : try to detect this case and not take genl_mutex a
                        second time

- dump continuance:
netlink_rcv()         : call netlink_dump
netlink_dump          : take nlk->cb_mutex
ctrl_dumpfamily()     : take genl_mutex

Register genl_lock as callback mutex with netlink to fix this. This slightly
widens an already existing module unload race, the genl ops used during the
dump might go away when the module is unloaded. Thomas Graf is working on a
seperate fix for this.

Signed-off-by: Patrick McHardy <kaber@trash.net>
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f5aa23c..3e1191c 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -444,8 +444,11 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		if (ops->dumpit == NULL)
 			return -EOPNOTSUPP;
 
-		return netlink_dump_start(genl_sock, skb, nlh,
-					  ops->dumpit, ops->done);
+		genl_unlock();
+		err = netlink_dump_start(genl_sock, skb, nlh,
+					 ops->dumpit, ops->done);
+		genl_lock();
+		return err;
 	}
 
 	if (ops->doit == NULL)
@@ -603,9 +606,6 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
 	int chains_to_skip = cb->args[0];
 	int fams_to_skip = cb->args[1];
 
-	if (chains_to_skip != 0)
-		genl_lock();
-
 	for (i = 0; i < GENL_FAM_TAB_SIZE; i++) {
 		if (i < chains_to_skip)
 			continue;
@@ -623,9 +623,6 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
 	}
 
 errout:
-	if (chains_to_skip != 0)
-		genl_unlock();
-
 	cb->args[0] = i;
 	cb->args[1] = n;
 
@@ -770,7 +767,7 @@ static int __init genl_init(void)
 
 	/* we'll bump the group number right afterwards */
 	genl_sock = netlink_kernel_create(&init_net, NETLINK_GENERIC, 0,
-					  genl_rcv, NULL, THIS_MODULE);
+					  genl_rcv, &genl_mutex, THIS_MODULE);
 	if (genl_sock == NULL)
 		panic("GENL: Cannot initialize generic netlink\n");
 

  parent reply	other threads:[~2008-06-18  8:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-14 12:35 netlink circular locking dependency Marcel Holtmann
2008-06-16 21:34 ` Jarek Poplawski
2008-06-16 21:48   ` Patrick McHardy
2008-06-17  1:45     ` Marcel Holtmann
2008-06-17 12:50       ` Patrick McHardy
2008-06-17 13:09         ` Jarek Poplawski
2008-06-17 13:07           ` Patrick McHardy
2008-06-17 13:24             ` Jarek Poplawski
2008-06-17 13:27               ` Patrick McHardy
2008-06-17 13:43                 ` Jarek Poplawski
2008-06-18  4:30                   ` David Miller
2008-06-18  6:15                     ` Jarek Poplawski
2008-06-18  8:52                     ` Patrick McHardy [this message]
2008-06-18  9:08                       ` David Miller
2008-06-18 11:38                         ` Marcel Holtmann
2008-06-18 11:42                           ` Patrick McHardy
2008-06-17 13:08           ` Thomas Graf
2008-06-17 13:19             ` Patrick McHardy
2008-06-17  8:49     ` Jarek Poplawski

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=4858CCCE.7060404@trash.net \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=jarkao2@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /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;
as well as URLs for NNTP newsgroup(s).