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 EDFAFC64EC4 for ; Mon, 20 Feb 2023 12:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbjBTMYY (ORCPT ); Mon, 20 Feb 2023 07:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbjBTMYR (ORCPT ); Mon, 20 Feb 2023 07:24:17 -0500 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2079.outbound.protection.outlook.com [40.107.15.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6DA1C322; Mon, 20 Feb 2023 04:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D6+0aNYciQQQIhCokmgPM7WapN6OkqmlPhUh34d1NtsH3tyjDZrD5NFx4zL0Bo2I1xgWVLi4CDp7EFxETk4qdm9IVr9rD9hpOqr13BFNdOTn9rRXn5U1srJyLcX84qibj09MLTlazsl0K3aQGGjLFIePRyP6hXwBbVr6lQoneV4YjvU7C0Kw6FnSs//7kAatv48KTd3zJ6Icq8Z+ikRHTfBpm46WfL9ej1KIFIQLx1DiOHJpZ7ckj0atMfE/6s8Dmhc3SE/PzG8ufrIQU3dqvqv45sGKKf7dNONXWuWYzdn5XWGC+cr7Bq5e3uSsSALlSkW/9udvgDDYnJkeb61BnA== 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=QyyofujqUIRJiXljGPJ3G/lvIRLm5Yx2jXCQIilfv9A=; b=A84WNTwAMiLu6DkrU3/DB7arxqdO2NMw/G/ipTsmzSldQtmNCfMWSSdBOtxJ1a1C5wlCj42FCZ8flWEGISi5xZ6vd/4kzC/gTio/gRHgrqnduKQMLZ3WTSjHJqoD23wdMR6rjW0FnIasTfJ/8MQxsfledQqeUexfgeiKBj+kiK6oFiOYeocMsq9R2CYUHcEw2qg1yL1TTkOjlTiOPuQLt3Ffys83C14dZYJ8AVQm4dCNBzvaMh88GVIrsiVgJGna3h2WNiIBb2qnFHNK+T15JxM2y99zQ+6xX4UeijkcmuA8JYCvsE08EC99MDIe/BzEYZiBGd9KNMFqXwnB74+QnA== 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=QyyofujqUIRJiXljGPJ3G/lvIRLm5Yx2jXCQIilfv9A=; b=hNDGAX7k1UbntYhSIsOUiLpShLxDxvMg4Db3d20kOADLbWtf+2UsaK6XaWc/ICku9mhhBSIEjLH1VfmKzWc2Sa7r3ys3fTaXepg4ptYJlH+5Rsrth2ULRrz6xRKJFBQx7TzkBkXOQyF621nHI63K0z90b+KLWJ7PQrTYYKfny0E= 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 PA4PR04MB7725.eurprd04.prod.outlook.com (2603:10a6:102:f1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.19; Mon, 20 Feb 2023 12:24:05 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%7]) with mapi id 15.20.6111.019; Mon, 20 Feb 2023 12:24:05 +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 , Roger Quadros , Pranavi Somisetty , Harini Katakam , Giuseppe Cavallaro , Alexandre Torgue , Michael Sit Wei Hong , Mohammad Athari Bin Ismail , Jacob Keller , linux-kernel@vger.kernel.org, Ferenc Fejes Subject: [PATCH v3 net-next 04/13] net/sched: mqprio: add extack to mqprio_parse_nlattr() Date: Mon, 20 Feb 2023 14:23:34 +0200 Message-Id: <20230220122343.1156614-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220122343.1156614-1-vladimir.oltean@nxp.com> References: <20230220122343.1156614-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BE1P281CA0183.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:8d::17) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PA4PR04MB7725:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f4ecc86-8459-4f46-eb45-08db133d5b9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JRuw5s5zJEFg7hAJxfw9Geh8iHGKfMI/9DU4YLehuZo/G8EjJW+JAbNu++hcDYYE2HSyftwAhRrs3w1Bi8qEQatj7DwbAL0gZks3ZV3AiQzJeK/9Nm8l2ddWaeyP1PINzkiEEPVTRADEq3LFwKyF55uxKLcgzYdkv819JuX7EHEsyvFuNsfnVxA1Yt5FtvXLk0i67TfnGFYDbUf/72EOeczxyfvP2sBAKCuklX75uxU6ek7I6vVdkS7YZFsQyg0U/0zxJiV9odgbILVhSJmykstg3oxRYBPRCtMdSszSp6ULvYbO1wa0pOtBqt4ycuXNaD5hpeeUNH4PbOlPAN3A65SEjWMnJ9ksDLihUauOr/bEUOXz4umr3L5MTbjVlgX5TPMfAE4Mm0lqR4QU4ZD4AxiWjYRjl418+GTbw+0YHO2sGdNfmee3jqfiAhr9S5WA/7vJVt6tX98llrPTInOKfaoOOi+j/1UGtcgW3hqiIO8jQtmZ2jwrXyQgeDLQ9nosNgQG9iVgH7mBF3plL32FclRYncbj++BF6cjFCBs1dVSRWobHFRakWd8eTL7wR32JUKu2yXEiGQ/tnBzTbq999EC9DLSINgSwn5PHbUMjCg1maCbd3T7Y0c5/jZO0smjNRQ0p/6/IvMoiICjFbRIFJP6cZ7Bjp4egi7JaW75pDxvW/ikG17QAYMNxGwYQ6UHIBYUk5Xw2x5uOE2Rc5lx3IA== 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)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8676002)(6916009)(4326008)(66556008)(316002)(6486002)(66476007)(54906003)(66946007)(7416002)(52116002)(8936002)(5660300002)(41300700001)(86362001)(36756003)(478600001)(38100700002)(1076003)(38350700002)(6506007)(26005)(186003)(6512007)(6666004)(2616005)(2906002)(44832011)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData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fGfJdqOVj2Npe8ZLcFgOWmJ?= =?us-ascii?Q?KlPCzM3o+iPNSuuUcFJ98I6EU0C6ULPDkBHRpadKDwzsFm6fF5hULLe018RS?= =?us-ascii?Q?caHco2gXR5tvS0vknjzA07Z4nfmFOqV7HSu678/90HqVkR25OrUOHdHEg2zW?= =?us-ascii?Q?OxfRUT8YTnmn8Zct2bqh8C8/FYPb0r2JLlO/KQWSbfvRkYJoxKxe1WM0VAfB?= =?us-ascii?Q?hE5ekcTqhnraKGlMbtjua+/4jwZpyMyGhWwwopwu5gMWmMUgp7N6/1bcoPDL?= =?us-ascii?Q?TVyTI02e1zRWa+NuS2cJZCLa1bTWkjjCFn0CrmGulMawleF3og+n3DYTa7ws?= =?us-ascii?Q?dQqfk+34W3LaKH5NDuKh5bQNNqOd2rOrHB2PO8QETpJFGAuQCGM0EXSkrrun?= =?us-ascii?Q?EJH/9KjvRdyiAzHPOVusN8MjpD/+NMYcJZDLCUR1jcl30iPyTMopP6kodB3p?= =?us-ascii?Q?nb4WJMumpARBPrUB6JE1rqOdbJPnUf37GEErDzs4eLZYaHYuWigrA/IDsmqT?= =?us-ascii?Q?MNCby9NwKkkOeK66HyLOjJjE4UdgfaEomUWhaIRI4Z8JjyftW9gCZdYi4r6w?= =?us-ascii?Q?/msk25WM43yEw3oqPHqTVU68lAZ7aEmMIdTkfq1T6YfIpwVmmkisgAwXqsVl?= =?us-ascii?Q?5fpb34+yamiqr7BPFeQ50HHBJRMdaVakOxyzUSVZugRSIGg/YH1lDJBLjsVZ?= =?us-ascii?Q?o9lTJKF5N17h/vZeX3Ml28qQU1yhBo1y5dCOAY5N3LAiP+ngdngfkd7HOfrQ?= =?us-ascii?Q?fA=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f4ecc86-8459-4f46-eb45-08db133d5b9c X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2023 12:24:05.6187 (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: u715lqPIu3IVgnS4Fh6Auwc/2n3naKSIui8e4IouWdzCSwd8x0kA6JpQAQ8SxExbTYmdvAgZ15hgTLM0eu5yiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7725 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 Reviewed-by: Ferenc Fejes --- v1->v3: none 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 94093971da5e..5a9261c38b95 100644 --- a/net/sched/sch_mqprio.c +++ b/net/sched/sch_mqprio.c @@ -150,7 +150,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)); @@ -167,8 +168,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; @@ -181,13 +185,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); @@ -197,13 +207,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); @@ -252,7 +268,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; } -- 2.34.1