Blob Blame History Raw
From: Cong Wang <xiyou.wangcong@gmail.com>
Subject: net_sched: acquire RTNL in tc_action_net_exit()
Patch-mainline: v4.14-rc8 
Git-commit: a159d3c4b8291998c018f0dbddd4678315264a1e
References: git-fixes

I forgot to acquire RTNL in tc_action_net_exit()
which leads that action ops->cleanup() is not always
called with RTNL. This usually is not a big deal because
this function is called after all netns refcnt are gone,
but given RTNL protects more than just actions, add it
for safety and consistency.

Also add an assertion to catch other potential bugs.

Fixes: ddf97ccdd7cb ("net_sched: add network namespace support for tc actions")
Reported-by: Lucas Bates <lucasb@mojatatu.com>
Tested-by: Lucas Bates <lucasb@mojatatu.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Denis Kirjanov <dkirjanov@suse.com>
---
 include/net/act_api.h | 2 ++
 net/sched/act_api.c   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/include/net/act_api.h b/include/net/act_api.h
index 26ffd8333f50..bc0966d00d98 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -151,7 +151,9 @@ void tcf_hashinfo_destroy(const struct tc_action_ops *ops,
 
 static inline void tc_action_net_exit(struct tc_action_net *tn)
 {
+	rtnl_lock();
 	tcf_hashinfo_destroy(tn->ops, tn->hinfo);
+	rtnl_unlock();
 	kfree(tn->hinfo);
 }
 
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index bf4b7bd99971..0618165f98e6 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -87,6 +87,8 @@ int __tcf_hash_release(struct tc_action *p, bool bind, bool strict)
 {
 	int ret = 0;
 
+	ASSERT_RTNL();
+
 	if (p) {
 		if (bind)
 			p->tcfa_bindcnt--;
-- 
2.12.3