From patchwork Sun Oct 10 06:55:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Mytnyk X-Patchwork-Id: 12548269 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0709C433F5 for ; Sun, 10 Oct 2021 06:56:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8D3860F55 for ; Sun, 10 Oct 2021 06:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbhJJG6Y (ORCPT ); Sun, 10 Oct 2021 02:58:24 -0400 Received: from mail-am6eur05on2139.outbound.protection.outlook.com ([40.107.22.139]:11744 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230267AbhJJG6N (ORCPT ); Sun, 10 Oct 2021 02:58:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SQtVDYrXHfnV5bXwoAwaX9l44rUuStnZ0iSDxqHP2PsTVD3uglFuyy7sjTPLj4Xf0ridIMybzlbqj6jq5jNmY37kncXMGlMX1j3tJHz3WENyGdoGXV/dcNGYeYUz1sKdWs9sSfazMSduHboYlgqNqmYFFZXPYTfZaoJAY/WifQxioYc2rUcQqUlkvW7IYCnOd1CV3CbGqkP30uNTqZq0Tk8BRacOdIiUtB4IserxxF05f219v7b8MRz3ojCi4DvpXtnW/ZunjTgIAJ8LNN8usAaa4ed3FZHu19hPDCLg1yuC15a6QwZ6IToamlx5l9VwbmQStwVrsn7uDZo9RHK95w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xsQ4RaVEjboGSa/ozKMApxsPFweAZoX0F+0AGA8C2GY=; b=Xri3zvqmn6WIMoCZcA2UXBXRkXqAMIypdzzKC/0v1F3+h9uIYVDKejmgRJyis3u7Evv+hFFgQJtku5xC12CBW9QGU/qtLPaHye9c96AiyUcu/qwu6vcks7Hw8cXRPOltFrgvQYXmT7icJm+PHue+fQdcOucoHpRtr84wKaNb9H7ahT243XgpE6boV/WCtfS5ALaXlX+i0+BSSz3q2uLcDIueffDz35osUHxNrFMWq6WNOf6WeDjs2W9e1wYahjJlIL3h2KfKrEsN3M8YTtiS8N3Cbxc39v/HGQszypbgf1H5w9b6pLDfer2gvEtM2Q1VaAaEd8Q+EoJoVzNBjn36RQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=plvision.eu; dmarc=pass action=none header.from=plvision.eu; dkim=pass header.d=plvision.eu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plvision.eu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xsQ4RaVEjboGSa/ozKMApxsPFweAZoX0F+0AGA8C2GY=; b=oAM/N2XuRUObVzNZrqueFWqBBJ6Fq36KCCj67tfsM8ER2wvLX6NObZ5cx2ksjks6p1DhWIy7sEldGFTKL6AoLGLHs+hdO/3H2GWwptyb4bruISFCQuWJUXru7I+fVxKlL4q8BpopyPx3iNzjfHdL1VbBtZFaGCj+28WKNzW3PAg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=plvision.eu; Received: from VI1P190MB0734.EURP190.PROD.OUTLOOK.COM (2603:10a6:800:123::23) by VI1P190MB0223.EURP190.PROD.OUTLOOK.COM (2603:10a6:800:a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Sun, 10 Oct 2021 06:56:12 +0000 Received: from VI1P190MB0734.EURP190.PROD.OUTLOOK.COM ([fe80::4c5:a11b:e5c6:2f36]) by VI1P190MB0734.EURP190.PROD.OUTLOOK.COM ([fe80::4c5:a11b:e5c6:2f36%4]) with mapi id 15.20.4587.025; Sun, 10 Oct 2021 06:56:12 +0000 From: Volodymyr Mytnyk To: netdev@vger.kernel.org Cc: Volodymyr Mytnyk , Serhiy Boiko , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Jakub Kicinski , Vlad Buslov , 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 Message-Id: <1633848948-11315-1-git-send-email-volodymyr.mytnyk@plvision.eu> X-Mailer: git-send-email 2.7.4 X-ClientProxiedBy: HE1PR0202CA0029.eurprd02.prod.outlook.com (2603:10a6:3:e4::15) To VI1P190MB0734.EURP190.PROD.OUTLOOK.COM (2603:10a6:800:123::23) MIME-Version: 1.0 Received: from vmytnykub.x.ow.s (217.20.186.93) by HE1PR0202CA0029.eurprd02.prod.outlook.com (2603:10a6:3:e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4587.18 via Frontend Transport; Sun, 10 Oct 2021 06:56:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3d7062b-3a82-40fd-bb7b-08d98bbb0bd9 X-MS-TrafficTypeDiagnostic: VI1P190MB0223: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rKMHN7Pb+Rmq7l12nKn6eXuLdf4PoP2XnBjis1fzQ//BgUNjE+WnyFtKujZkvQkA2UkXW8GnP0UxLGYalfdeYJeITPUABiQbhvXY2hHUW1o66Cm1Zmps4Pe0TB4IwPlE0qtrzAf4cLfi0WX0GL8n7VbATkSctcPMBy160ZL6Fx51rncs8qCRYPXT8HsXoODcBATJx1kfzS/7JDQb00f4LKVGRp9Jo86wSZxoQ390XoVAz9HvggxeA3q2rVe4sg0RNbqJERcex9gTRvHgMijmnofIexGgFngVOsdSMsIg9PBD1jVMicvPWjr9BFrDDee3cc5ZXCQlEpmA3IDpylICQ4OqM8VZijpwKx0cuBBNat9W20Ifz65lgtFf0rdDnQ7lBFASn1Hl1tmfZBE8cljAxDPsiavZqUqpHG547RNXZ/xkKsUknifk5X8HBZA6/8X2ReH//GvOkdlIlEteHtxlib37oGlMv1C/wwOI9mY88/NPlN1kcXE/7YlNjmAHBTEvVKsscNIVQYUB4NRM5lmQ5+70vleIy88aQrDjr8ywzL4UolhVlxGWdv+G2AjCRHahg1hvVwpUFt2l1ni+7Z9QV2KOJouDvBfHrozIndpp7CXXkDpFRRD7ebjd7KfGtSBKPwdtGxtGvyC0D69WTR0YBGu17fbxO9OXbBEVT2i7PleIn3VpacKVwdKPXLfwrZrJpTSLmPNDsoFG7A92G+wD4A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1P190MB0734.EURP190.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(376002)(396003)(39830400003)(366004)(346002)(136003)(4326008)(956004)(2616005)(54906003)(316002)(86362001)(5660300002)(66556008)(2906002)(66946007)(66476007)(36756003)(8676002)(186003)(508600001)(44832011)(8936002)(6916009)(6486002)(38100700002)(38350700002)(6666004)(6506007)(52116002)(6512007)(26005)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1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wrYh84WguwzCvaNI5roT7VwNdPSV+3DgX+WV1ZZDhb0hm314O+KKR3LMfIhpTjctuL8/WYe+5YJqtNomuhH/s96inhe+h2c9A9m7LyUBPfQvxBZIKy4yqfINpTJeQO7bmgB0LJbLvN1Uz6uBntzce+2wPcmVm+1XoRZG1qCa8JnXsNHEn6FxwkxVxNXyJYAGXfOkHzHWmO/Dj68p2Pe6AOpZxCY/0BvjcwNSJIg2Ot0WfzXb/33paeuID9sczhgHcN5QUHHGIHqo3X4yYKvkpcAHlhnpkGfezSJ2WRG6wA2jNnQ19Ij X-OriginatorOrg: plvision.eu X-MS-Exchange-CrossTenant-Network-Message-Id: f3d7062b-3a82-40fd-bb7b-08d98bbb0bd9 X-MS-Exchange-CrossTenant-AuthSource: VI1P190MB0734.EURP190.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2021 06:56:12.5740 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 03707b74-30f3-46b6-a0e0-ff0a7438c9c4 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 04OmkH6shAOEGBK3wo/ENOf2ToqfNOQYYycY25KUQUp5912tsieZ+TQ+73k9it1Zcpd2DoMHu0aFxHLlvHpaD3TuNCOs/A7Xvftx/m5ntG8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1P190MB0223 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Volodymyr Mytnyk 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 Signed-off-by: Serhiy Boiko Signed-off-by: Volodymyr Mytnyk --- 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,