From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH net-next 4/6] rtnetlink: init handler refcounts to 1
Date: Thu, 10 Aug 2017 16:53:00 +0200 [thread overview]
Message-ID: <20170810145302.30391-5-fw@strlen.de> (raw)
In-Reply-To: <20170810145302.30391-1-fw@strlen.de>
If using CONFIG_REFCOUNT_FULL=y we get following splat:
refcount_t: increment on 0; use-after-free.
WARNING: CPU: 0 PID: 304 at lib/refcount.c:152 refcount_inc+0x47/0x50
Call Trace:
rtnetlink_rcv_msg+0x191/0x260
...
This warning is harmless (0 is "no callback running", not "memory
was freed").
Use '1' as the new 'no handler is running' base instead of 0 to avoid
this.
Fixes: 019a316992ee ("rtnetlink: add reference counting to prevent module unload while dump is in progress")
Reported-by: Sabrina Dubroca <sdubroca@redhat.com>
Reported-by: kernel test robot <fengguang.wu@intel.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/core/rtnetlink.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 087f2434813a..59eda6952bc9 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -262,7 +262,7 @@ void rtnl_unregister_all(int protocol)
synchronize_net();
- while (refcount_read(&rtnl_msg_handlers_ref[protocol]) > 0)
+ while (refcount_read(&rtnl_msg_handlers_ref[protocol]) > 1)
schedule();
kfree(handlers);
}
@@ -4324,6 +4324,11 @@ static struct pernet_operations rtnetlink_net_ops = {
void __init rtnetlink_init(void)
{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rtnl_msg_handlers_ref); i++)
+ refcount_set(&rtnl_msg_handlers_ref[i], 1);
+
if (register_pernet_subsys(&rtnetlink_net_ops))
panic("rtnetlink_init: cannot initialize rtnetlink\n");
--
2.13.0
next prev 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 ` [PATCH net-next 3/6] rtnetlink: switch rtnl_link_get_slave_info_data_size to rcu Florian Westphal
2017-08-10 16:17 ` David Ahern
2017-08-10 14:53 ` Florian Westphal [this message]
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-5-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).