From patchwork Tue Apr 11 18:01:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 82124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2766378vqo; Tue, 11 Apr 2023 11:14:50 -0700 (PDT) X-Google-Smtp-Source: AKy350aOkJoK2TU0ySmx0tCRfHR9ME8A5oHrngeOvZGMQ8/iEpcgFEJc5bC2UhkWi245xeattCUr X-Received: by 2002:aa7:c043:0:b0:4fc:9a22:e0d2 with SMTP id k3-20020aa7c043000000b004fc9a22e0d2mr13826757edo.14.1681236889734; Tue, 11 Apr 2023 11:14:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681236889; cv=pass; d=google.com; s=arc-20160816; b=lO1yTgThJITxG5jmGb8Y2C6E+McHtzNmI9EomLfSIG6pgsm/Y56qsj4LSp3giHaWOF RcKvx9iZYydJrHFBQbW/+gJqe8jUmCDcTWSaxIyEG6xesmaZdXRij98cR9YT1vtF2Cl1 985KHLGxQz8JupgD7fCLXHOM1ddlTKLz+MUPy7p/8lr0OOdvb1H/IzTYO8vZiH/5znJv Wc2tog8vqBhD8YNfH8id4WKNamWwxPgZQTxXLfWPlXf88MTDSQhZL/YQk3L2eFuyJno2 B5UoNW50L2hoRI7nXtD0kf56KrKy3fQ7Wl4XpXWWCcSFUZoE5H5FrprtO0Z6dCiiybMY JUUA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020a1709060a5400b0094e45c894a1si429401ejf.963.2023.04.11.11.14.25; Tue, 11 Apr 2023 11:14:49 -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 S230030AbjDKSCi (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> 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: WjJZJB7JWDdWexrWpUFheuz51PExbtFz0Er8v1CbQ3I5sA6n2fSpyTGL9M0WIqFIkNg3hxnOU/lo+JsV58yZNkTB7mYzPsRvr+wCQUwY1tV+E39hqnrO9wQFYedorwCf5orvmdBNNMlilnNxXl2bOjnUXK6uf/Gl+kTO+In1dcwtMA4w9N6YJrUR5IaHJ1kK2QE06FKyp5BLeWGNaj8ZCCgyLXYURO7IouPntlb5F/zRR3NZbGMXCu4SVg6tXYPIoRq0JXBjP6BrSqW+vzVgGL5hW/vVKD6+JqWHsKYWKfiEl4ODvY0jtwu2KLCA53FvsflNLg6wDLGhkV5HwYmAMaOLsp2PqYxr+axunx7HdozCX/iZxZEbIDva9yhVhjJIsS8QuLqb5rkjUJghuM59B6CjFqNJE9xX3Y8I3OUyO4u1pEoeH9z0FTrgeyq1TdaI3T/ka5yVC/iR9Qqjq6H4+UO+fCvtENY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fxDZbPMebkIobVCX8CXZpX6UAUt+Wsn4+Azm+IUqeHajs14rp6eCR/TzjWg== 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762904653125794123?= X-GMAIL-MSGID: =?utf-8?q?1762904653125794123?= 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; }