From patchwork Wed May 24 01:17:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2528112vqo; Tue, 23 May 2023 18:29:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6LtyILxfdFujwBFTbHAjCuJgmANnyzpjTebqFpoCouEBSO3nQhui7DtmOsl779bCCkHsmM X-Received: by 2002:a17:902:f682:b0:1a6:db0a:8005 with SMTP id l2-20020a170902f68200b001a6db0a8005mr17695302plg.68.1684891784533; Tue, 23 May 2023 18:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891784; cv=none; d=google.com; s=arc-20160816; b=KrzWwyxdTJSq7JC+UThIGtlZwXRWIubjQQMC7qQnuFFWZPhiH5qyoSjc15o7XS77lA lBNLop8Ehhfbi0lHV5sh5q6uINVyloPc3ggAhjXI/RRTezHAZX5e50eRA4i+FR0OZEG6 HSME0ZMeCR4cgCPtvz74U9Ep+0HJSuIFxIraQcXLmppkBclaxNRGgSyMzzOg936DwXZw q2eYd832/D8rEwrK9yugm+dzrWSCaNzf55YzWOM6SJeHxJBNPBZzL8ZC/u3Gj6xsBfrR d0LHhXFXKPg+NwIrFH7bC51IHcHz3bb+lwb1JCYUD6gpYfvJtY7g/dp+sy91GzgnOcui Lmfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CcHI3x4ohvXiCTNBiyxTM+9Lco9SeIQmLnH1EsUllhU=; b=TUIpyeg0B9aeydnReBgZaa+Zn112nTABrvj14IuV4be/lML21CrMcEzGyN0QZ8Fo42 EtE9qem7rLLtAwFKHAeHHAtmIdnZgM5WzztWQWaLA1hzUqBEDzvenY1IV6ejVw4rZo8M +YBAZUitxcH2Ymw9aYufEtWZEffZ5tkKc8B6U78/tnph/pgg1k16HFbMxkCrlyk7XzZI nsrfF+NhRtDlth2RmCr8RZNgWwpCUMTgu7aq2YjJibzjxrEJ+dgnCl1d90xwioQmFbAR tBIF5y1Ey4cTOJqZsaJrueFLwxuckkG3yyDCR3Ln45R2ITG9IvGF0vnE7kZScBEgTPUM ZnVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DtQCWPCO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a17090ac90700b0024ddcb3e1a6si285917pjt.190.2023.05.23.18.29.30; Tue, 23 May 2023 18:29:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DtQCWPCO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238839AbjEXBSJ (ORCPT + 99 others); Tue, 23 May 2023 21:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbjEXBSH (ORCPT ); Tue, 23 May 2023 21:18:07 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E945DA; Tue, 23 May 2023 18:18:06 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-75b17b80834so70486885a.1; Tue, 23 May 2023 18:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891086; x=1687483086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CcHI3x4ohvXiCTNBiyxTM+9Lco9SeIQmLnH1EsUllhU=; b=DtQCWPCOPWS0+xDr8/swlbtrJH3RwebebAKwTSXG5R4kuTsfi71x0G5lXvhMh74ox8 dgtHcrBAOndyoBNqZBxeK6YufsUoALMkPziyDyfAQ4OTLdq1iM3viKF+Cm10LfzTGeu9 wTMHxvOZL/V6yit4mFGrJsEN3eLmxA3ceGnL49kT5HIZZU29wqZ8/LjBVdGdDGyLv8Qc Xz8Tad0q9vny+wNpxp29SHxmxOfDXXgHuqDMyRoxhBu1nKaMRtcPeszYw3tiIWMG/X1L QwT4ODVyrWHkBcmfRyk9eiw4DMHEsiRx47/TLNvLZEgVB85NuB8pQcsyb0dZtabOhjSO tX6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891086; x=1687483086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CcHI3x4ohvXiCTNBiyxTM+9Lco9SeIQmLnH1EsUllhU=; b=GVNuoUg3Rzpv6ljtobEd0LWguU5jLW1gVngzva4cy7Z6VfJKwtQFWL2BVVQWHcz9la /fLsyB9rG8gm6sh1Hq9YDh1V68ETBsMo13IkqlhrIiUUs/gJOHqE8iCXV5fspkadeJ/o 4h+FiEnUmnUMuQ+giqUQOXLTuCKv0jrnl/GawO+qP3Ccabwd1kkTUhUs92pDIBEDcPW+ mClnmkhjIaSEPHtUGmqxXvL3BWm2D/oppY2rnUQdk9GLqC6EwFcXrq8PbOcShJyFQ1Jm tObkAkI3J+0fyNVUxfwr7wcJN1QJumm5yplhhi3p9grgtM5R40v/r18PkmD5duhZR+oA 2wCQ== X-Gm-Message-State: AC+VfDwL43rP6Hc7cjCvdPDPoZgwGyGZpDsuqPigbg8ZI97sVI/+S8CE XOBqd6VN2uW0ADI+J5L4qZuOrtuf5g== X-Received: by 2002:a37:4d6:0:b0:75b:23a1:44b with SMTP id 205-20020a3704d6000000b0075b23a1044bmr5344164qke.17.1684891085685; Tue, 23 May 2023 18:18:05 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id a19-20020a05620a103300b0075798551db7sm2920764qkk.22.2023.05.23.18.18.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:18:05 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 1/6] net/sched: sch_ingress: Only create under TC_H_INGRESS Date: Tue, 23 May 2023 18:17:39 -0700 Message-Id: X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766737087523410242?= X-GMAIL-MSGID: =?utf-8?q?1766737087523410242?= From: Peilin Ye ingress Qdiscs are only supposed to be created under TC_H_INGRESS. Return -EOPNOTSUPP if 'parent' is not TC_H_INGRESS, similar to mq_init(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+b53a9c0d1ea4ad62da8b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/0000000000006cf87705f79acf1a@google.com/ Signed-off-by: Peilin Ye Tested-by: Pedro Tammela Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- change in v5: - avoid underflowing @ingress_needed_key in ->destroy(), reported by Pedro change in v3, v4: - add in-body From: tag net/sched/sch_ingress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 84838128b9c5..f9ef6deb2770 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -80,6 +80,9 @@ static int ingress_init(struct Qdisc *sch, struct nlattr *opt, struct net_device *dev = qdisc_dev(sch); int err; + if (sch->parent != TC_H_INGRESS) + return -EOPNOTSUPP; + net_inc_ingress_queue(); mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress); @@ -101,6 +104,9 @@ static void ingress_destroy(struct Qdisc *sch) { struct ingress_sched_data *q = qdisc_priv(sch); + if (sch->parent != TC_H_INGRESS) + return; + tcf_block_put_ext(q->block, sch, &q->block_info); net_dec_ingress_queue(); } From patchwork Wed May 24 01:18:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2525267vqo; Tue, 23 May 2023 18:21:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RwbbmoduPVdCk4PInWjOLJKnDgXYHDAtaFoJJvxU0/bXk5k20YwrupUZ3/AegPHTA9uyG X-Received: by 2002:a05:6a00:a17:b0:638:7e00:3737 with SMTP id p23-20020a056a000a1700b006387e003737mr993493pfh.23.1684891260984; Tue, 23 May 2023 18:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891260; cv=none; d=google.com; s=arc-20160816; b=MRR76/nyMNsaDg9H8owcFZl0mkcl6IadaW5RRlVcHLZtKjd0YNwog41OJ3slalDskY QNYq6+xT/X4A4TZeb4TQMxmrBp4BYuxQNLGSPn3O+Xb9KdE084PLE8p/Me+QVM4eX7JY 1YCXpd7QQCzIxRII31HFv9qJzSuKyKk5ZmigUYtpeQybn/x4nah4NKtzYnwtzRXSK1BW JY7O30Q0TtZQG4u+uw4kUQrrffrD9y4zPZYscUnfW5JntzfiNN+y2Ygm6+Huh04dTYJY glLPEuzo1K4FOEIyTpsZfuv7jSUZqh89ivM4rNHgdFOO1V1M6YCHnI1SY+LLdzuDDr8I LqOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TJv/Mw0cjZxSPI53855B262nqFR1u1C+NNKjhLR5zAc=; b=e4pTRH5OxhTik1l9chaogNnTeHaDT9L6anByuyFp+gx7pBAihvHHcuJNYheQ2Nr+nZ wrUbmGPB5RYoehx8/rjcJGl27JTW0mAThZolL7gD5L/bkSeYuZM3ib9pMU+U3MTOc316 7fI67/hPWHGh5p28VmzTtpwHChOa/qBsS0LT2FVuAr/P6s13N6X1dMH781stC4E6ROk3 NfcdW5QaQEHMfZ9xSh03kLRLuFcnH5f0l7+GTLTknVn0b4cGTktSHFn8puIkaRCFv22+ J/lohcLHyfZP0dqat/KU2tFtwDOmysIiDREK20bQkfUohsUnUwSFLra7zkqCzS+OlVY+ 3raw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=bHh2xG4v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a633304000000b005346c49e06esi5769328pgz.843.2023.05.23.18.20.39; Tue, 23 May 2023 18:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=bHh2xG4v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238509AbjEXBTD (ORCPT + 99 others); Tue, 23 May 2023 21:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjEXBTC (ORCPT ); Tue, 23 May 2023 21:19:02 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C06E5; Tue, 23 May 2023 18:19:00 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-75affb4d0f9so49323085a.2; Tue, 23 May 2023 18:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891140; x=1687483140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TJv/Mw0cjZxSPI53855B262nqFR1u1C+NNKjhLR5zAc=; b=bHh2xG4vMLwDfNkJoMtqyCOK1LyFyld0lllv/VgIUkukjyDA+3SoBce0g0B/7yUrV3 a0NeiyWiF8xzqkzj2yCXi5XGoukztOJQjPKDJN47yZOBHkkdWZtSVIAOm3rw3dH5Bl1b Un1LlbsPAPrZm4FlKCbnIwLloVEKU0CDgmYXjLuVs6jI2Bef5IErYLRdZ7TFBDLAC4+h vn0cTwa3oOvHw+7yaYCnj/DiQiJizfg4GiPvHZ8nIPSs3b/EYMuuTor9mWI1w6NZV+Is Uex0+ruJrQfU9FvCu0g1Yy9+KLo6ZNpxNnlAec+Okm9RrLAh0K9izme21sMpzGlRn5qe gqtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891140; x=1687483140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TJv/Mw0cjZxSPI53855B262nqFR1u1C+NNKjhLR5zAc=; b=d2vUx0sQSHgujYZE12HEhxOV1wH/am9cYigjWKJNLUNBIpkR0F62kU+SDjsPO+4laN I04VHWtgcdL2zJzRzZiJEQHHmuJmiPeBuQJbioLNZMM1RCc3vSVlViuX4iknKaaD23kU Hxipj5Q9tiEsbnTyTYq/aD220mpIVpO6wSE8BQ0rtym03bK51DjvXg88fz5FO0sA8Fhl 6g8+dSno+ScnQWI69ZxvAmrC+9Z4ihJOENb+1tX5ZE+rpBpAhnPxeoFqmcOb1zbTpLkK K8qysq8lumu971GYbkM03zfN5qEskPvGuSTS+PTwpcsAYhQFc85UEhdDPUblzoGohFuP ajCA== X-Gm-Message-State: AC+VfDz/AmDuBxQE0rU+n6dDJJcqXfsaIv5X0/VvdHJF/ibuwcHbPt0p axYeNoUTVPzpGr1wog57rg== X-Received: by 2002:a05:620a:a9b:b0:75b:23a0:e7df with SMTP id v27-20020a05620a0a9b00b0075b23a0e7dfmr6174329qkg.64.1684891139934; Tue, 23 May 2023 18:18:59 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id ow21-20020a05620a821500b0074636e35405sm2913190qkn.65.2023.05.23.18.18.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:18:59 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 2/6] net/sched: sch_clsact: Only create under TC_H_CLSACT Date: Tue, 23 May 2023 18:18:35 -0700 Message-Id: <0c07bd5b72c67a2edf126cd2c6a9daadddb3ca95.1684887977.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766736539236682745?= X-GMAIL-MSGID: =?utf-8?q?1766736539236682745?= From: Peilin Ye clsact Qdiscs are only supposed to be created under TC_H_CLSACT (which equals TC_H_INGRESS). Return -EOPNOTSUPP if 'parent' is not TC_H_CLSACT. Fixes: 1f211a1b929c ("net, sched: add clsact qdisc") Signed-off-by: Peilin Ye Tested-by: Pedro Tammela Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- change in v5: - avoid underflowing @egress_needed_key in ->destroy(), reported by Pedro change in v3, v4: - add in-body From: tag net/sched/sch_ingress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index f9ef6deb2770..35963929e117 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -225,6 +225,9 @@ static int clsact_init(struct Qdisc *sch, struct nlattr *opt, struct net_device *dev = qdisc_dev(sch); int err; + if (sch->parent != TC_H_CLSACT) + return -EOPNOTSUPP; + net_inc_ingress_queue(); net_inc_egress_queue(); @@ -254,6 +257,9 @@ static void clsact_destroy(struct Qdisc *sch) { struct clsact_sched_data *q = qdisc_priv(sch); + if (sch->parent != TC_H_CLSACT) + return; + tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info); tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info); From patchwork Wed May 24 01:19:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2525315vqo; Tue, 23 May 2023 18:21:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ddk8jZhRmw0eO3wAMxc66zGIKEG1idiMTv/ltyBSlS9q9nV9yHbJ1Z0DAlwcwaBITXmWN X-Received: by 2002:a05:6a20:8e13:b0:10c:2a14:a357 with SMTP id y19-20020a056a208e1300b0010c2a14a357mr6532501pzj.26.1684891269548; Tue, 23 May 2023 18:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891269; cv=none; d=google.com; s=arc-20160816; b=JtMD8FgBwyb3i+BonjwsIFvQt7ibMDz/IJR8TD3GsnAShwZc9tEGBLVLr9eK+iG2jf Xypj3zjYzqYaV4dDk0h2x4lQgw81guKZCRFoxzXeaPyYowF3eujwGQafkQuKrw1y5YNz pwG6PKmefelW6GR+ZLMAinRm6eHSmBxdnjw6aF4Bv9wpac+pOO+wvlW7pKDl7HR+SS2w aKmCBClB4gwvps2oHs67PngODHdU6d1zW+fZWrMaW4W03uSgsSGntAVAeayGIPWONqci ud0zLMm8SXA2N26K8Ywd4qq3QaUCWsauOeCl5LZXB6G/EtmacXyGFvya8fPwljs0K6jO /MCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kk5Fbp1XDe1Iwik6nOEtU3rLxoAf3ax2ERfkaCeUvsg=; b=0jr0d41We0YhI4Lu9ekh10ILB+pEaDkV92wdI1JkAd57ZL33JIKoePFxGI+AYi3DNg 9wEKKcJBetn4vtgzAUbHL6MLx7qyq4b5UGCZqkSEKcbZKxoS+p3WEk6IL91eG7n4nG7c j6mrGdrheeO8zyJvgD0nE0XeaglHSkKCDWYK2ZDdU4X4O3RmUKvN0FMKYfps0a0CqLT6 nog1TKee09CcJc+g9zWQNEOnkaA6vsO2V56HTXHzIAhldtbHltYz0D6GqFc15CEn3/ZH ZLyfSVuNkwDLoxmyHoH5RbP+CA3zSEpjWg0QSNeEkbLVqXw7q93P3wI61ilrqspYiDOo 3wew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OPUEswG9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r191-20020a632bc8000000b0052cc0c1c39bsi5476204pgr.684.2023.05.23.18.20.56; Tue, 23 May 2023 18:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OPUEswG9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230299AbjEXBTZ (ORCPT + 99 others); Tue, 23 May 2023 21:19:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238867AbjEXBTX (ORCPT ); Tue, 23 May 2023 21:19:23 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49974139; Tue, 23 May 2023 18:19:21 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-3f6c0d651adso5380031cf.2; Tue, 23 May 2023 18:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891160; x=1687483160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kk5Fbp1XDe1Iwik6nOEtU3rLxoAf3ax2ERfkaCeUvsg=; b=OPUEswG9EUu6RwEkbOrd4uxrF/03QDQsRiIQBb/h+o4SSpw49e243AraXpmv2Y/N2v X/tr0xbtzYRrrg0+dYo14ypY3LD9P18XH/15tFFKEjyZCpTVwHlro62EhZ/xGpq3T26Y 2ZoDL5OTAw7uFvqFBqtJSCo/MZgn5LPSeOqKcu+vHFP0lAdxZw9W5gvZHtE4C6GpbSSW 3+oBQ8uoHBqVxv6sIW+C/kEQFHWh+QrmbbnWyHeCETkbNFlvxoflfSQhZspke83T2yuq RjSTp4365coJTuxm1cb4jWDEJb426TEULx4X4SrI22kWVWPCaPzLNwhEwkpKU1aZLwjw GQ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891160; x=1687483160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kk5Fbp1XDe1Iwik6nOEtU3rLxoAf3ax2ERfkaCeUvsg=; b=MsbVaiTGfaHhxV43P1C1Osl83iav4v49sqbzJgS5SEzLUyMExrA3PkT5NIB41CdD4A 12Io25SfIz2yBexUD6JmqD2db/ZtLN8wyIRtj61tt6nikBPYbFcQjgkSxboi0zOP/YcB zCby1aQ3z4TRbQG5t6IU4eNQp/7Ud/3AcBY5bvw9inNm4h03aHB6JkVAZ1lDAoMVnMoS NB//uPKtfHMXKg75YeRv137cG6VuVctUQUOaeZvqDuaAGEd8AMohLCh8GmdJwyZGct+c /gc8MM2EZdMvpAdYdnhzF7XM9B9VIO2An3FHwbEwTZBMpIJaaqPzVJCLc8Gbe9wlcIrH DoRQ== X-Gm-Message-State: AC+VfDzWrabRkzgO2+wcdXEVK2QGeYULPLHgay9yAPXegUTRBPydUtmd vVw/A17R18odwYBmrUDsmA== X-Received: by 2002:a05:622a:1115:b0:3f5:1f9c:5b35 with SMTP id e21-20020a05622a111500b003f51f9c5b35mr25002785qty.63.1684891160401; Tue, 23 May 2023 18:19:20 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id r6-20020ac85c86000000b003f6b22de8f8sm1815119qta.91.2023.05.23.18.19.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:19:20 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 3/6] net/sched: Reserve TC_H_INGRESS (TC_H_CLSACT) for ingress (clsact) Qdiscs Date: Tue, 23 May 2023 18:19:08 -0700 Message-Id: <9815766bb41f8413d90c14936974a528870044fa.1684887977.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766736547716412696?= X-GMAIL-MSGID: =?utf-8?q?1766736547716412696?= From: Peilin Ye Currently it is possible to add e.g. an HTB Qdisc under ffff:fff1 (TC_H_INGRESS, TC_H_CLSACT): $ ip link add name ifb0 type ifb $ tc qdisc add dev ifb0 parent ffff:fff1 htb $ tc qdisc add dev ifb0 clsact Error: Exclusivity flag on, cannot modify. $ drgn ... >>> ifb0 = netdev_get_by_name(prog, "ifb0") >>> qdisc = ifb0.ingress_queue.qdisc_sleeping >>> print(qdisc.ops.id.string_().decode()) htb >>> qdisc.flags.value_() # TCQ_F_INGRESS 2 Only allow ingress and clsact Qdiscs under ffff:fff1. Return -EINVAL for everything else. Make TCQ_F_INGRESS a static flag of ingress and clsact Qdiscs. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 1f211a1b929c ("net, sched: add clsact qdisc") Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim Signed-off-by: Peilin Ye Tested-by: Pedro Tammela --- change in v3, v4: - add in-body From: tag net/sched/sch_api.c | 7 ++++++- net/sched/sch_ingress.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index fdb8f429333d..383195955b7d 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1252,7 +1252,12 @@ static struct Qdisc *qdisc_create(struct net_device *dev, sch->parent = parent; if (handle == TC_H_INGRESS) { - sch->flags |= TCQ_F_INGRESS; + if (!(sch->flags & TCQ_F_INGRESS)) { + NL_SET_ERR_MSG(extack, + "Specified parent ID is reserved for ingress and clsact Qdiscs"); + err = -EINVAL; + goto err_out3; + } handle = TC_H_MAKE(TC_H_INGRESS, 0); } else { if (handle == 0) { diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 35963929e117..e43a45499372 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -140,7 +140,7 @@ static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { .cl_ops = &ingress_class_ops, .id = "ingress", .priv_size = sizeof(struct ingress_sched_data), - .static_flags = TCQ_F_CPUSTATS, + .static_flags = TCQ_F_INGRESS | TCQ_F_CPUSTATS, .init = ingress_init, .destroy = ingress_destroy, .dump = ingress_dump, @@ -281,7 +281,7 @@ static struct Qdisc_ops clsact_qdisc_ops __read_mostly = { .cl_ops = &clsact_class_ops, .id = "clsact", .priv_size = sizeof(struct clsact_sched_data), - .static_flags = TCQ_F_CPUSTATS, + .static_flags = TCQ_F_INGRESS | TCQ_F_CPUSTATS, .init = clsact_init, .destroy = clsact_destroy, .dump = ingress_dump, From patchwork Wed May 24 01:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98234 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2527554vqo; Tue, 23 May 2023 18:27:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bYsYYweMjxGnZLyeXK6V1bWn7ZdoGBEjScOgJUvLLO9H9B85XQEvmNUOKAmBpbP15PUzd X-Received: by 2002:a05:6a20:258b:b0:10c:18a3:cbb6 with SMTP id k11-20020a056a20258b00b0010c18a3cbb6mr6524509pzd.10.1684891677282; Tue, 23 May 2023 18:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891677; cv=none; d=google.com; s=arc-20160816; b=aKzggam8RmAqQKUPwxJAL2MeCcAy00PcAk48IcmA2/F0ar+Z6IjQgN1y0N6DIGnXE8 FB2l2ITz7KBuGuPN8iOCJ0Nc63kQhat9lgEaoUM4AwxSR71sQ59KOw/dzejdylpncBp4 x7zTDBlPrxm62C/HiqaxBkNXn5D6ujt7eYw//YYf2yw5zJoLTWzHBD4frvaDm+WlBNNV wKDsu2PWY7GjJN3LeHk1QC3WGIEHw1lhrPxh2XODjxTsO6nJS8BcOmwmK7czLmY7nsPP wPD26jDM66Y2nokIB/gw0MGGzWWtlTfLlNnax6WxS6ljgDiaQlS05FoglNFqKJIPvG9E iqqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TTODVV/LQUtZuq/RjLJcuBFwBujVuHAiJuRPCFPbCjM=; b=ji48IzgalCkTAPKhfDNEjp6v71muGfbhJOJdOejwaPuwKCPlKVqB+N6PWCZlcfJ9dS 74rSy1Biw1PdDwWaXsl5dg1tvLIN+bXMf9fFe3PyO6RWdse6J5P5yNF2djUzWEbn0Cb5 gbZJNV/EzsfE4te4k0KyGNd7ZfwuX3PLcZtq+Z6G2ZqxldImfULr2N8p5MCnM+5MwjPn 6CG0WKdNqXAGCbnfQfboZo+x5j9sMvSu10Xg/j4Qz+0MNRlrrC41C6eQLD+PXOJw60/S BcaZEV6x3QE2ZA1nsHdYJVAeWNdPAE1GmStDwn+BlZUtHdqVzFACdkA1qaE5Au+j43zu Nxig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BrzggDAg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j15-20020a633c0f000000b0053efcd2001fsi955887pga.883.2023.05.23.18.27.40; Tue, 23 May 2023 18:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BrzggDAg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238867AbjEXBTs (ORCPT + 99 others); Tue, 23 May 2023 21:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230490AbjEXBTp (ORCPT ); Tue, 23 May 2023 21:19:45 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8365F127; Tue, 23 May 2023 18:19:43 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-75b0df81142so78112585a.2; Tue, 23 May 2023 18:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891182; x=1687483182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TTODVV/LQUtZuq/RjLJcuBFwBujVuHAiJuRPCFPbCjM=; b=BrzggDAga5Rt3a3iEX7vGPEPt9SXVvN3Cnmu+jq6buGccnno5pp2RlpBZmRBZCPww6 OwbmSmBRlyXtf1Av66MLqOLLmZwzCBTcKxztaLXj4xreZeEUGfh2ViqVc5e5T4BhAP+X 1ASjtc6Ee/bGG16bbymk2qaG6SBGQFNeTXsbQMpxpcbZ8V3jfOKiv0E1YeSR73mLZJga qb+T5v7D4dK66cfBrMLE7SD+i3CzH0HgI8e7T2C6+BgKflxzNPu2h3P1nrDPi5/bra+C 5igsrdlal26mnn+bFgQZ9Di7wrdQW00BLddUjI6LrdcbnXYep6VTHDg5T9Q9VkRTpFY8 7WwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891182; x=1687483182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TTODVV/LQUtZuq/RjLJcuBFwBujVuHAiJuRPCFPbCjM=; b=GBDSHsic5eRpKIZTNeWz6pvBzkc38MgnUitCmmgxHUmLaOoEOgGLnaDqAqkNykrr3U FnlXdWbohHqXPxzBmuiDjSU56fE8AYhrknKeSpOGfTY4aNEhat/1daZhf33l5GN/itPc fxGWaRQHKBKuxqGLqxHhOE/hdgFg0/H5V+gkgTfyGTCpe0j92+MWdbFGSwvEWVTIJYV3 Ureas+xvWrtgm5NNPqmb9g9HoZwSKztqPoPRQL91VIeuOt2aYOluiFQ8/M1gTpi9I6uf qMcF1n4WXFGOhXiVxgE9vYWUWc9P+ofQEQ/ijWZ7T8ZW3Yx/G/GPdzIENUbgRQaw3YTz OelA== X-Gm-Message-State: AC+VfDzvqiOg1mozKxBsQHNGda43mqRvOeW3BboS5TQDOP4TLYOkYPSx Cut4u1Tgo/j0M1Xmk9kN1g== X-Received: by 2002:a05:6214:f0a:b0:5f1:683e:9bd6 with SMTP id gw10-20020a0562140f0a00b005f1683e9bd6mr28074624qvb.9.1684891182604; Tue, 23 May 2023 18:19:42 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id t27-20020a05622a181b00b003e3921077d9sm3347317qtc.38.2023.05.23.18.19.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:19:42 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 4/6] net/sched: Prohibit regrafting ingress or clsact Qdiscs Date: Tue, 23 May 2023 18:19:28 -0700 Message-Id: <81628172b6ffe1dee6dbe4a829753e0d97f61a48.1684887977.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766736975319011385?= X-GMAIL-MSGID: =?utf-8?q?1766736975319011385?= From: Peilin Ye Currently, after creating an ingress (or clsact) Qdisc and grafting it under TC_H_INGRESS (TC_H_CLSACT), it is possible to graft it again under e.g. a TBF Qdisc: $ ip link add ifb0 type ifb $ tc qdisc add dev ifb0 handle 1: root tbf rate 20kbit buffer 1600 limit 3000 $ tc qdisc add dev ifb0 clsact $ tc qdisc link dev ifb0 handle ffff: parent 1:1 $ tc qdisc show dev ifb0 qdisc tbf 1: root refcnt 2 rate 20Kbit burst 1600b lat 560.0ms qdisc clsact ffff: parent ffff:fff1 refcnt 2 ^^^^^^^^ clsact's refcount has increased: it is now grafted under both TC_H_CLSACT and 1:1. ingress and clsact Qdiscs should only be used under TC_H_INGRESS (TC_H_CLSACT). Prohibit regrafting them. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 1f211a1b929c ("net, sched: add clsact qdisc") Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim Signed-off-by: Peilin Ye Tested-by: Pedro Tammela --- change in v3, v4: - add in-body From: tag net/sched/sch_api.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 383195955b7d..49b9c1bbfdd9 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1596,6 +1596,11 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, NL_SET_ERR_MSG(extack, "Invalid qdisc name"); return -EINVAL; } + if (q->flags & TCQ_F_INGRESS) { + NL_SET_ERR_MSG(extack, + "Cannot regraft ingress or clsact Qdiscs"); + return -EINVAL; + } if (q == p || (p && check_loop(q, p, 0))) { NL_SET_ERR_MSG(extack, "Qdisc parent/child loop detected"); From patchwork Wed May 24 01:20:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2528083vqo; Tue, 23 May 2023 18:29:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Qr8lx8Xm8b1EpPDVwCxUEJQPLqJc0K7mDf+hvDIf7rDS0uZQ95CdxX2sKhxNFhIzSRt+1 X-Received: by 2002:a17:902:7587:b0:1ae:3bfb:f58b with SMTP id j7-20020a170902758700b001ae3bfbf58bmr12500558pll.64.1684891777546; Tue, 23 May 2023 18:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891777; cv=none; d=google.com; s=arc-20160816; b=Vu7PmtXtL4thFfIwcrIF94nx/+a/eDgOe+EmIgk6SZxt/RtZOhB5LWNmlr9hbzB0vr r6TBPKaEolYOOguvR7lICu7WXhUo9kF6MTBNG5F10mpovjOtZJkNYsAJziGX3hnFImxd lqNnGU2pZZjUKb5/RjRh1GNm1g0T8vyOFSPlQfGqXyc2IO/6bhkvablh3iD+2584jDRN KMOQd7D7KookdRrRsYa0pgVl0ZQrood6WoLPddxxQqPVb6g2LC4ZPrNrj+iyb8CQfO9j 5NhwA95V3x6Epx6N3cPXuPHlIazRyjozNaR0g2JI7OpCMDXHIjHI0UGsgES9EWX0ebns uIYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=84jCH5csYFlMMdBF7z2xCF1DPFHya9qG/1Sk/ks2VEQ=; b=xQxvL2wF1yv+xl5hTX2pQ/yUQvqE6UQa+tFr8+E9J2NGv5GydG+3VVnVCsVntR8u6I Nhahdi4wb8vxhnnscduwj+fd7X/ArpSejX5NUHghkfvhj17udWfbcP8f4Z9jYwhbOK4A NObFcAHHbg9n/mcpHS+SA8kJMqiUs3HI5id9XZnavZt4/PA33+EpzVQZQ47ZVbpQ5xZs +u+NXw3IflsfNcjuJszuV8zu8D3TBEX/rijp87jBHAuv5DibqHXO0JJrYL/CHvU3hnI+ Z8KxmN1HHPPZjbphpSwF6AfhF5/fME7i9yvkmXBjmprJZWeafwf4ynG2gxDrnkPVt85Z J/NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hOcUcInM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij25-20020a170902ab5900b001aaf59c9633si2347038plb.565.2023.05.23.18.29.18; Tue, 23 May 2023 18:29:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hOcUcInM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238853AbjEXBU0 (ORCPT + 99 others); Tue, 23 May 2023 21:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234246AbjEXBUY (ORCPT ); Tue, 23 May 2023 21:20:24 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBB4129; Tue, 23 May 2023 18:20:10 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-3f6bb5e8ed2so3665891cf.0; Tue, 23 May 2023 18:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891210; x=1687483210; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=84jCH5csYFlMMdBF7z2xCF1DPFHya9qG/1Sk/ks2VEQ=; b=hOcUcInMs4JnVjQj2ZGvkpXlgz5dC1ExyBx89pSGavh3uY3f/mXgkaIXKa/ttgPc4a tG52vcl5hWvhNvGdfeDx5/3CuBgpEImIEFa5n9oZUpcVslaKy9/Uo+9o0grj2HIRnSWE 0aoImLF8dqdzIyO1EePCTTfboXa4mEb4v1fm3dkTIH4TrrPk0+7d9Gs7ZatiZfl2O1fm 2I+xYJwIEWYFkIjjEg36HQuXEqxNnhWU6V0v60Qgt+H1462O6vMV/zkciG/1TZT5QHU9 4BizBXXqmRkORlq3hMLjV2zVGWnVNq7UPZ3Qb/cDqgp+0KW596oAR/OfAamUy3RM/YKT qZSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891210; x=1687483210; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=84jCH5csYFlMMdBF7z2xCF1DPFHya9qG/1Sk/ks2VEQ=; b=gp5/pi2kv3u3AUXeCGHYrUypqebQFEg52O8ZE7AzoqKujZFK53Jn7tTANfQy6OPZZe fs0Ip/0uQjLOlwHAbJ2jCtiuycw3KHa+PtA6IVM5zgkgQRhKdFgSUDo1J4dgS1KvcRt1 9+DMynS5nVwfy9c6VI5Fe9mwurcTHTrRZ+xZmHFm5urmWx69my06iDIuLaavHa+Bzug+ iMvctWo2T6WQ5pZNgR712lJ60/ClF8/YmrCqqI2MDdB4Qd629olKhZVWCCVSF+++yDHi +0kfkmJwOeqQUF8hm6Znnd4KdjrgF3XYD4hpUxfeEZ7rNq8umT9iRXXsrk/kF0ARgcbX kJpQ== X-Gm-Message-State: AC+VfDxX8IUd4eQ20JjNc3V9kViCUW7w6Lq+ThYfd5RODI37tYT3Kp1m lsvzeKYT+RSC746E1i37MSNcV3vNKg== X-Received: by 2002:a05:622a:652:b0:3e6:3851:b945 with SMTP id a18-20020a05622a065200b003e63851b945mr24754439qtb.67.1684891210003; Tue, 23 May 2023 18:20:10 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id g14-20020ac8774e000000b003e38c9a2a22sm3298930qtu.92.2023.05.23.18.20.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:20:09 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 5/6] net/sched: Refactor qdisc_graft() for ingress and clsact Qdiscs Date: Tue, 23 May 2023 18:20:02 -0700 Message-Id: <304dfaef69e0212b98c355a45daf85316d7ce47d.1684887977.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766737080490257368?= X-GMAIL-MSGID: =?utf-8?q?1766737080490257368?= From: Peilin Ye Grafting ingress and clsact Qdiscs does not need a for-loop in qdisc_graft(). Refactor it. No functional changes intended. Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim Tested-by: Pedro Tammela Signed-off-by: Peilin Ye --- change in v3, v4: - add in-body From: tag net/sched/sch_api.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 49b9c1bbfdd9..f72a581666a2 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1073,12 +1073,12 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, if (parent == NULL) { unsigned int i, num_q, ingress; + struct netdev_queue *dev_queue; ingress = 0; num_q = dev->num_tx_queues; if ((q && q->flags & TCQ_F_INGRESS) || (new && new->flags & TCQ_F_INGRESS)) { - num_q = 1; ingress = 1; if (!dev_ingress_queue(dev)) { NL_SET_ERR_MSG(extack, "Device does not have an ingress queue"); @@ -1094,18 +1094,18 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, if (new && new->ops->attach && !ingress) goto skip; - for (i = 0; i < num_q; i++) { - struct netdev_queue *dev_queue = dev_ingress_queue(dev); - - if (!ingress) + if (!ingress) { + for (i = 0; i < num_q; i++) { dev_queue = netdev_get_tx_queue(dev, i); + old = dev_graft_qdisc(dev_queue, new); - old = dev_graft_qdisc(dev_queue, new); - if (new && i > 0) - qdisc_refcount_inc(new); - - if (!ingress) + if (new && i > 0) + qdisc_refcount_inc(new); qdisc_put(old); + } + } else { + dev_queue = dev_ingress_queue(dev); + old = dev_graft_qdisc(dev_queue, new); } skip: From patchwork Wed May 24 01:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 98238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2528170vqo; Tue, 23 May 2023 18:29:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lKjhSGbpz3N4K+7I1FZbtaf5+BWk5YyoGHu8NLiRSQSyT8a3mxDLqp5OX3/wPYXj269WR X-Received: by 2002:a05:6a00:c8d:b0:64c:9972:f74b with SMTP id a13-20020a056a000c8d00b0064c9972f74bmr1107968pfv.12.1684891797800; Tue, 23 May 2023 18:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684891797; cv=none; d=google.com; s=arc-20160816; b=Ur5Q5+3j6zcDQgodIc+ZyMOd3BqB6uF0FDo1qLrDtumaUNsZbfI4jFZlFf5fa6S80I ChwdP7/HjEOuqZ9sMLj0XLC/L1Ma25TI7dMLp8Kv/q1COAfyFhGC4/YxX0dnV90vCUE4 OyZyND3yyOY82qk5R3xXQE5IhCLWptB4NMBxVoh/D24mzu5RO0fHT5eymE0aede+DGG1 qLXHEeC1GhBRSPgyeCOiP9z6CqUZZPSUZSBioPg6CVDXldd78jM+/NeBTkEMYTCCl1nD gPwtmttRpxFUvNaccGhXdIZZKBcWGmwGB5ckbQoZU3s7+TIx3Wc5QETL0pyUec/WzWWn LCyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tKpUR2FFpXmH27P+0k3LZaBzm4wZrrFObgzzkOXFaAo=; b=HjoQ3+5cJBWJlu1X0hYFTs2j/ohns5SIh9Ucp0CWSzXKWghA72j3szqBgLtYKLWxtl p2ViOuFH6vKEgpYjth7e/hCt62o+fVacg0cB9Wymw0XVowY/fPnEwotpPZVt/qbgqwiT 14kbvLi36rxZmWeMZ0grU/MbbCxvAYBFWJgEvJ4knXcE264RIuOdCdCj+Ghe5MqOUrTq apAHhSscsfDF+G/mVRPQVrugY7zq2Z3t+YRQvldmSFhd6EMhYIGIzn4oqH4JxCw6D15z dQ4TmA15AdKZWrJzu2hl/ckuAOH4TOdZ2NetTOFfPQgFe1DpjQQ3pyrhPPW95Z+JPsaq Urzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=efMfi9QM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a633301000000b0050309caf60esi7553667pgz.750.2023.05.23.18.29.43; Tue, 23 May 2023 18:29:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=efMfi9QM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238955AbjEXBUn (ORCPT + 99 others); Tue, 23 May 2023 21:20:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238950AbjEXBUl (ORCPT ); Tue, 23 May 2023 21:20:41 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8F1127; Tue, 23 May 2023 18:20:34 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-75b1219506fso49849385a.1; Tue, 23 May 2023 18:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684891234; x=1687483234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tKpUR2FFpXmH27P+0k3LZaBzm4wZrrFObgzzkOXFaAo=; b=efMfi9QMl8QWY/ux4eAXzVEX+V70xaI3MurHUynBLz+plLkXN4MdhgAsxDmQfgIB8H ROtuL/tN/0JJlX5c/eaDT+f1e+AoFk9bq+Oc0Nr9TkM2+gVguu1QvnTxHhvNKXoutoyB Ff49L8zUQ9R5s8oRMfFyS6S+MfVrt/PJKfsQ9N6fkKDvMcL/b0zRFf6HtZUfmbXn8yHT B5YrM2Wnp7ezjAQcdgk2XVh4puSXNR8T4H3mxDpXZ8xxAGj8eRuZyI/L/j4wzLY6FcOa CyRZCrT2EJkDhfqbkQ+yp4Y//ySzHKaFAI3tuUOlzbzsEbni+CwPl7gmUixo74MXNDDR akCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684891234; x=1687483234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tKpUR2FFpXmH27P+0k3LZaBzm4wZrrFObgzzkOXFaAo=; b=df+FqzfmGjOhk8VSoCHz0EcqnWYaIsJ7JnJR2pOlekAodoiODWRbvARAUrphSYeAug kwDDMxckNg/mNvtZlHMMoXeWmkoa2TUHxmJYWuGdfc7wfwt9T9LK3pMNqPh1FOfrBJ1E zgfIklxRLf3yPJKiiDfsO5V2mlZi/UdtkVPDmUapZkGk+BIX8NRPHHxqe3xZlN3ckaFK Tul/RAiKfOJnkeUuahM1P36WOwFDSLrbyuqbGd0wNK+kbI5pnEN779YPInr6NuA6mWrG pfFKb5whw2YCEvsJQUv/2isVGMUZaWIPgfnZJrzMDDnBM9AAdnV3D8NQqeO1CMpBqSDx 8r1Q== X-Gm-Message-State: AC+VfDyukoUV9EDOps27lezkn20cXig9GhFBLEMzI8m2qnz8psOfQY+A +yaua8Qz+8YMVLaI337WZg== X-Received: by 2002:a37:c48:0:b0:75b:23a1:8e4e with SMTP id 69-20020a370c48000000b0075b23a18e4emr6207392qkm.31.1684891233700; Tue, 23 May 2023 18:20:33 -0700 (PDT) Received: from C02FL77VMD6R.bytedance.net ([2600:1700:d860:12b0:c32:b55:eaec:a556]) by smtp.gmail.com with ESMTPSA id p16-20020ae9f310000000b007577d3d1f65sm2916899qkg.7.2023.05.23.18.20.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 May 2023 18:20:33 -0700 (PDT) From: Peilin Ye X-Google-Original-From: Peilin Ye To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: Peilin Ye , Daniel Borkmann , John Fastabend , Vlad Buslov , Pedro Tammela , Hillf Danton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang , Peilin Ye Subject: [PATCH v5 net 6/6] net/sched: qdisc_destroy() old ingress and clsact Qdiscs before grafting Date: Tue, 23 May 2023 18:20:20 -0700 Message-Id: <429357af094297abbc45f47b8e606f11206df049.1684887977.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766737101541561613?= X-GMAIL-MSGID: =?utf-8?q?1766737101541561613?= From: Peilin Ye mini_Qdisc_pair::p_miniq is a double pointer to mini_Qdisc, initialized in ingress_init() to point to net_device::miniq_ingress. ingress Qdiscs access this per-net_device pointer in mini_qdisc_pair_swap(). Similar for clsact Qdiscs and miniq_egress. Unfortunately, after introducing RTNL-unlocked RTM_{NEW,DEL,GET}TFILTER requests (thanks Hillf Danton for the hint), when replacing ingress or clsact Qdiscs, for example, the old Qdisc ("@old") could access the same miniq_{in,e}gress pointer(s) concurrently with the new Qdisc ("@new"), causing race conditions [1] including a use-after-free bug in mini_qdisc_pair_swap() reported by syzbot: BUG: KASAN: slab-use-after-free in mini_qdisc_pair_swap+0x1c2/0x1f0 net/sched/sch_generic.c:1573 Write of size 8 at addr ffff888045b31308 by task syz-executor690/14901 ... Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106 print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:319 print_report mm/kasan/report.c:430 [inline] kasan_report+0x11c/0x130 mm/kasan/report.c:536 mini_qdisc_pair_swap+0x1c2/0x1f0 net/sched/sch_generic.c:1573 tcf_chain_head_change_item net/sched/cls_api.c:495 [inline] tcf_chain0_head_change.isra.0+0xb9/0x120 net/sched/cls_api.c:509 tcf_chain_tp_insert net/sched/cls_api.c:1826 [inline] tcf_chain_tp_insert_unique net/sched/cls_api.c:1875 [inline] tc_new_tfilter+0x1de6/0x2290 net/sched/cls_api.c:2266 ... @old and @new should not affect each other. In other words, @old should never modify miniq_{in,e}gress after @new, and @new should not update @old's RCU state. Fixing without changing sch_api.c turned out to be difficult (please refer to Closes: for discussions). Instead, make sure @new's first call always happen after @old's last call, in qdisc_destroy(), has finished: In qdisc_graft(), return -EAGAIN and tell the caller to replay (suggested by Vlad Buslov) if @old has any ongoing RTNL-unlocked filter requests, and call qdisc_destroy() for @old before grafting @new. Introduce qdisc_refcount_dec_if_one() as the counterpart of qdisc_refcount_inc_nz() used for RTNL-unlocked filter requests. Introduce a non-static version of qdisc_destroy() that does a TCQ_F_BUILTIN check, just like qdisc_put() etc. Depends on patch "net/sched: Refactor qdisc_graft() for ingress and clsact Qdiscs". [1] To illustrate, the syzkaller reproducer adds ingress Qdiscs under TC_H_ROOT (no longer possible after patch "net/sched: sch_ingress: Only create under TC_H_INGRESS") on eth0 that has 8 transmission queues: Thread 1 creates ingress Qdisc A (containing mini Qdisc a1 and a2), then adds a flower filter X to A. Thread 2 creates another ingress Qdisc B (containing mini Qdisc b1 and b2) to replace A, then adds a flower filter Y to B. Thread 1 A's refcnt Thread 2 RTM_NEWQDISC (A, RTNL-locked) qdisc_create(A) 1 qdisc_graft(A) 9 RTM_NEWTFILTER (X, RTNL-unlocked) __tcf_qdisc_find(A) 10 tcf_chain0_head_change(A) mini_qdisc_pair_swap(A) (1st) | | RTM_NEWQDISC (B, RTNL-locked) RCU sync 2 qdisc_graft(B) | 1 notify_and_destroy(A) | tcf_block_release(A) 0 RTM_NEWTFILTER (Y, RTNL-unlocked) qdisc_destroy(A) tcf_chain0_head_change(B) tcf_chain0_head_change_cb_del(A) mini_qdisc_pair_swap(B) (2nd) mini_qdisc_pair_swap(A) (3rd) | ... ... Here, B calls mini_qdisc_pair_swap(), pointing eth0->miniq_ingress to its mini Qdisc, b1. Then, A calls mini_qdisc_pair_swap() again during ingress_destroy(), setting eth0->miniq_ingress to NULL, so ingress packets on eth0 will not find filter Y in sch_handle_ingress(). This is only one of the possible consequences of concurrently accessing miniq_{in,e}gress pointers. The point is clear though: again, A should never modify those per-net_device pointers after B, and B should not update A's RCU state. Fixes: 7a096d579e8e ("net: sched: ingress: set 'unlocked' flag for Qdisc ops") Fixes: 87f373921c4e ("net: sched: ingress: set 'unlocked' flag for clsact Qdisc ops") Reported-by: syzbot+b53a9c0d1ea4ad62da8b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/0000000000006cf87705f79acf1a@google.com/ Cc: Hillf Danton Cc: Vlad Buslov Signed-off-by: Peilin Ye Tested-by: Pedro Tammela Acked-by: Jamal Hadi Salim --- change in v5: - reinitialize @q, @p (suggested by Vlad) and @tcm before replaying, just like @flags in tc_new_tfilter() change in v3, v4: - add in-body From: tag changes in v2: - replay the request if the current Qdisc has any ongoing RTNL-unlocked filter requests (Vlad) - minor changes in code comments and commit log include/net/sch_generic.h | 8 ++++++++ net/sched/sch_api.c | 40 ++++++++++++++++++++++++++++++--------- net/sched/sch_generic.c | 14 +++++++++++--- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index fab5ba3e61b7..3e9cc43cbc90 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -137,6 +137,13 @@ static inline void qdisc_refcount_inc(struct Qdisc *qdisc) refcount_inc(&qdisc->refcnt); } +static inline bool qdisc_refcount_dec_if_one(struct Qdisc *qdisc) +{ + if (qdisc->flags & TCQ_F_BUILTIN) + return true; + return refcount_dec_if_one(&qdisc->refcnt); +} + /* Intended to be used by unlocked users, when concurrent qdisc release is * possible. */ @@ -652,6 +659,7 @@ void dev_deactivate_many(struct list_head *head); struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue, struct Qdisc *qdisc); void qdisc_reset(struct Qdisc *qdisc); +void qdisc_destroy(struct Qdisc *qdisc); void qdisc_put(struct Qdisc *qdisc); void qdisc_put_unlocked(struct Qdisc *qdisc); void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, int n, int len); diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index f72a581666a2..286b7c58f5b9 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1080,10 +1080,18 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, if ((q && q->flags & TCQ_F_INGRESS) || (new && new->flags & TCQ_F_INGRESS)) { ingress = 1; - if (!dev_ingress_queue(dev)) { + dev_queue = dev_ingress_queue(dev); + if (!dev_queue) { NL_SET_ERR_MSG(extack, "Device does not have an ingress queue"); return -ENOENT; } + + /* Replay if the current ingress (or clsact) Qdisc has ongoing + * RTNL-unlocked filter request(s). This is the counterpart of that + * qdisc_refcount_inc_nz() call in __tcf_qdisc_find(). + */ + if (!qdisc_refcount_dec_if_one(dev_queue->qdisc_sleeping)) + return -EAGAIN; } if (dev->flags & IFF_UP) @@ -1104,8 +1112,16 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, qdisc_put(old); } } else { - dev_queue = dev_ingress_queue(dev); - old = dev_graft_qdisc(dev_queue, new); + old = dev_graft_qdisc(dev_queue, NULL); + + /* {ingress,clsact}_destroy() @old before grafting @new to avoid + * unprotected concurrent accesses to net_device::miniq_{in,e}gress + * pointer(s) in mini_qdisc_pair_swap(). + */ + qdisc_notify(net, skb, n, classid, old, new, extack); + qdisc_destroy(old); + + dev_graft_qdisc(dev_queue, new); } skip: @@ -1119,8 +1135,6 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, if (new && new->ops->attach) new->ops->attach(new); - } else { - notify_and_destroy(net, skb, n, classid, old, new, extack); } if (dev->flags & IFF_UP) @@ -1450,19 +1464,22 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, struct netlink_ext_ack *extack) { struct net *net = sock_net(skb->sk); - struct tcmsg *tcm = nlmsg_data(n); struct nlattr *tca[TCA_MAX + 1]; struct net_device *dev; + struct Qdisc *q, *p; + struct tcmsg *tcm; u32 clid; - struct Qdisc *q = NULL; - struct Qdisc *p = NULL; int err; +replay: err = nlmsg_parse_deprecated(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy, extack); if (err < 0) return err; + tcm = nlmsg_data(n); + q = p = NULL; + dev = __dev_get_by_index(net, tcm->tcm_ifindex); if (!dev) return -ENODEV; @@ -1515,8 +1532,11 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, return -ENOENT; } err = qdisc_graft(dev, p, skb, n, clid, NULL, q, extack); - if (err != 0) + if (err != 0) { + if (err == -EAGAIN) + goto replay; return err; + } } else { qdisc_notify(net, skb, n, clid, NULL, q, NULL); } @@ -1704,6 +1724,8 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, if (err) { if (q) qdisc_put(q); + if (err == -EAGAIN) + goto replay; return err; } diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 37e41f972f69..e14ed47f961c 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1046,7 +1046,7 @@ static void qdisc_free_cb(struct rcu_head *head) qdisc_free(q); } -static void qdisc_destroy(struct Qdisc *qdisc) +static void __qdisc_destroy(struct Qdisc *qdisc) { const struct Qdisc_ops *ops = qdisc->ops; @@ -1070,6 +1070,14 @@ static void qdisc_destroy(struct Qdisc *qdisc) call_rcu(&qdisc->rcu, qdisc_free_cb); } +void qdisc_destroy(struct Qdisc *qdisc) +{ + if (qdisc->flags & TCQ_F_BUILTIN) + return; + + __qdisc_destroy(qdisc); +} + void qdisc_put(struct Qdisc *qdisc) { if (!qdisc) @@ -1079,7 +1087,7 @@ void qdisc_put(struct Qdisc *qdisc) !refcount_dec_and_test(&qdisc->refcnt)) return; - qdisc_destroy(qdisc); + __qdisc_destroy(qdisc); } EXPORT_SYMBOL(qdisc_put); @@ -1094,7 +1102,7 @@ void qdisc_put_unlocked(struct Qdisc *qdisc) !refcount_dec_and_rtnl_lock(&qdisc->refcnt)) return; - qdisc_destroy(qdisc); + __qdisc_destroy(qdisc); rtnl_unlock(); } EXPORT_SYMBOL(qdisc_put_unlocked);