From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiri Pirko Subject: Re: [PATCH] net: sched: fix crash when deleting secondary chains Date: Sun, 19 Nov 2017 17:23:10 +0100 Message-ID: <20171119162310.GD1965@nanopsycho.orion> References: <20171119114405.17264-1-code@rkapl.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: netdev@vger.kernel.org, Cong Wang To: Roman Kapl Return-path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:44059 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750784AbdKSQXM (ORCPT ); Sun, 19 Nov 2017 11:23:12 -0500 Received: by mail-wm0-f67.google.com with SMTP id r68so14573362wmr.3 for ; Sun, 19 Nov 2017 08:23:11 -0800 (PST) Content-Disposition: inline In-Reply-To: <20171119114405.17264-1-code@rkapl.cz> Sender: netdev-owner@vger.kernel.org List-ID: Sun, Nov 19, 2017 at 12:44:05PM CET, code@rkapl.cz wrote: >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()") Patch looks fine. Please repost with proper "Fixes: " tag. Feel free to add my: Acked-by: Jiri Pirko tag. Thanks! > >Signed-off-by: Roman Kapl >--- > 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 ab255b421781..7d97f612c9b9 100644 >--- a/net/sched/cls_api.c >+++ b/net/sched/cls_api.c >@@ -205,13 +205,14 @@ static void tcf_chain_head_change(struct tcf_chain *chain, > > static void tcf_chain_flush(struct tcf_chain *chain) > { >- struct tcf_proto *tp; >+ struct tcf_proto *tp = rtnl_dereference(chain->filter_chain); > > tcf_chain_head_change(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.15.0 >