From: Cong Wang <xiyou.wangcong@gmail.com>
To: netdev@vger.kernel.org
Cc: jiri@mellanox.com, code@rkapl.cz, davem@davemloft.net,
fli4l@franke-prem.de, stable@vger.kernel.org,
gregkh@linuxfoundation.org
Subject: [Patch 4.14 2/4] net: sched: crash on blocks with goto chain action
Date: Thu, 1 Mar 2018 13:46:37 -0800 [thread overview]
Message-ID: <20180301214639.852-3-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <20180301214639.852-1-xiyou.wangcong@gmail.com>
From: Roman Kapl <code@rkapl.cz>
[ Upstream commit a60b3f515d30d0fe8537c64671926879a3548103 ]
tcf_block_put_ext has assumed that all filters (and thus their goto
actions) are destroyed in RCU callback and thus can not race with our
list iteration. However, that is not true during netns cleanup (see
tcf_exts_get_net comment).
Prevent the user after free by holding all chains (except 0, that one is
already held). foreach_safe is not enough in this case.
To reproduce, run the following in a netns and then delete the ns:
ip link add dtest type dummy
tc qdisc add dev dtest ingress
tc filter add dev dtest chain 1 parent ffff: handle 1 prio 1 flower action goto chain 2
Fixes: 822e86d997 ("net_sched: remove tcf_block_put_deferred()")
Signed-off-by: Roman Kapl <code@rkapl.cz>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/sched/cls_api.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 1451a56a8f93..ddae7053b745 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -282,7 +282,8 @@ static void tcf_block_put_final(struct work_struct *work)
struct tcf_chain *chain, *tmp;
rtnl_lock();
- /* Only chain 0 should be still here. */
+
+ /* At this point, all the chains should have refcnt == 1. */
list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
tcf_chain_put(chain);
rtnl_unlock();
@@ -290,17 +291,23 @@ static void tcf_block_put_final(struct work_struct *work)
}
/* XXX: Standalone actions are not allowed to jump to any chain, and bound
- * actions should be all removed after flushing. However, filters are now
- * destroyed in tc filter workqueue with RTNL lock, they can not race here.
+ * actions should be all removed after flushing.
*/
void tcf_block_put(struct tcf_block *block)
{
- struct tcf_chain *chain, *tmp;
+ struct tcf_chain *chain;
if (!block)
return;
- list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
+ /* Hold a refcnt for all chains, except 0, so that they don't disappear
+ * while we are iterating.
+ */
+ list_for_each_entry(chain, &block->chain_list, list)
+ if (chain->index)
+ tcf_chain_hold(chain);
+
+ list_for_each_entry(chain, &block->chain_list, list)
tcf_chain_flush(chain);
INIT_WORK(&block->work, tcf_block_put_final);
--
2.13.0
next prev parent reply other threads:[~2018-03-01 21:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-01 21:46 [Patch 4.14 0/4] net_sched: backport tc filter fixes to 4.14 Cong Wang
2018-03-01 21:46 ` [Patch 4.14 1/4] net: sched: fix crash when deleting secondary chains Cong Wang
2018-03-01 21:46 ` Cong Wang [this message]
2018-03-01 21:46 ` [Patch 4.14 3/4] net_sched: get rid of rcu_barrier() in tcf_block_put_ext() Cong Wang
2018-03-01 21:46 ` [Patch 4.14 4/4] net: sched: fix use-after-free in tcf_block_put_ext Cong Wang
2018-03-02 1:56 ` [Patch 4.14 0/4] net_sched: backport tc filter fixes to 4.14 David Miller
2018-03-02 8:22 ` Greg KH
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=20180301214639.852-3-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=code@rkapl.cz \
--cc=davem@davemloft.net \
--cc=fli4l@franke-prem.de \
--cc=gregkh@linuxfoundation.org \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=stable@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).