netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH net-next 3/6] rtnetlink: switch rtnl_link_get_slave_info_data_size to rcu
Date: Thu, 10 Aug 2017 16:52:59 +0200	[thread overview]
Message-ID: <20170810145302.30391-4-fw@strlen.de> (raw)
In-Reply-To: <20170810145302.30391-1-fw@strlen.de>

David Ahern reports following splat:
 RTNL: assertion failed at net/core/dev.c (5717)
 netdev_master_upper_dev_get+0x5f/0x70
 if_nlmsg_size+0x158/0x240
 rtnl_calcit.isra.26+0xa3/0xf0

rtnl_link_get_slave_info_data_size currently assumes RTNL protection, but
there appears to be no hard requirement for this, so use rcu instead.

At the time of this writing, there are three 'get_slave_size' callbacks
(now invoked under rcu): bond_get_slave_size, vrf_get_slave_size and
br_port_get_slave_size, all return constant only (i.e. they don't sleep).

Fixes: 6853dd488119 ("rtnetlink: protect handler table with rcu")
Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/core/rtnetlink.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a9b5ebc1af21..087f2434813a 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -402,16 +402,24 @@ static size_t rtnl_link_get_slave_info_data_size(const struct net_device *dev)
 {
 	struct net_device *master_dev;
 	const struct rtnl_link_ops *ops;
+	size_t size = 0;
 
-	master_dev = netdev_master_upper_dev_get((struct net_device *) dev);
+	rcu_read_lock();
+
+	master_dev = netdev_master_upper_dev_get_rcu((struct net_device *)dev);
 	if (!master_dev)
-		return 0;
+		goto out;
+
 	ops = master_dev->rtnl_link_ops;
 	if (!ops || !ops->get_slave_size)
-		return 0;
+		goto out;
 	/* IFLA_INFO_SLAVE_DATA + nested data */
-	return nla_total_size(sizeof(struct nlattr)) +
+	size = nla_total_size(sizeof(struct nlattr)) +
 	       ops->get_slave_size(master_dev, dev);
+
+out:
+	rcu_read_unlock();
+	return size;
 }
 
 static size_t rtnl_link_get_size(const struct net_device *dev)
-- 
2.13.0

  parent reply	other threads:[~2017-08-10 14:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-10 14:52 [PATCH net-next 0/6] rtnetlink: fix initial rtnl pushdown fallout Florian Westphal
2017-08-10 14:52 ` [PATCH net-next 1/6] rtnetlink: use rcu_dereference_raw to silence rcu splat Florian Westphal
2017-08-10 15:38   ` Ido Schimmel
2017-08-10 14:52 ` [PATCH net-next 2/6] rtnetlink: do not use RTM_GETLINK directly Florian Westphal
2017-08-10 14:52 ` Florian Westphal [this message]
2017-08-10 16:17   ` [PATCH net-next 3/6] rtnetlink: switch rtnl_link_get_slave_info_data_size to rcu David Ahern
2017-08-10 14:53 ` [PATCH net-next 4/6] rtnetlink: init handler refcounts to 1 Florian Westphal
2017-08-10 14:53 ` [PATCH net-next 5/6] rtnetlink: fallback to UNSPEC if current family has no doit callback Florian Westphal
2017-08-10 14:53 ` [PATCH net-next 6/6] selftests: add rtnetlink test script Florian Westphal
2017-08-10 16:50 ` [PATCH net-next 0/6] rtnetlink: fix initial rtnl pushdown fallout David Miller

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=20170810145302.30391-4-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).