LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Volodymyr Mytnyk <volodymyr.mytnyk@plvision.eu>
To: netdev@vger.kernel.org
Cc: Volodymyr Mytnyk <vmytnyk@marvell.com>,
	Serhiy Boiko <serhiy.boiko@plvision.eu>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Vlad Buslov <vladbu@mellanox.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net] sched: fix infinite loop when creating tc filter
Date: Sun, 10 Oct 2021 09:55:47 +0300	[thread overview]
Message-ID: <1633848948-11315-1-git-send-email-volodymyr.mytnyk@plvision.eu> (raw)

From: Volodymyr Mytnyk <vmytnyk@marvell.com>

After running a specific set of commands tc will become unresponsive:

  $ ip link add dev DEV type veth
  $ tc qdisc add dev DEV clsact
  $ tc chain add dev DEV chain 0 ingress
  $ tc filter del dev DEV ingress
  $ tc filter add dev DEV ingress flower action pass

When executing chain flush, the "chain->flushing" field is set
to true, which prevents insertion of new classifier instances.
It is unset in one place under two conditions:

`refcnt - chain->action_refcnt == 0` and `!by_act`.

Ignoring the by_act and action_refcnt arguments the `flushing procedure`
will be over when refcnt is 0.

But if the chain is explicitly created (e.g. `tc chain add .. chain 0 ..`)
refcnt is set to 1 without any classifier instances. Thus the condition
is never met and the chain->flushing field is never cleared.
And because the default chain is `flushing` new classifiers cannot
be added. tc_new_tfilter is stuck in a loop trying to find a chain
where chain->flushing is false.

By moving `chain->flushing = false` from __tcf_chain_put to the end
of tcf_chain_flush will avoid the condition and the field will always
be reset after the flush procedure.

Fixes: 91052fa1c657 ("net: sched: protect chain->explicitly_created with block->lock")

Co-developed-by: Serhiy Boiko <serhiy.boiko@plvision.eu>
Signed-off-by: Serhiy Boiko <serhiy.boiko@plvision.eu>
Signed-off-by: Volodymyr Mytnyk <vmytnyk@marvell.com>
---
 net/sched/cls_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index d73b5c5514a9..327594cce554 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -563,8 +563,6 @@ static void __tcf_chain_put(struct tcf_chain *chain, bool by_act,
 	if (refcnt - chain->action_refcnt == 0 && !by_act) {
 		tc_chain_notify_delete(tmplt_ops, tmplt_priv, chain->index,
 				       block, NULL, 0, 0, false);
-		/* Last reference to chain, no need to lock. */
-		chain->flushing = false;
 	}
 
 	if (refcnt == 0)
@@ -615,6 +613,9 @@ static void tcf_chain_flush(struct tcf_chain *chain, bool rtnl_held)
 		tcf_proto_put(tp, rtnl_held, NULL);
 		tp = tp_next;
 	}
+
+	/* Last reference to chain, no need to lock. */
+	chain->flushing = false;
 }
 
 static int tcf_block_setup(struct tcf_block *block,
-- 
2.7.4


             reply	other threads:[~2021-10-10  6:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10  6:55 Volodymyr Mytnyk [this message]
2021-10-11 13:42 ` Vlad Buslov
2021-10-13  9:43   ` Volodymyr Mytnyk [C]

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=1633848948-11315-1-git-send-email-volodymyr.mytnyk@plvision.eu \
    --to=volodymyr.mytnyk@plvision.eu \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=serhiy.boiko@plvision.eu \
    --cc=vladbu@mellanox.com \
    --cc=vmytnyk@marvell.com \
    --cc=xiyou.wangcong@gmail.com \
    --subject='Re: [PATCH net] sched: fix infinite loop when creating tc filter' \
    /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

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).