From patchwork Thu Feb 16 23:21:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 58277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp583005wrn; Thu, 16 Feb 2023 15:23:15 -0800 (PST) X-Google-Smtp-Source: AK7set+phbVWL0LzMeNA1Elx5Y549fQkhu81f8y3SSG6TVkflqnEnr0C/7kkEGdzgxVa/8+jNQoO X-Received: by 2002:a05:6a20:734c:b0:bf:4903:22fa with SMTP id v12-20020a056a20734c00b000bf490322famr7764757pzc.11.1676589795337; Thu, 16 Feb 2023 15:23:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1676589795; cv=pass; d=google.com; s=arc-20160816; b=1H4RwapS4GBh+rCsNxHjGNGYJejMNlQzFE5IbOEluhZzfeRBiGc2IbOr2s1eyIuppo CHdO65XHmgpt8b9N+he4fNk5xbW7Sgv1T8zta4UwGGTvKzDF2uQGv+m/7pX/6/k5yTKK TINtRk3JmtWy+cXxqBkDPhyWhEPMQGO3SdLmYVvdTQbK3eAcyFcrfjpK2+B/AJd8AVNH OW3LQC3YGgoOfWhQkwBhOHB8wwJvD+YmJy7VKrFjWcJ19r+PlKKusTJYiRjxtuk6ySBA iIv43gX8YhyFc8d9URotcDJyYqG9RSY9eJERlbdpcMOVDhNx/V+vfw9YQKXFA2yOqnkC /auw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hN68A9dOgisiMZbohGpFUD572fa+AlUlqQ84jTWoNKo=; b=yGiG7/pzGkiFVNXidLvcScCVjJw0NlsFO7Q8+SWSYSabpb7C2AjiXoVCEfABY1hMxH lPasKZmKo8wU23K54Oecp1lD7I7/xTrQ4Ua6zxx8GQdEdLRkLyH+K240l6Ze0Zrjdi1F weuuyJ4sVKn9zj6s6PW0D+KpQ5IMymwfjFLXoI2o7NyEFzE1JrafNx7diUAxMJzjIUNm yz28zH+qFOKg0/IPREthfNU05JcD8icxO4Ke7iaa871bprlG0D3boFYtMvU+UXmueRjh vW3VJDtT6GdF/SO8q5uI4Rc5mzZVEUiBJnBqcKkpZQmVrhWr8CWQ+/ASCu0Utfdlrhhx DliA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=CTbA0viF; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a655787000000b004fb8f5e1a8dsi3068624pgr.111.2023.02.16.15.23.02; Thu, 16 Feb 2023 15:23:15 -0800 (PST) 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=@nxp.com header.s=selector2 header.b=CTbA0viF; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjBPXW3 (ORCPT + 99 others); Thu, 16 Feb 2023 18:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbjBPXWI (ORCPT ); Thu, 16 Feb 2023 18:22:08 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2089.outbound.protection.outlook.com [40.107.104.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F87154D17; Thu, 16 Feb 2023 15:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bHcvMViSQKx2hO4BfZScwZoycBSiMxKsiKc+ItqU/QKLnCbvo1ouroISzkXD11noDXZn0OaVGN5nKOq6z7q0QKwgejq0bbN6V1MJYAX6ok509FGnRahEYSw4au0szMcrd/WHmgv7acwATXhsSVtTsplStIDcFaRvLRPNNrkBbL+m7m2fObEFQkUNVFXG+lcfcU2tfVy4+6r1Qpl4JkIa6nBaGeSLIyBOn5uilBO6B62BPEpvdh1N+JU/w/taKlWLHhMKAmhtlhKrjVmzQp4M2CqBa+A23CXd6qUP0L+nF5MexM11NLAP7pEfL9vCQwlpRQt5HzeFUj4HekAbxFxTYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hN68A9dOgisiMZbohGpFUD572fa+AlUlqQ84jTWoNKo=; b=H2cNoSmCN78OCfMdy3VrxdTpo0pCpY4QFKh47dN9YhNkDLVQ+sB6RnWIps4SeWqFWd9or3aSLdR50KfCL+lnWEoqHsDi4lifvMptkrxTM94N7rumzK49zkkl37KdjUD7PtBH6v8O+iLHq04jibJSl8mY7Xy/1p4zEIyDi6AKM/RDAf4n+g+EsMGUrC22uGJksltpV4ddKGOQ6VA0cfXp9KacXHKEprdvVewpibOCkc5zHW4E6gxuSKkb65OcwlMe8cCCPAr6jxGMxrl0085Xu73AY6wQLBhswi6Re1D8TkZuqkX8POQwmAY2lzZmuz7DP/hU/lIyyfXgaxSHlhjFvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hN68A9dOgisiMZbohGpFUD572fa+AlUlqQ84jTWoNKo=; b=CTbA0viFznR9DmedONb28l0YO58iYmOSLQ21ivxX+gZRZOTjvFYrALY2Nf3hDrBdivAfy3IsHBl3dPwpIG8pXePWKZIKgwrDIXnpIdggMQXgudhHrGv1U6N2hCnEC904mN4YDG9MRU21gBUCzC5B7umAsGmgG+GXzx2x5rO9d/M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by PR3PR04MB7436.eurprd04.prod.outlook.com (2603:10a6:102:87::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.26; Thu, 16 Feb 2023 23:21:48 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%4]) with mapi id 15.20.6086.026; Thu, 16 Feb 2023 23:21:48 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , Kurt Kanzenbach , Gerhard Engleder , Amritha Nambiar , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Ferenc Fejes , Xiaoliang Yang , linux-kernel@vger.kernel.org Subject: [PATCH net-next 07/12] net/sched: mqprio: add extack to mqprio_parse_nlattr() Date: Fri, 17 Feb 2023 01:21:21 +0200 Message-Id: <20230216232126.3402975-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216232126.3402975-1-vladimir.oltean@nxp.com> References: <20230216232126.3402975-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR0501CA0018.eurprd05.prod.outlook.com (2603:10a6:800:92::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PR3PR04MB7436:EE_ X-MS-Office365-Filtering-Correlation-Id: 5703ae59-58dd-4f8f-cdac-08db107493b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 072dGNqbiZr6R6IlDXR/X3MzNUBux8NR5Xy01VImTXTE5XxrUX6qpd5M7aulXCr0MuDznIgOi1TYkgiJ5VaLAvdu9mFny0QbTzYxd1MXBOxQx/RpywJIy2B3NGdPdk9v4xn0ro3c/iLaQxNPOoH9E1IR02UIoDXmWklsY3CZag9hgO1MU2GZH7MfTmy0gC1Huj3Io9ym/CbV+2YpDE/Bm1g3UhtAMwgk1U6VYY1EE2FsGvwNUMVeYWSObDLlJG/9yUonqif89KyTpkerRS9P6LN5Qm3hTGPCp6kaMGYFRYteQO38B5WpZ2I2jasvmEn5Vb301WD/b+6jVhsElTNq1pxLyK7wKxJJ99j8akDwCCsB2A2IuXYj0/H3kP7ZQusp6hg3M+XWWCSns9qoHCKhIDb434lCsUum8UD5UoPQ2ip3i/vn/Oqjt1P/pWjM8UNvO7v84mIpOlGzizscpEadtShm0awT3QWUoGpaGFqM4VIlDEWiy5Bt+G6JL/6kOmC+DP6eEQ8tb/v6lh7pRoNRIHiD0v4RphwqCgccAC9f0psfdf1sqLM358zNqB4zY1nSRKJMwbeQD7acDWo8ZtG2mhBUzcg0Ks63OKuRh0ajvFKMCeSAtU2fbeb8OPmt5KX8AKqglJcHLlcH0pouqr4gHFUd3+aA61V2FDgzsRzA9YL3sudZyeuPy2FeegMwmjurAScBJamKep7vgyXKl+1Rog== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(366004)(396003)(136003)(39860400002)(346002)(451199018)(38100700002)(2906002)(38350700002)(44832011)(7416002)(83380400001)(66476007)(2616005)(86362001)(478600001)(6916009)(66556008)(36756003)(5660300002)(41300700001)(6506007)(52116002)(6666004)(4326008)(66946007)(6486002)(54906003)(186003)(316002)(8936002)(26005)(6512007)(1076003)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9GYEZMd87KllhVSUJxRrSAc12tnnS50iD+YEvzDYw93mxdW5LsCCA4FpNKdV+BGPCA7e6rTv0fIA3bH40wOFk2nRR8IRxSIeMjxQpqsDN75kp8D0vuQadYWCqu78XzOt7Q/8sXFvdv6jnHqKUkHt0pvVv/m4Y8xJFl8Kl+7TqfGIR0kLZ4V4euGAG9s/3Yb1O5JSme6Ku2jNvw1wsMW9AfZxgeyRjqqozHiCRbqLlLAhAygsSMuaMN5Yk5majAyOGdEttMBMbi2lxE+qLBdyzThhMGNUXjyUlmwE2q6jgDb08BN52m5p1AB6LDpkb0PrZM/eFTeUq/uAdXzXFSJBZB5bBn8hkG4NraIlWxk/ujOxmOPQVsa3S8SdK9rEgQBgjt6AnQNdkViLko4E7m3FwcYukOKRAKXEUjKgaUPaxokGPWCL0DygdsiNVnyR1EmvfgmyJjm7edqCSxzQ1zhFs9/hPIxME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fimXe0H1gVaN9XFrvkF0wCGzcec30kUE30XRwbuUzXSYR9nYsMWjpMpug== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5703ae59-58dd-4f8f-cdac-08db107493b1 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2023 23:21:48.5086 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P0FxYVhcn1/1kVkFUW7uK/MxvBQtfdBvmo6jQPcGXglJ7JDGo/Sc/z9q8E+GZFV9zQki9lZfz7rQPrJf+O0hDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7436 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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?1758031820943846695?= X-GMAIL-MSGID: =?utf-8?q?1758031820943846695?= Netlink attribute parsing in mqprio is a minesweeper game, with many options having the possibility of being passed incorrectly and the user being none the wiser. Try to make errors less sour by giving user space some information regarding what went wrong. Signed-off-by: Vladimir Oltean --- net/sched/sch_mqprio.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c index cbb9cd2c3eff..18eda5fade81 100644 --- a/net/sched/sch_mqprio.c +++ b/net/sched/sch_mqprio.c @@ -151,7 +151,8 @@ static const struct nla_policy mqprio_policy[TCA_MQPRIO_MAX + 1] = { * TCA_OPTIONS, which are appended right after struct tc_mqprio_qopt. */ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, - struct nlattr *opt) + struct nlattr *opt, + struct netlink_ext_ack *extack) { struct nlattr *nlattr_opt = nla_data(opt) + NLA_ALIGN(sizeof(*qopt)); int nlattr_opt_len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); @@ -168,8 +169,11 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, return err; } - if (!qopt->hw) + if (!qopt->hw) { + NL_SET_ERR_MSG(extack, + "mqprio TCA_OPTIONS can only contain netlink attributes in hardware mode"); return -EINVAL; + } if (tb[TCA_MQPRIO_MODE]) { priv->flags |= TC_MQPRIO_F_MODE; @@ -182,13 +186,19 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, } if (tb[TCA_MQPRIO_MIN_RATE64]) { - if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE) + if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE) { + NL_SET_ERR_MSG_ATTR(extack, tb[TCA_MQPRIO_MIN_RATE64], + "min_rate accepted only when shaper is in bw_rlimit mode"); return -EINVAL; + } i = 0; nla_for_each_nested(attr, tb[TCA_MQPRIO_MIN_RATE64], rem) { - if (nla_type(attr) != TCA_MQPRIO_MIN_RATE64) + if (nla_type(attr) != TCA_MQPRIO_MIN_RATE64) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "Attribute type expected to be TCA_MQPRIO_MIN_RATE64"); return -EINVAL; + } if (i >= qopt->num_tc) break; priv->min_rate[i] = *(u64 *)nla_data(attr); @@ -198,13 +208,19 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, } if (tb[TCA_MQPRIO_MAX_RATE64]) { - if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE) + if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE) { + NL_SET_ERR_MSG_ATTR(extack, tb[TCA_MQPRIO_MAX_RATE64], + "max_rate accepted only when shaper is in bw_rlimit mode"); return -EINVAL; + } i = 0; nla_for_each_nested(attr, tb[TCA_MQPRIO_MAX_RATE64], rem) { - if (nla_type(attr) != TCA_MQPRIO_MAX_RATE64) + if (nla_type(attr) != TCA_MQPRIO_MAX_RATE64) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "Attribute type expected to be TCA_MQPRIO_MAX_RATE64"); return -EINVAL; + } if (i >= qopt->num_tc) break; priv->max_rate[i] = *(u64 *)nla_data(attr); @@ -253,7 +269,7 @@ static int mqprio_init(struct Qdisc *sch, struct nlattr *opt, len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); if (len > 0) { - err = mqprio_parse_nlattr(sch, qopt, opt); + err = mqprio_parse_nlattr(sch, qopt, opt, extack); if (err) return err; }