netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily()
@ 2013-08-20 13:50 Sergey Senozhatsky
  2013-08-20 14:03 ` Berg, Johannes
  0 siblings, 1 reply; 3+ messages in thread
From: Sergey Senozhatsky @ 2013-08-20 13:50 UTC (permalink / raw)
  To: David S. Miller
  Cc: Patrick McHardy, Pablo Neira Ayuso, Johannes Berg, Gao feng,
	netdev, linux-kernel

Commmit 58ad436fcf49810aa006016107f494c9ac9013db
Author: Johannes Berg <johannes.berg at intel.com>

    genetlink: fix family dump race

added genl_lock() call to ctrl_dumpfamily(), which potentially
can deadlock. Suppose the following case:

genl_rcv_msg(): !family->parallel_ops -> genl_lock()
	genl_family_rcv_msg()
		netlink_dump_start()
			netlink_dump()
				ctrl_dumpfamily() --> genl_lock()

Take in account possibility of genl_lock() in genl_rcv_msg() and do
not acquire genl_mutex in ctrl_dumpfamily() for a family that supports
parallel_ops.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

---

 net/netlink/genetlink.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f85f8a2..fca3659 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -791,6 +791,12 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
 	int fams_to_skip = cb->args[1];
 	bool need_locking = chains_to_skip || fams_to_skip;
 
+	if (need_locking) {
+		/* genl_mutex could be already locked in genl_rcv_msg() */
+		rt = genl_family_find_byid(cb->nlh->nlmsg_type);
+		need_locking = need_locking && rt->parallel_ops;
+	}
+
 	if (need_locking)
 		genl_lock();
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily()
  2013-08-20 13:50 [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily() Sergey Senozhatsky
@ 2013-08-20 14:03 ` Berg, Johannes
  2013-08-20 19:31   ` Sergey Senozhatsky
  0 siblings, 1 reply; 3+ messages in thread
From: Berg, Johannes @ 2013-08-20 14:03 UTC (permalink / raw)
  To: Sergey Senozhatsky, David S. Miller
  Cc: Patrick McHardy, Pablo Neira Ayuso, Gao feng,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

 
> +	if (need_locking) {
> +		/* genl_mutex could be already locked in genl_rcv_msg() */
> +		rt = genl_family_find_byid(cb->nlh->nlmsg_type);
> +		need_locking = need_locking && rt->parallel_ops;
> +	}

This is equivalent to reverting the patch because parallel_ops will be false for the genl family. :-)

johannes
-- 

Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily()
  2013-08-20 14:03 ` Berg, Johannes
@ 2013-08-20 19:31   ` Sergey Senozhatsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2013-08-20 19:31 UTC (permalink / raw)
  To: Berg, Johannes
  Cc: David S. Miller, Patrick McHardy, Pablo Neira Ayuso, Gao feng,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

On (08/20/13 14:03), Berg, Johannes wrote:
> > +	if (need_locking) {
> > +		/* genl_mutex could be already locked in genl_rcv_msg() */
> > +		rt = genl_family_find_byid(cb->nlh->nlmsg_type);
> > +		need_locking = need_locking && rt->parallel_ops;
> > +	}
> 
> This is equivalent to reverting the patch because parallel_ops will be false for the genl family. :-)
>

sorry, didn't notice that there is already a thread on lkml regarding
this issue. will follow that discussion. the reason was that I see an
actual deadlock on my machine during certain network activities, but
lockdep is silent.

thanks,
	-ss

> johannes
> -- 
> 
> Intel GmbH
> Dornacher Strasse 1
> 85622 Feldkirchen/Muenchen, Deutschland
> Sitz der Gesellschaft: Feldkirchen bei Muenchen
> Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
> Registergericht: Muenchen HRB 47456
> Ust.-IdNr./VAT Registration No.: DE129385895
> Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-20 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-20 13:50 [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily() Sergey Senozhatsky
2013-08-20 14:03 ` Berg, Johannes
2013-08-20 19:31   ` Sergey Senozhatsky

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).