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 1/4] net: sched: fix crash when deleting secondary chains
Date: Thu, 1 Mar 2018 13:46:36 -0800 [thread overview]
Message-ID: <20180301214639.852-2-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <20180301214639.852-1-xiyou.wangcong@gmail.com>
From: Roman Kapl <code@rkapl.cz>
[ Upstream commit d7aa04a5e82b4f254d306926c81eae8df69e5200 ]
If you flush (delete) a filter chain other than chain 0 (such as when
deleting the device), the kernel may run into a use-after-free. The
chain refcount must not be decremented unless we are sure we are done
with the chain.
To reproduce the bug, run:
ip link add dtest type dummy
tc qdisc add dev dtest ingress
tc filter add dev dtest chain 1 parent ffff: flower
ip link del dtest
Introduced in: commit f93e1cdcf42c ("net/sched: fix filter flushing"),
but unless you have KAsan or luck, you won't notice it until
commit 0dadc117ac8b ("cls_flower: use tcf_exts_get_net() before call_rcu()")
Fixes: f93e1cdcf42c ("net/sched: fix filter flushing")
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Roman Kapl <code@rkapl.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/sched/cls_api.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index ecbb019efcbd..1451a56a8f93 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -197,14 +197,15 @@ static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
static void tcf_chain_flush(struct tcf_chain *chain)
{
- struct tcf_proto *tp;
+ struct tcf_proto *tp = rtnl_dereference(chain->filter_chain);
if (chain->p_filter_chain)
RCU_INIT_POINTER(*chain->p_filter_chain, NULL);
- while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
+ while (tp) {
RCU_INIT_POINTER(chain->filter_chain, tp->next);
- tcf_chain_put(chain);
tcf_proto_destroy(tp);
+ tp = rtnl_dereference(chain->filter_chain);
+ tcf_chain_put(chain);
}
}
--
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 ` Cong Wang [this message]
2018-03-01 21:46 ` [Patch 4.14 2/4] net: sched: crash on blocks with goto chain action Cong Wang
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-2-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).