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: 13144129 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0C31C636CC for ; Thu, 16 Feb 2023 23:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbjBPXW3 (ORCPT ); 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+YEv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y2V3Qu6+7hwhZz7+qnCrSiKEhpnIz6AVtE2MjmIdu9fsup9O7P2oP0XqCXBefyxSSJR/EhdLerOgwd4+8mk5O9nSZ7TMfhyPrM1qeapv+UFappaqKnBdfCaGe0iVKHlRBulVvV6nS6au8x/DPtaTT58BieZZnelSrnoGs2jLtADL3ia3rP1uxazt4OEnvJ6XnW0qrZZxttEfQEFhdQootE9A+tAk89pcruj9mvRRcbwRHk1yaaDHLzPxLto60fjImma672CObs3ANbtdpYFZVOkZHAvs9p1jnJsEGsB0S5vjD53JkG5rKI4kYbdP715G35RWYjQ368phL9ca3mH58MEKzgSa3hCXUCLEJq3jOjK4q1n0OJtjvhWOIz7M1tOz9w71U7mXCPwQjsdjptPA2naCM9BYzBI4So/SELuus0KMwdy9O6Rx0wxahRVpa3gswEfIIxs42ixw20RfimXe0H1gVaN9XFrvkF0wCGzcec30kUE30XRwbuUzXSYR9nYsMWjpMpug== 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 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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; }