public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: Patrick McHardy <kaber@trash.net>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Johannes Berg <johannes.berg@intel.com>,
	Gao feng <gaofeng@cn.fujitsu.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily()
Date: Tue, 20 Aug 2013 16:50:33 +0300	[thread overview]
Message-ID: <20130820135033.GA2315@swordfish.minsk.epam.com> (raw)

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();
 


             reply	other threads:[~2013-08-20 13:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-20 13:50 Sergey Senozhatsky [this message]
2013-08-20 14:03 ` [PATCH next] netlink: prevent deadlock in ctrl_dumpfamily() Berg, Johannes
2013-08-20 19:31   ` Sergey Senozhatsky

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=20130820135033.GA2315@swordfish.minsk.epam.com \
    --to=sergey.senozhatsky@gmail.com \
    --cc=davem@davemloft.net \
    --cc=gaofeng@cn.fujitsu.com \
    --cc=johannes.berg@intel.com \
    --cc=kaber@trash.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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