From patchwork Mon Feb 20 12:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 59412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1276892wrn; Mon, 20 Feb 2023 04:25:40 -0800 (PST) X-Google-Smtp-Source: AK7set8CR5+sE2AMweY50o8kN8qfXuNKbo0hU1ahwBxbsE1gDFW/ejQ4991fjHmUT6AOK8muRWBd X-Received: by 2002:a05:6a20:7291:b0:be:b137:9d1c with SMTP id o17-20020a056a20729100b000beb1379d1cmr12155086pzk.37.1676895939859; Mon, 20 Feb 2023 04:25:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1676895939; cv=pass; d=google.com; s=arc-20160816; b=ILX/3RGH2DUMxbYua5CSktgmU/i/lAeTkvCSZKHSWMLKvNabiKuBe6r2Wd7Sh37E60 GFYcaZZod9sj8QLUfTL1MYUXJry1ExMfkin8ky7ZcEuJQHyKqK0PWuuwHs9JCoOMjtxC qnERSxvThi5wdfcXVFHlMw8rJuspE2tWJwFqiICCLc6/LVVZN5PjrZNcCeOHnHjgZVuK PpoHx3U6dnA4OFGD4cD6ZCIGkpiGdJcMWQhrsnj+fXgt/yonpWqR37q1tps1eXa4W9r+ aVskv1wuchpFwb5qUFV7tX00iys68P2QdCOTI6Lxo/V9o7TxkIE4/RTxbqYZ1Er5/E5n ELlA== 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=QyyofujqUIRJiXljGPJ3G/lvIRLm5Yx2jXCQIilfv9A=; b=XyldiG5Vx7qIQI3mQQVOSD+cIQqyvDwgJNnSegj9Do8X0TQcU1fGt/R1Ce48J/UH0f x0BxviklV4i8zYqtNHueC80cfCgsIt3WjWgkmv3qVLqqF3PURCS5MY7svejMIx0BCt5P 6hF+WplztVvclIsUdZ5YiF2PzuqG/S7iF3M0juXuikZ6XlwBNc84zxEGPktrr7zwp8xx 9BXdor97wX5ud2HaD3SxhIuaA1GlvfW1zqgQh0xIe+CjjORm47SRQh7R95DSxFUQWi5A FdWrXpb8haAaooquSrhZW8R6eXQ5+5caTUsjeERONNSUrEC+HpWkOIRvj1/ptcBfQEgL wGhw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=hNDGAX7k; 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 s73-20020a63774c000000b004d2621d6a70si15118299pgc.163.2023.02.20.04.25.27; Mon, 20 Feb 2023 04:25:39 -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=hNDGAX7k; 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 S232056AbjBTMYY (ORCPT + 99 others); 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> 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-0: 0fQQ69r3esQq3Pc1YJx0wLKgsByhSxuajWBe4yLerOoxkf7DGrIKgCv2TunWTv5z06QDQ8D6j+9L/MCH780grMMhUMcycEHN34JMAE1MSiDSje29wCM3GPrbhypXW6G8B44WrIiO0b+ri9aD6PvIWDTMEkTI/DXBQZDcwfUgOFQVJt5Ptjo6qJ8t70TBrLzOpFJUPH5+3CAyFJUAJTA6Z6P9GhTFdAQsCRAkBj/EWkkxptfG4w+BjGAINMLQjju6UECbMcCKbu0Q+um0fY5n09QGKnnDRzvka5fYkQL87iIcqaX1j1ZBcd2xQ91UN7zcJB5LdpSKtv1DCkML7kp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W9gCZdYi4r6w/msk25WM43yEw3oqPHqTVU68lAZ7aEmMIdTkfq1T6YfIpwVmmkisgAwXqsVl5fpb34+yamiqr7BPFeQ50HHBJRMdaVakOxyzUSVZugRSIGg/YH1lDJBLjsVZo9lTJKF5N17h/vZeX3Ml28qQU1yhBo1y5dCOAY5N3LAiP+ngdngfkd7HOfrQfA== 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 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_PASS,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?1758352837130035403?= X-GMAIL-MSGID: =?utf-8?q?1758352837130035403?= 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; }