From patchwork Sat May 6 00:12:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp783927vqo; Fri, 5 May 2023 17:57:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ihN2rkmilZKYZ6zDpKN5V6hAOPw3ZvO5XCmDcEy7uWIEyrDkavf7wQL7pYCA5m4Q0y/dh X-Received: by 2002:a17:902:d483:b0:1ab:2a89:ed9d with SMTP id c3-20020a170902d48300b001ab2a89ed9dmr3785435plg.10.1683334624101; Fri, 05 May 2023 17:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683334624; cv=none; d=google.com; s=arc-20160816; b=SbjM4rz1K5GxZf1Flo5cUo5+kV5Lke1sOHcwZ5DSW0ltDxByDcY+kQ4oXCCY+LqwRy x/yrc60ZI5tRIAI7NWRsdGX0TX/H5F1udor7kz+++cCNQbRXOg3cNxTQ+RIXd6Ajk1Li 6Ua2LqkF2nio+UR1y7EG5sTN+qmCTY7b/yIRmhESRI26Am3SK/pGqONewWX5+QSVRD10 yRSr2LKC/mw84fIY7bJ3Vn5JtRLQijphdZj0Uihs+QUcTt2aPwILjDVWXimKoa2gBpZZ CgvjR5NXkIWXklmCjsnUbBcAJEAS27Urg3UkzUiYpl1CEeNLSfhIV/wqwKPOh+zNL7OL 9g+w== 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=i/2a2fmRaVPEPp2SSETeOf9kawD9M9PLZwiVrKPPSQY=; b=BPaqzLASyoC0eC1hA6FUsKxjgBNiw8Dk0Th68L+KwIhpwSFJqP7fJPfdDVdego3TlW PqKpN9Xh3atsXVr/bzgRCwhSHrPuKq2xaZ/f+wKffheIxASlMoD9ibTvBgmyQCdqITpy wTlzcdkl7Fe4sBsM84KtFIpCQIwR+Q3Hxd8BIzRuhQAO70IGdSh+9mUKUPW6Vqpb7PPW n2lJ1vop0//MkxCOJdTqT4a1No+7BtTyK6NzKt8mHLZiDWzNNor8nc5DSXjvNKc0bRWc AZVaMD1kXcwoVneaoGpzxgiADffmq/63HOh/zAY3FroqbFobtFqhQQ1et4dgjip8prK0 JWIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=CxrOtlBi; 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 bf9-20020a170902b90900b001aaecc8a84dsi2651476plb.645.2023.05.05.17.56.51; Fri, 05 May 2023 17:57:04 -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=CxrOtlBi; 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 S230400AbjEFAMe (ORCPT + 99 others); Fri, 5 May 2023 20:12:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjEFAMc (ORCPT ); Fri, 5 May 2023 20:12:32 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420A6659B; Fri, 5 May 2023 17:12:31 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-55a829411b5so22455897b3.1; Fri, 05 May 2023 17:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683331950; x=1685923950; 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=i/2a2fmRaVPEPp2SSETeOf9kawD9M9PLZwiVrKPPSQY=; b=CxrOtlBiwg4s9rfgq1NtTTDlmpby0f6ol7PjTQ3rv2KCdADYKCJX6/woREeP/oxuMM idy8F9tgM6fXoB45VbLt/lKYUq0ofl+ecMnWMFkNOpRcNwTRdSUYzbNiUTmOmy6SUmVW 3ss6EgBTlQNU0TUNYInGrGEvkXpyN792OyEUvYvenPLwFy0vT7yMiGjCDR6Ojbp1OPKE xpmz7911Saafm1DBQK9VI48gViPqLu5upXBVph5/GBNVuTlyx+egZV3Viog8/40UCNj/ V9Qs8/8k6yo27BfQxYgghd5B72QBfMzzlgwk6lOm+X9AzOQmiiKq3bZk/7XcT7kHhYnA 1mbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683331950; x=1685923950; 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=i/2a2fmRaVPEPp2SSETeOf9kawD9M9PLZwiVrKPPSQY=; b=aN9eYHFmAXBKFnEg1OJPOPV6GCCRFXN+bLwo/IantjHyxTf+6xZaYxhSzFy5fO88EJ xatI3wUe4ZXx/GsUdxk4+7p1H3TZPiEg3rnwnbvyg5H4eT5u2C42LrSJk9dp0+N0mVpR MPJdfMVjxhcuax92w+2kym2QoNbxCDkbN0no2qzOIivR2KZNWqz+GKeP0xDgWLT84JPH u3hfXRYkKaJd+T/BEJQ6CVcvqb/uwjIg7yeGvvk8bPfv3CQuVvihTmHzKD/jiPEaT4/K hsjv7daSRdq0vS9rUmoP0fmB5MbWCiLbkPVTCD8ORj3klkYkXMgNU2SUQlXS891h1vqZ l0Dg== X-Gm-Message-State: AC+VfDxHmdMqc4A2ZCAIe+whuNcDuEW1KSKHh2d471ae9+8qxFU+UR/c mGxijdFcSMLp+Qn9lcVbuw== X-Received: by 2002:a81:7345:0:b0:556:ea38:eb07 with SMTP id o66-20020a817345000000b00556ea38eb07mr3517093ywc.50.1683331950369; Fri, 05 May 2023 17:12:30 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id x185-20020a814ac2000000b00552a118d059sm793267ywa.117.2023.05.05.17.12.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:12:30 -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 net 1/6] net/sched: sch_ingress: Only create under TC_H_INGRESS Date: Fri, 5 May 2023 17:12:22 -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?1765104286593061998?= X-GMAIL-MSGID: =?utf-8?q?1765104286593061998?= ingress Qdiscs are only supposed to be created under TC_H_INGRESS. Similar to mq_init(), return -EOPNOTSUPP if 'parent' is not TC_H_INGRESS. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+b53a9c0d1ea4ad62da8b@syzkaller.appspotmail.com Link: https://lore.kernel.org/netdev/0000000000006cf87705f79acf1a@google.com Signed-off-by: Peilin Ye Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- net/sched/sch_ingress.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 84838128b9c5..3d71f7a3b4ad 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); From patchwork Sat May 6 00:13:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp788166vqo; Fri, 5 May 2023 18:07:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NNE1ts0h14IORxNqeANNwhid790ak2CK2gwwy6RfwXdSq0iUaCieF/vxRI50eMOWWEQCZ X-Received: by 2002:a17:902:f546:b0:1ab:1319:89f8 with SMTP id h6-20020a170902f54600b001ab131989f8mr4203058plf.32.1683335237088; Fri, 05 May 2023 18:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683335237; cv=none; d=google.com; s=arc-20160816; b=NIR3W8Rxm4rflcsSW9ucCoFnudHAOwJKFdn4vtM+lnG/Ce1iz3GSr/pDyN3WXqKRgK ibWeSgo6OvVMhSEBZlxSFAdEYLOVQszwCNjMGuhfbolpp6SP2B2Nw8lU9uGCNcnfGeSQ 91no86/KibBFbdQmzWaCfUkq2wiIdx/Y3qMalIC3rqidPVAikbg/HaTmw2xCd2vIe3NS eWl9Ff1mPEnB2/4xCvHM/Gn4F2qv8EIln4uDVJOtFJLuRjHttnjAPIESQAS8JuJSoyJu ehNDO407iqcGwbpRu3EASYsmszvGwqvmHVduHpTJw+uNrep8lGl+0kkxJ7YdkTlFZWLw FvHg== 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=LpQnycD4NBJS2K7bUxjOFhm2fk8qfStWlOlna9WRdZw=; b=UtIwls95LshRaWdE48r3tFaBKaHuHU9lQm2zd67xfYdsQyTYHfFK5O5XzVcLxYd1FA WZV1TSU9xwQyPVrbry5e6Cp2jXaWTo/mm6yiqRMMleiFxxcyqMjf3GPNZdQ5qC3stmWi LQK0ysvSWscEw8u84Fon4frIN/lcv8ea8TXNkC71O96wcDfJB3IR4Ceb3MVLWaQR9e49 QF8gC8P/SuMrMZCs13tjaPl6U31VTk/0HusWgaJXlvJrxjMfeaai5u2rFCQ3n5WDAW+B WO1Ca1c1hdxTAGfwE9EKLOSbENojPiWaU8fkJw2zi2CEHdeNsQKeCe/ivX7I7OSDX8t+ 67/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gHOOwYnG; 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 i188-20020a636dc5000000b005215235fbd7si3121999pgc.365.2023.05.05.18.07.01; Fri, 05 May 2023 18:07:17 -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=gHOOwYnG; 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 S231435AbjEFAN6 (ORCPT + 99 others); Fri, 5 May 2023 20:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjEFANv (ORCPT ); Fri, 5 May 2023 20:13:51 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E921C65A5; Fri, 5 May 2023 17:13:49 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-55a5e0f5b1aso23125127b3.0; Fri, 05 May 2023 17:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683332029; x=1685924029; 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=LpQnycD4NBJS2K7bUxjOFhm2fk8qfStWlOlna9WRdZw=; b=gHOOwYnGC3x7wKGcS5bH5zVlnyCwlFzmfpKYUNl8Xoi1jNkiau1YcNvRO7t0WDk+S3 j2Nn94jyo9yu7U+2iFOr/rSwTMHfuzKFCWKUbwu6eqjsJyKwzFZsi4JeGbKNzjmGKvbZ 1gIZqOTmU5slKs2lWbOKYN5QUDGnk8CwNo4wsCAknE80c6ZAlpZm/4mRi8naN2yxiW8L PJ2YE4wkqG1DqMbbthU9qBrxSlxzUWy8DYtmZZUJY+4rDw0GvHD9wX0hTcmIH17y/C06 Bg92/rWiT1dnNCAMRsvaaclugYK/WfsHyhJomevuM83/6lvYG9lYpx6o+ruSO850uL0D IiHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683332029; x=1685924029; 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=LpQnycD4NBJS2K7bUxjOFhm2fk8qfStWlOlna9WRdZw=; b=b8ncejNpfNRDct0YuGrUpUTOoZc69gEG/0Sff6Fln9Ak6M0FVQ08mwBVPSS/qLSF+6 Vp1ip5v0gw4ypvPZPQ8dT3fKcMPMA5oTFhC5GITzHusaXdwnnZE4GsGp0jQanuSIewDt LKmtNAAip56QM1xfCbYjhBHeoEYsYEYA1ODoLkCllXYDCdKWK2U4fDDvsQ8H1FwRN/+Y JsxogolTLLm8rAdvxEwdIDWrl1DD6+Vntz3PXi0q+NwZdfWBbb7v4pOI01jj/pCUWYyN QmWSkQTxeWEcRypJV9Mh/tEn7/gDrYSuqAxu2mqmvy18vHZ1Ugj++TU4tAt0G94s0JO2 pmXg== X-Gm-Message-State: AC+VfDwUBZJZF36iPxrc4coP3D9crClCFV2TvGDO5h/6zevxj3q5QS9q nwaP9SarW+252Q2FhqyW0w== X-Received: by 2002:a0d:d916:0:b0:556:b11e:ec34 with SMTP id b22-20020a0dd916000000b00556b11eec34mr3429474ywe.50.1683332029141; Fri, 05 May 2023 17:13:49 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id u185-20020a8160c2000000b00552ccda9bb3sm802377ywb.92.2023.05.05.17.13.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:13:48 -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 net 2/6] net/sched: sch_clsact: Only create under TC_H_CLSACT Date: Fri, 5 May 2023 17:13:41 -0700 Message-Id: <21f1455040137e531f64fdc4edc3d36840e076ed.1683326865.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?1765104929124372196?= X-GMAIL-MSGID: =?utf-8?q?1765104929124372196?= 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 Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- net/sched/sch_ingress.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 3d71f7a3b4ad..13218a1fe4a5 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -222,6 +222,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(); From patchwork Sat May 6 00:14:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp783839vqo; Fri, 5 May 2023 17:56:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7GoBOB4imfeflqVe6JhxdI5ONS4SckuxHT65d7X8z60HXeNo3KbNCHlUZtY/yf4YpBBxtR X-Received: by 2002:a17:903:230c:b0:1a8:1f43:70f3 with SMTP id d12-20020a170903230c00b001a81f4370f3mr3873564plh.63.1683334606222; Fri, 05 May 2023 17:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683334606; cv=none; d=google.com; s=arc-20160816; b=O1j/QuzxIHXGk2uMeZgbs/Jl296uEAm7pBRoVdfgvVQYsrY9Ih+oZUN7u25lbfMmZ6 Dl5jHaSjYxkRIkxWXQsvER6J4bz7LOuDKB3+BLjTnQJW/Bg5iIAihTq6b+VoPMcHkTj4 4F6RZfjSMawKNh3TM2QRyyPzSeoznPtCeiiMRTzy/26tnmtiAVKdY2fTCtFdj4UVcZ2t TMpscWB6OXlH4Ls6MkBcJHoEcmkbf9z2mTFouvAOVK36lWK3auSpWJJjM4k3/7cqFWWf m7HQ0q9HseIhoUv7DkJuD8h3lv8mTjctChOrB8oeBAUhIO6RaFCrnTp38OznpjAgacCf 6UoQ== 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=8a8CBrqerMNM81FeXTG90ZuWVi7X7KBRpVk7Q/RxZcE=; b=f4BLcStEsZfLrIWXYjQ6WFd6o0in2MECe6ocT3tGATksCJZAvuUd+5Ns3r+Mwaynm5 y7LJpeg5vEE+j15LTZyAd7XAtbZG4U9SJtZsydI6i+d9pT69DpGZXQ2avy3DYtooN+2I Xe/J417wBLKRE3GXiwBMxdvaBbP2W10mOVPlTfUjAngFivOEP4h6ZCIy1r3HHWe62Qb/ ZW6d73fztlU73pTYKhUT+pNILjZf/dWsVsqjDvAUDDJBTFCVXRphRhm5744qYXbanvYZ vnfyL+r9SvEvSk1J4QBJ3NrM1kLN87Ldcf6SV28uVwBAo3XCsp97uDeOnVh+ZoaILWj5 0+ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QhjGtAzf; 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 b5-20020a170902e94500b0019e2bd0fea8si2884407pll.143.2023.05.05.17.56.34; Fri, 05 May 2023 17:56:46 -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=QhjGtAzf; 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 S231628AbjEFAOi (ORCPT + 99 others); Fri, 5 May 2023 20:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjEFAOg (ORCPT ); Fri, 5 May 2023 20:14:36 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E6872A7; Fri, 5 May 2023 17:14:21 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-55a5a830238so22422717b3.3; Fri, 05 May 2023 17:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683332057; x=1685924057; 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=8a8CBrqerMNM81FeXTG90ZuWVi7X7KBRpVk7Q/RxZcE=; b=QhjGtAzf0ADf3+KrDmk9mQjw9nPdcAhwjvz4xh+zD3de2THUIkL3OjYsZo79XEfebT Idrl5lxK4nSXCpc1mofdUoGYlB3H3FjzQ//h0oqkDIjsld+N7LCUrs/BQRWjA9iQg2yg 1u0IeCsI0RzeIH1iUBUgPmOpMt6IuKy9SXGDZg5C0d36yP88qoMCzDAEjxCnQjdEMeDY By51V4HQsI6ohorPzWJkR0+ttqg6aS6fG7GEkAkoN/hgLu2xf+lm1p6QzH+ZlTJCO5Sw +MwFHOglNvBmAvZH83fD9uJpzWX/LVmSkclD6wCJxWRENIuxqYCISXSuglviqDEXWCsk GaSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683332057; x=1685924057; 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=8a8CBrqerMNM81FeXTG90ZuWVi7X7KBRpVk7Q/RxZcE=; b=Rn4qLGofT5J0ffx9Y85VyXx2dXJDTPai1oo+2/SHRHwRJQg8erMK9MttoqanknSMUl 6IvqRG1m91+u5ZSWX4xVw+/MTyDhE+DJBm0a2nzMYZfZKGxHLPBBqBTdPcDYGNCoQFjQ /uYHJYfzXca+/EuuFTDJ0mvQRtHIFHvm6g3NL8/UvpeO3PqIE6GcKyx5MttATdqbnrCB cY4uUMJosww5TzNx0t0APbIUNkCtc1K4M4hOyq4NDLhcAYI4oY+ecXd8jypaBlRWELnT ZE8dRpDAut907ku9AZ++eu1X41PKGclRqwUalxCj63i+fWSSubtpavjJl9p2A5uRKpNu 9+JQ== X-Gm-Message-State: AC+VfDzAm8T6/A1oCo0giET3mmLgJLdO6IvDF1rz3+9wwvTuCUrL6Nzn +m6urDi1emwG5B4sfNSdvA== X-Received: by 2002:a0d:ddd7:0:b0:55a:4bd3:f73b with SMTP id g206-20020a0dddd7000000b0055a4bd3f73bmr4085086ywe.10.1683332056864; Fri, 05 May 2023 17:14:16 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id n82-20020a0dcb55000000b00559be540b56sm800536ywd.134.2023.05.05.17.14.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:14:16 -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 net 3/6] net/sched: Reserve TC_H_INGRESS (TC_H_CLSACT) for ingress (clsact) Qdiscs Date: Fri, 5 May 2023 17:14:07 -0700 Message-Id: <9969180f9219ed18656d8f3c92e717f6eb398aa1.1683326865.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?1765104267731068745?= X-GMAIL-MSGID: =?utf-8?q?1765104267731068745?= 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") Signed-off-by: Peilin Ye Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- 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 13218a1fe4a5..caea51e0d4e9 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c @@ -137,7 +137,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, @@ -275,7 +275,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 Sat May 6 00:14:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp781564vqo; Fri, 5 May 2023 17:49:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lMD5a/VWOWHgFMlk3j+6/KlYs+eQSW2/XaRA7sENfWPnoddo8fZ4YhZfErxNxqLBcIHOP X-Received: by 2002:a05:6a21:398a:b0:fe:29f:dc89 with SMTP id ad10-20020a056a21398a00b000fe029fdc89mr3427440pzc.20.1683334189094; Fri, 05 May 2023 17:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683334189; cv=none; d=google.com; s=arc-20160816; b=FRG/OK4yPscD9D8Y1vr9oyT9ejsYIMA2oE6UtSOQoyhRZ9txuSnp9w7GMznfCBPAPU uCptT7Pj1MVCRnZUjq99hlC7byNabZ5zIup2FabLxzJ5zj/58GlH3BMbp1JJvhaAde0f /N8T64RCVPza3aFOJ2P11GKkjibacaGKL7f2F/Q/9RZDI2iDwC53pjaiiXgtyQ47AFmN ZJjkMk0hMulfAEo9G7ECx/iXLjrkTu1JcPHUgkMmrM3sZTKpOEDw94bJ4pQhv9p9mij4 EhfEv4PY48rAvXAo4VZ255eW9Y6xYGdS9+fIXqVgxjbHDtpC3ywGjHAFofzs2a4PClm5 GT5Q== 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=R5eH6bco8EBNg+RUkT1y/nbet2LbT1MKzNNIZmJJf/I=; b=Bp8cLQDWDh8UAhJzXfFdYYnNGzIBPaeSfGG6x9tXvI/0w9sIO04F6/agr/qkCSVtxq LVpvziFZxEr5sRLnX2sdNhRD4RuJ6il7TLgPkh5trxwnBSU64vtf//VFtE9dwjQ5L4w6 H7OdDU/uxA7tj8vq20ct51NYHCuB0TU76e4wZNTQaEpit8HVzuq0EErbvCR/14PVNYHM fVKYv+VmToXK+DMOR8G01xDGE/xWbG9/oivunJom/7Qo1RQgO4Iw+SbRg+vKaAyAdU0q aeSyOPMgTIkrJ0TEr1XWV3QF3+EBdps9cavZY1Mj8Ajz1LLiVXyR4GUkOjC1Cih4e6b0 G4Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=GLdgRvgm; 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 u11-20020a6540cb000000b0051b25ff72a9si2995465pgp.889.2023.05.05.17.49.36; Fri, 05 May 2023 17:49:49 -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=GLdgRvgm; 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 S231820AbjEFAPP (ORCPT + 99 others); Fri, 5 May 2023 20:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbjEFAPL (ORCPT ); Fri, 5 May 2023 20:15:11 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D2C7298; Fri, 5 May 2023 17:14:59 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-b9e6ec482b3so3134148276.3; Fri, 05 May 2023 17:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683332098; x=1685924098; 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=R5eH6bco8EBNg+RUkT1y/nbet2LbT1MKzNNIZmJJf/I=; b=GLdgRvgmy+lIHMs//TSSKBV1q7prEBGmiOrTpubYTUMBiNdgH1R44GroLHFsS1wJal StwIZaY71xUZcAHD5DwccrbpdOU8nsh1g/1vV0bGOa32rAVxpByxhgra1psurezlKn0b cqFgdOJS1j16lD+697pewqVJR1v4Cy3oh0B76yvGHSWlyBNsPY9NyUdjYSp2kTf0P4lX m6/qGqqW2gSU6Ycr7NyV+jiuZBxySHnPOZXjxLOTzyJlBDMrRoYpcn1uk7TcpZxJKuhD rjp5yb1CXoizWx7QPpdD/gMFRarZgQ1EL3wVMwbiS9yfdr8ruuiRrOWYELf6Gt9+rLiq gDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683332098; x=1685924098; 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=R5eH6bco8EBNg+RUkT1y/nbet2LbT1MKzNNIZmJJf/I=; b=bpBh2dUeaUd56dedzry8yr5PHOjuz/DOaIGkdzUbA7KgZp0DgLrNgVxHyT83XBnYfw 1GpwLQUTwhicQ9dISiJ7rmFUdUo457YkLAyomN51oZafMqRsDXpf7FhUlfdVbTWbPO+U Pxu8wZeG1lEZn+ztcObWW8iQ1ZIr7Od4HrB7NNlQi2DsoHfTaudWvW7mNy4foTW4ybOz hx6/zgeiSCr9BSMhCG8ok7GnT6A/jpXXaV2dphIRYPnlPKwkAba2rQNBaDqWZkNKEJWp W5EDuE13FkPQ6SZOS0fSoawhZ0oDTLzS1w9O2c3ctef2RqdKl82ntChELajnW2q40mUP HuQw== X-Gm-Message-State: AC+VfDxbBcLErNP9+4Qcs81kzbVsza+aL80Hacizpm/NRJZnaF5VT/rq ja/WT3i3g8KCtWHOIt9uRA== X-Received: by 2002:a25:2fd4:0:b0:b96:6c84:9288 with SMTP id v203-20020a252fd4000000b00b966c849288mr4436859ybv.9.1683332098347; Fri, 05 May 2023 17:14:58 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id g194-20020a25dbcb000000b00b9a65b05384sm802044ybf.15.2023.05.05.17.14.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:14:58 -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 net 4/6] net/sched: Prohibit regrafting ingress or clsact Qdiscs Date: Fri, 5 May 2023 17:14:40 -0700 Message-Id: <846336873bfba19914397a1656ba1eb42051ed87.1683326865.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?1765103830677317083?= X-GMAIL-MSGID: =?utf-8?q?1765103830677317083?= 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") Signed-off-by: Peilin Ye Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim --- 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 Sat May 6 00:15:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp779916vqo; Fri, 5 May 2023 17:45:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wUh8pX8yuDoJ8AXugrcIz/PMTZBwjN4Octv8d1D2a48u/9maEyGUxLC0ox4V6nSv37vGH X-Received: by 2002:a17:90a:34c2:b0:247:1605:6e1a with SMTP id m2-20020a17090a34c200b0024716056e1amr4233044pjf.0.1683333907778; Fri, 05 May 2023 17:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683333907; cv=none; d=google.com; s=arc-20160816; b=0RTba4684D4pVjUBDXJQccVCV+a+2yUZ+fvJsgPPKKnSaJwIlP+/CMLEeMOpNvMZHH WbXdfft7J/UFZ2zT/xVgOntEQ1BFiGwTNHQ8tYP9WmkQwkoo1ASvNrmyUiu310uNPo1z vE/ykHH0TMfqPmaGOQ1oTogNwb9qnzE4KmVxIWvbR2Q7VmX2Uh5M2zpNAmSdX5IqF8Oj fuVg1tgxzGehsp+Vea0d3Gkokju9hwrTpy+fng/YlGveIOvPjeXJ+OmoLCuBiY7RNO+Y zeGH2OdF9wFxBGjKjANt3r8Jy5hm8JwMvbNZngR0e1gjELJnhS0rVyWUuUppN+BUgZxO /Oyw== 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=+Uvnsen7YTJ+/XuD5tR1o/JBOwU+HqDAI5vfYihveLM=; b=keyIXxoooT/pMq4E3rYmxrj5gsBPWGHABwcToW+sn6T/vHHxxBliVeDHDilIlAJBOk 1H92U4IIWZtMvwr2WbjkrP060HM187qGJb5ispudRBI0NjQNPA1FmAucyKtLYMMoPRyI FYLJdUlsIi8UwSfAaGtbrrmyAdDj4G8J7aEae1T0WuiZiiUr3CJ+RS5Cn3y4b8vhIegu 6gDio3BarFA5sIFjyLIhjIWuKKe/8vBSkoAumue5AS2jbFKFnhyB/gscykVfcWfITSlv JIL/+4tbAg1cjptfqRdwkLNw73/aqYgLKMJqSUGDoI0Z3Oun4AOESy5TzEqt7UjzAPi9 tDGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="FG/7OyvT"; 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 cc19-20020a17090af11300b0022c9cb7662csi591786pjb.159.2023.05.05.17.44.52; Fri, 05 May 2023 17:45:07 -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="FG/7OyvT"; 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 S231857AbjEFAPp (ORCPT + 99 others); Fri, 5 May 2023 20:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbjEFAPn (ORCPT ); Fri, 5 May 2023 20:15:43 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8196E8C; Fri, 5 May 2023 17:15:38 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-b9a6f17f2b6so16608074276.1; Fri, 05 May 2023 17:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683332137; x=1685924137; 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=+Uvnsen7YTJ+/XuD5tR1o/JBOwU+HqDAI5vfYihveLM=; b=FG/7OyvTnAQI17bZUseuqc3tFLR32GBm+HmmQnz/R7ESFNBaq0RaHWmcrWUCXyaX0H +LCzkQWwChzvo+zFbg61dq23hJn/vlefYt5k4g7R62VnAU9W/GsRGyAgh2rjkylU76AL rW0YckgHTWJaKoO9Wa4w2YVUdchsKfy7X9svgrPBQuWAHQPzMUV4e9Axt9QsYxe16e5/ fl9Qu648SF7Lvmfc0r2ZcPQ/XwuwfVljhj58NCQMpjWZUnMh7u1QryP5txNEXvB8wmma um7PoF0LVlIPWI2/NAFXyKgLJP0+vQfOepvfw7kKDkl6+Yvo6+sSev2FWUP9s57PYLk/ lntw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683332137; x=1685924137; 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=+Uvnsen7YTJ+/XuD5tR1o/JBOwU+HqDAI5vfYihveLM=; b=AyH2I5LXjz88MWjvjNavQPaoVGw4XC4qPaiyIc1kcvSspto741GNk4taMwJUjF4MHm dklbpXP3JGU7FNQjRXzLKUIizQPUPLyMLowve0uNH2IJPwG3SHpa5dq4zezUGuewoaf8 lR0R10wp05G3anVOUSLzT5pp0qMsdcFTR+kUCIXHtvP+ibzfSngP+KSPhEseAshKW/ua 8SqcVNleyAkWsS2z+l9lDBkr9mRlX7rfur6V0h4JkOoJjYCDLQA2Ji4ngzlUneYHQfBA t7285IJLc1r5SNxjoIKc1TBS/I1P3eWLWLoZTPeUMGBSK6GHlPmce2Ft1MYaPGF50k91 MoCw== X-Gm-Message-State: AC+VfDzyS04JqG3FIxcJFKJPbF8mFw7iI10JRh6aDYx/HKUNxyD+sVPX WIn8fR3Gx/n1Nr2vjNecbg== X-Received: by 2002:a25:6d09:0:b0:b9e:64b7:3e75 with SMTP id i9-20020a256d09000000b00b9e64b73e75mr5746289ybc.0.1683332137546; Fri, 05 May 2023 17:15:37 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id g4-20020a056902134400b00b7d2204cd4bsm771554ybu.21.2023.05.05.17.15.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:15:37 -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 net 5/6] net/sched: Refactor qdisc_graft() for ingress and clsact Qdiscs Date: Fri, 5 May 2023 17:15:29 -0700 Message-Id: <1cd15c879d51e38f6b189d41553e67a8a1de0250.1683326865.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?1765103535445369611?= X-GMAIL-MSGID: =?utf-8?q?1765103535445369611?= Grafting ingress and clsact Qdiscs does not need a for-loop in qdisc_graft(). Refactor it. No functional changes intended. Signed-off-by: Peilin Ye Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim Tested-by: Pedro Tammela --- 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 Sat May 6 00:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 90641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp784203vqo; Fri, 5 May 2023 17:57:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ZZu6oVW3I8xHY8nnKbPc+CBBvogB8am9R29gw30FxTUx0F+SI4QZ79IGdTWCVAkMORcwk X-Received: by 2002:a17:90b:1243:b0:24e:1df5:103f with SMTP id gx3-20020a17090b124300b0024e1df5103fmr3385773pjb.42.1683334673245; Fri, 05 May 2023 17:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683334673; cv=none; d=google.com; s=arc-20160816; b=M1NtZYYpOFF0Qfbbd6xuZ7TG8L752g5j4YnWOi0ciU6Ggf3pV6M2jyNj5vVJMfVRJy OntFjn0WASMKfh1OTwBHwD2LsveEEx1gf3wggM8dRstWkEOBkZgerRf7YWm0FfRK/Zjl kFcVWC1HL7CtxjI7QRdkPgagr3QTdtmjZLSVq/SUy3dN8WTdFMZQkclX4OoiRx6tA3+o eFm+/TO5MgkSxEuqnagfAbEu+eF/kNhJZATVWkfcwz6clUF8aME06tGXftZCgNdp5oAo RfIYsCr+0Iv55mjqYjpph2P+O8Gt3AS2jxJr+oNWrOSJWM6Q3Sg9Wb+d6yQd50VHJoEW HsGQ== 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=S7AI48GyyCwGO0uPw6kpNL/21jqgbbM33iUu+eDBZ4Y=; b=MMBdnGnF9vhVS8mXIDdamMX0A82neOVKu+ALt/eW5e3uDqpEnpZNT2sLv+QTlOV6Uq rhDSe5nU9tmYDOg5Z14vkn0hxZaKkPcjd7ArEy93MsgWjA7w3O3HynjxmhSgnqbecU6a Lk3NHhhPmeA0fiEYAGHfp2wPoB+7VehkscKzzd9TwnuKaoACkWtKcNYzBfGpSY+fOMuS TD9VHa7+2vTJUSS6M5F5yANji52DzAFFOU0HTeNRsUCMDzmR95XKbveaQV0pcBUZVNTZ A9/nKhBnG74g+QA3O52r+53gqMY+mDbmmMpqZ+GpL+UdXQ6tggEsxjJ8/2XqgHMgrIrM IJpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=EMcW+G1O; 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 b66-20020a633445000000b0052c3ca8220dsi3141217pga.196.2023.05.05.17.57.39; Fri, 05 May 2023 17:57:53 -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=EMcW+G1O; 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 S230033AbjEFAQc (ORCPT + 99 others); Fri, 5 May 2023 20:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbjEFAQa (ORCPT ); Fri, 5 May 2023 20:16:30 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2380B6E8A; Fri, 5 May 2023 17:16:29 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-55a214572e8so37257207b3.0; Fri, 05 May 2023 17:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683332188; x=1685924188; 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=S7AI48GyyCwGO0uPw6kpNL/21jqgbbM33iUu+eDBZ4Y=; b=EMcW+G1OGv1cOOhvkhP8d6xuW0h2Ccsp91rcxT9RtS2cVk3Xsrg5AHGRQVwn5v7uR3 G3IkuC64sXmHBAONIWuujF6i3FldimDXWvD0eCHna6m3iLYDrjRgWUulqsHd25DSJi2c wC/3AYCSn4HHBJAIxLVaHvcuW5XQbJcXdnem8NYkVGWpqVNWpS3yB5Ga0Vu9ne8l32rX FtJkwake/5P5KOeNGHZTciZQcyzKkFnbg3KqlyfIhG19nnU0Gm7f+C5lHbuz86I1R8fW OUJl5MEv4hRNEGLuly8di+Wr5jUHQUsoIn3b0DEvToT/e5ix8SK2B8XyBm4VcyzX6ISr A0NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683332188; x=1685924188; 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=S7AI48GyyCwGO0uPw6kpNL/21jqgbbM33iUu+eDBZ4Y=; b=CgjERmSz6hzMDyO3rDy6oAU/u7L7XGAe4xDi141DnTdQCt4no2Cpx3oN8kODKbakIs qxWUXJFGHEP6pgjy82xSRuK95+5ThbV/FbSqawTJnnx9yh4uLz1cwlNO+QFTm67QQh0b Yn3C9OVrq+Q+gIGexL2zfmfc59FaX2iFajc0TN8WjK4MJETn0pP/5unhVa/lLw6rrVYY rE/Il8JeJM+Wd70AAccpmv8oacRPMLHNV/wxi5izs2PbXV9dkhOWG19k5H9ixrrwWt3/ nEXc08orfVKcsi2BQ06QLN2P54BgDv9Jo6jH1sLTa4CmVv0B+hhhYFk8n45UmxLYVdYL pa0g== X-Gm-Message-State: AC+VfDyWiYG4RNXCUegx5aKrzxF5uaSv8Wx6n8xrg2s9j+HLLXxYupnU DTrsMrAUV6qzqtEmRObdCg== X-Received: by 2002:a81:4a0a:0:b0:55a:40d3:4d6f with SMTP id x10-20020a814a0a000000b0055a40d34d6fmr3640675ywa.26.1683332188225; Fri, 05 May 2023 17:16:28 -0700 (PDT) Received: from C02FL77VMD6R.attlocal.net ([2600:1700:d860:12b0:5c3e:e69d:d939:4053]) by smtp.gmail.com with ESMTPSA id n82-20020a0dcb55000000b00559be540b56sm801631ywd.134.2023.05.05.17.16.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2023 17:16:27 -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 net 6/6] net/sched: qdisc_destroy() old ingress and clsact Qdiscs before grafting Date: Fri, 5 May 2023 17:16:10 -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?1765104338233139181?= X-GMAIL-MSGID: =?utf-8?q?1765104338233139181?= 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-lockless RTM_{NEW,DEL,GET}TFILTER requests, when e.g. replacing ingress (clsact) Qdiscs, the old Qdisc could access the same miniq_{in,e}gress pointer(s) concurrently with the new Qdisc, causing race conditions [1] including a use-after-free 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 ... The new (ingress or clsact) Qdisc should only call mini_qdisc_pair_swap() after the old Qdisc's last call (in {ingress,clsact}_destroy()) has finished. To achieve this, in qdisc_graft(), return -EBUSY if the old (ingress or clsact) Qdisc has ongoing RTNL-lockless 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-lockless filter requests. Introduce a non-static version of qdisc_destroy() that does a TCQ_F_BUILTIN check, just like qdisc_put() etc. [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-lockless) __tcf_qdisc_find(A) 10 tcf_chain0_head_change(A) mini_qdisc_pair_swap(A) (1st) | | RTM_NEWQDISC (B, RTNL-locked) RCU 2 qdisc_graft(B) | 1 notify_and_destroy(A) | tcf_block_release(A) 0 RTM_NEWTFILTER (Y, RTNL-lockless) 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 just one of the possible consequences of concurrently accessing net_device::miniq_{in,e}gress pointers. The point is clear, however: B's first call to mini_qdisc_pair_swap() should take place after A's last call, in qdisc_destroy(). 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 Link: https://lore.kernel.org/netdev/0000000000006cf87705f79acf1a@google.com Cc: Hillf Danton Signed-off-by: Peilin Ye Reviewed-by: Jamal Hadi Salim Acked-by: Jamal Hadi Salim Tested-by: Pedro Tammela --- include/net/sch_generic.h | 8 ++++++++ net/sched/sch_api.c | 26 +++++++++++++++++++++----- net/sched/sch_generic.c | 14 +++++++++++--- 3 files changed, 40 insertions(+), 8 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..a2d07bc8ded6 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1080,10 +1080,20 @@ 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; } + + /* This is the counterpart of that qdisc_refcount_inc_nz() call in + * __tcf_qdisc_find() for RTNL-lockless filter requests. + */ + if (!qdisc_refcount_dec_if_one(dev_queue->qdisc_sleeping)) { + NL_SET_ERR_MSG(extack, + "Current ingress or clsact Qdisc has ongoing filter request(s)"); + return -EBUSY; + } } if (dev->flags & IFF_UP) @@ -1104,8 +1114,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 +1137,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) 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);