Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5867517rwl; Tue, 11 Apr 2023 11:04:17 -0700 (PDT) X-Google-Smtp-Source: AKy350aiqmV1fuGrrWeFYjvsA+MO9BbIxTP4H3ARcqRhLDevOl8jZzwOJrTGP0EhBeFwUQ0PrbqT X-Received: by 2002:a17:906:3843:b0:93a:353d:e38b with SMTP id w3-20020a170906384300b0093a353de38bmr10625602ejc.37.1681236257269; Tue, 11 Apr 2023 11:04:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681236257; cv=pass; d=google.com; s=arc-20160816; b=a1k9S7qVjmuJwt3CAYf8LgE6hK72SiWK94R+pVPbo3PS9e77qSKHmu30beQUOTFN9A Kt1pNF/ISsGrjbvghmLL1bQa1hsWIx287lXWggmpA2EYqopJyVkTS6RDum73xcQ9k4ED O41MLv3L6aAbzlXQHrf3V+A+3hCoyatjm1vWl3TXuZJCWW+II4+46RZ/6jmOt7tP91ih /fB2l00fiGfwGkTXjEX3GwU9570WidTsWAT69ZtB3Scsn+IPIp14EoINr51wHRiv+1Ww TkdluUzW3A0AMF44jdAnyiNodVoZFTcoKa5IAU0CSk6ZN2NlN6tKvYkPVK4SKNFgqamV mBtA== 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=D4MfKnnorVexmxTPclAKEWkprWBM20wpATNp+uMF4dY=; b=fzF1HFiOCE/xLEVFVjbNCzTwbfEcmWGVMGT5ofiZgDqoKGHQldxWLjT/nO+z5MLCQr GPSsyJQ+HtLnt6/xShBS7OiIybVD2blSweeG8UFvvxuv2gnce4Ay0Z6PZCqD70R3zr7R Sj4R7C1RRiwe4d37GleJY41QEi2tvqLaGh1/w6/4SwVFsOGorZSt1XCl3Oq/A1ZDSzVn LEX1yMA0JHCP1SvF7PCyN3H2DcDRI7N1FHDa27rHQjcD7jrxAwzQGvlM7BMPjSDDgIYX IhmYa4JnY5Z2eWO8oTPt3fdSeGjPKyBtMv6iXIXCYb9nsPA8+pByOPGOJSpGDqwG2UNe BkYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=i3iQnLbo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy17-20020a05640231f100b00504ca1f532fsi643352edb.487.2023.04.11.11.03.50; Tue, 11 Apr 2023 11:04: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=@nxp.com header.s=selector2 header.b=i3iQnLbo; 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 S230027AbjDKSCi (ORCPT + 99 others); Tue, 11 Apr 2023 14:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbjDKSC2 (ORCPT ); Tue, 11 Apr 2023 14:02:28 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2045.outbound.protection.outlook.com [40.107.8.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A4CD5593; Tue, 11 Apr 2023 11:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+depjGJc6mUe+8SvwJMREKtkUeMQcWztMBuCHBK/OcuHPo5f3stcLS5ebwGkoUwCnZstQ9c1Q942aSpe2xCBm32dUthbd5VU3e5LD9UNjzZaoOCgDxzk6l6qDfYrec9+0xEhwtF5JQYEDXcRivpT7GW2yVC/qcdmezwilIwDSk+WANubdXKdm0fLBiLMlvniWq9CW7oYfVTuh6AyX3STu3IiNH+3cfIBMOKNIx+1ejwfYBKgl92PkTsXfJI8qpR1Z9plz9jvSdlZMJlPP91a02XHVhR6cLS52UER2i2SE9I6DuaEwPfwhGDsKkxgpSoziG4D6LMzgGkHH4s735pPg== 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=D4MfKnnorVexmxTPclAKEWkprWBM20wpATNp+uMF4dY=; b=cP0RDcLKA6gH8k12Uu0svesTgzfuUSgviHkq4EWRzhiJtja+9dvIB4FAuhZ/AF5H9ENNLHSLM9EztDxnS/H9pQrsnNwLJPjRFu5J5XSLtFA6MP2dxUgObgJz6XfPGsZafpyuDqgFzLhdifpaZj99Uwi53YDtI/0n27xWd6SBq+tsv9IaZnfKR1RdjNg1u5lrHLY8thE5MAEoXgOk1wVcxXw/YX2SZuCu9IV0HOYBXsiOOAA6wSrwODT1d1RB5uDq35M/nlp7jwV4/GpS06mcsGzTSlXXcwK/7Y50nZdoJye1rR9NBCtYtQo3/qjK510mBoWe8EB9pEUV5CtYev1EVw== 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=D4MfKnnorVexmxTPclAKEWkprWBM20wpATNp+uMF4dY=; b=i3iQnLboKSUpuaUwF9j4wwszzbPWjKESdWWO6/7jzJE8wile3TWBbggCslZYO7CWryC+MCvibfptR045sX3YHH2Z1sQTCoSnhVwxDAREddqofYWgQY+LdDglPwFCleBT1wrMGRLylEWEUZU+JqXlup10oPGWmTMc589TZkeMf84= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AS8PR04MB7829.eurprd04.prod.outlook.com (2603:10a6:20b:2a7::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 18:02:25 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::55b1:d2dd:4327:912b]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::55b1:d2dd:4327:912b%5]) with mapi id 15.20.6298.028; Tue, 11 Apr 2023 18:02:25 +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 , Ferenc Fejes , Xiaoliang Yang , Roger Quadros , Pranavi Somisetty , Harini Katakam , Giuseppe Cavallaro , Alexandre Torgue , Michael Sit Wei Hong , Mohammad Athari Bin Ismail , Oleksij Rempel , Jacob Keller , linux-kernel@vger.kernel.org, Ferenc Fejes , Simon Horman Subject: [PATCH v5 net-next 3/9] net/sched: mqprio: add extack to mqprio_parse_nlattr() Date: Tue, 11 Apr 2023 21:01:51 +0300 Message-Id: <20230411180157.1850527-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411180157.1850527-1-vladimir.oltean@nxp.com> References: <20230411180157.1850527-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR2P281CA0186.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9f::20) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AS8PR04MB7829:EE_ X-MS-Office365-Filtering-Correlation-Id: c660420b-c188-4b89-a524-08db3ab6e7ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x0H/Ebw0OSvuNjvgLY3wdgmL1Z61KmCskJSKNq6GsDm8ZH27GkiFhwy1ML7acw10TsMAo1xrC1OSk2bfaEt0XWfGEraqyyfJfk83Dj1bF3flbxKnM6vb7yAhIFHBUDHxoTCd1wVARvE0uKTulxNHMYeOyZqwKSo3MaHGo+am+JwoyP1CcRnifjbVGKKMKywQFFECPfCj0lKiji4OaG6Y8xJRf2SWQcO508rjj4YOptALv1h7LHejKnkJb1q8/4dGamgZ5qMr/gCvN3gWIN236FyvGU1B/thdSrmYHrvfg5/mhxXS6HugmSC92f7nAoIfg+M0K1ltaXnLTgYxUD4g4N3E0O+d9RmTSQN9leYGtPetFzzgReMvWMUGwhqC2uKsFuS+/0BkdVrdTpiWngopKataJStt2C70FVdCfn8I5n3DpO0DifpGCvQ+IF+JT2olOtZ20bm43OggKnxfVaMZRIbjlb44e2HSeS3TN04MEg1rBCDyQD1I7cmsatI+1i8cEtq3S+a32/NmzLvzXvFVwXbRlOAY4gGqtg8GrQFagj8hMVI0aMqzn6KPf33ZnLSgfsVXVtDY2T1+1mSSXE9MNyjcUAcqmGePYo8IiZkFTkTgxbSTAauvgXxnS1wnIEDI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(136003)(346002)(39860400002)(376002)(451199021)(41300700001)(478600001)(86362001)(316002)(54906003)(8676002)(52116002)(6916009)(66946007)(66556008)(4326008)(66476007)(8936002)(6486002)(5660300002)(7416002)(44832011)(2616005)(186003)(36756003)(38100700002)(38350700002)(26005)(6506007)(6512007)(1076003)(83380400001)(2906002)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WjJZJB7JWDdWexrWpUFheuz51PExbtFz0Er8v1CbQ3I5sA6n2fSpyTGL9M0W?= =?us-ascii?Q?IqFIkNg3hxnOU/lo+JsV58yZNkTB7mYzPsRvr+wCQUwY1tV+E39hqnrO9wQF?= =?us-ascii?Q?YedorwCf5orvmdBNNMlilnNxXl2bOjnUXK6uf/Gl+kTO+In1dcwtMA4w9N6Y?= =?us-ascii?Q?JrUR5IaHJ1kK2QE06FKyp5BLeWGNaj8ZCCgyLXYURO7IouPntlb5F/zRR3NZ?= =?us-ascii?Q?bGMXCu4SVg6tXYPIoRq0JXBjP6BrSqW+vzVgGL5hW/vVKD6+JqWHsKYWKfiE?= =?us-ascii?Q?l4ODvY0jtwu2KLCA53FvsflNLg6wDLGhkV5HwYmAMaOLsp2PqYxr+axunx7H?= =?us-ascii?Q?dozCX/iZxZEbIDva9yhVhjJIsS8QuLqb5rkjUJghuM59B6CjFqNJE9xX3Y8I?= =?us-ascii?Q?3OUyO4u1pEoeH9z0FTrgeyq1TdaI3T/ka5yVC/iR9Qqjq6H4+UO+fCvtENYS?= =?us-ascii?Q?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+op/en?= =?us-ascii?Q?UFx+U6+tGPoXsCJH1/6RQ3UPO7PtoGc8qyQJlbht3Lf5cwDfcly67T5Yk9KV?= =?us-ascii?Q?zUfcnOnyYdDG3YSClZ3ed8UKb2H4bOK4l0CcaEbj0jOKIeUCo9bEgPSMF6MR?= =?us-ascii?Q?2xht6FKC14P+arXRPr6fwSnnN8X+VjVezFq1TU3aJbdIEeSwpC3+Q4Sagmmt?= =?us-ascii?Q?1fAfxDZbPMebkIobVCX8CXZpX6UAUt+Wsn4+Azm+IUqeHajs14rp6eCR/Tzj?= =?us-ascii?Q?Wg=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c660420b-c188-4b89-a524-08db3ab6e7ec X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 18:02:25.4624 (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: BvTuKR794MPQBJBBLqxLt/JCep2u1UP8dy4mO6e8yRSMmx06ziFWekS3U62EB7E5ky8YlFc4PNvLbFGQT7szZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7829 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 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 Reviewed-by: Simon Horman Acked-by: Jamal Hadi Salim --- v1->v5: 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 89e5dfb22db6..8e8151ca8307 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] = nla_get_u64(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] = nla_get_u64(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