From patchwork Sun Feb 19 13:53:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 59152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp856765wrn; Sun, 19 Feb 2023 05:56:26 -0800 (PST) X-Google-Smtp-Source: AK7set9nuYVNk8m6gMwU5myWp0LOzZSozmN9uBTos+bM+CCk8momN3oGEpR8egO+OiG749fIOZDE X-Received: by 2002:a17:906:35cc:b0:8af:2d2e:5d31 with SMTP id p12-20020a17090635cc00b008af2d2e5d31mr4512580ejb.31.1676814986190; Sun, 19 Feb 2023 05:56:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1676814986; cv=pass; d=google.com; s=arc-20160816; b=RTuLz4TwN5/TYdknMhumEWWIYJPD/j0GPdIn1cBusZEavqap1euocYtQAv9PZfwKTn /CVPl85VI72oroZIFVIMf75ihuXFbPF4hNwAv+6JjJnVIo8+CwE3bgbGTCKCx4CyG0fG cbg2dq+AqOHvrlcdu6JAS2oySzmOpzdYNC5ciNgiDG9rQVb05djap8lMMcjPbDqL4bZY EfE4L4XzjrjD7YLpZ41V/2cWW3997MSAwn9wB28Y3gu+XjW9YTd6J+VKZ7+hPcM8z8X6 WU1KR+Ukl84QY+Tk3FFFQZOR9YCoV5griArNWPtL+s+PyrDhmcGYQ2sWUqIHoCMbz1TZ s1Mg== 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=9xv3OHoj9xpm2LZXRJ8CcH0mgiYcoB0G7lZO1InBYok=; b=vt9tMDT9SoeJcN0cGoQwfHYyTp1tesFCeB9pih6rwfmrpFX9yPVpmv1bcbDsH7nfMy Kq2SUijZ2yxZ+vOxqZ8nLQApZ4KeraC2af3RH1frEdm/ODCj1mp1D01YENvz2z4LyRl1 4EhywoZz3+Iqf3y/sSm/2yTyswpufYYiy0G4n2ouG0lp40mNtBhi70qrY4cD8O6AUQFV H5Eq+fS2annfiQlIj39tNTwBUzgXC9chOi8KliwB+1pasCsOMqJ4+UbzZ/OfIPlhAfIX 0Q81ND14Wkohi7uFGmu0tfuNk+W6ks6yGS10HWVK/t3ZAJH0LffEDfRzqhIPFavkpImt etzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=rpNEmRFr; 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 p11-20020a170907910b00b008b71bc0308fsi6145419ejq.357.2023.02.19.05.56.03; Sun, 19 Feb 2023 05:56:26 -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=rpNEmRFr; 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 S229780AbjBSNyp (ORCPT + 99 others); Sun, 19 Feb 2023 08:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbjBSNyF (ORCPT ); Sun, 19 Feb 2023 08:54:05 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2084.outbound.protection.outlook.com [40.107.14.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10BB2113E7; Sun, 19 Feb 2023 05:53:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNKBDzUrBKXU2k27OORYefdykPbNRtwkgLVPJ84vKxGfqepVjAaGRzt2bJUOw1ZqX8ZZB7Eh8RLoJIaXQ29PaaBtpsq80QWXP/7A3RF4/aLWvk73CEtLcJFkaPlm0HLCrp3JDCTXsMByMkU0lqKUDMiAdW9avFSiE04kXI78cFEjkqFYFIfi2gyGyJ4+b14/N73pitmegomNKJuupa9hjpWmRsQ0mK0LPo2eESHVq8HOah6jj+yL9Hs2RHVNtrmjc5p+2p5YIIqdArh24sOTMmB+iFKi+er1G5BzswWEYfVHCb0n8/CS+rP16AkJvjhIn1lQ54Qo8ca7tUAeZEiEaw== 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=9xv3OHoj9xpm2LZXRJ8CcH0mgiYcoB0G7lZO1InBYok=; b=bgEgvKUeLrmb4kBH4vQAlMk1wkmNvHwAxp0rT149gtWO0U5yVXQo/4Icd6hrofdCVaZuFb951FZ1Qqm7OSBkCF4L2XrJBBMLZn1fCfQF11nH+m5K+j2eaPlhlKVIhRlIytMWJyFZRo+u81GkHnJyI70P8DS0Fr3EWsBY5kLg7xDqWRcKPjN7cRomILYdvQMPh8qGCwTDqrM/vA5e6RTgrLM9kHYjiJoxCwXv486wHcOQ1MJGUIGdNtz6gpvjBgaYIunaQkMmku/RAKTD9MaYwPR5ZaDU3AJNwx5Dm6izg6uhv8ElzKzK6ZKS8o8MUK4P2PHRg5d7VkpRb+6u1crLpQ== 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=9xv3OHoj9xpm2LZXRJ8CcH0mgiYcoB0G7lZO1InBYok=; b=rpNEmRFrwPxiMxIQlgO0UTA1kk1+3m+GUrloHxj+RFNxRB2YSrxYzqndVKOkGsyGk1UwrK6nD9qoN6GgeCmLeBlgCZrPF8M2j05l5cTvvRWQz1oDA4eFZntH2eMLtubV6j4WruqwkwtV1PoXKXjMRtovexu0JjamAg5g5/i0iJw= 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 PAXPR04MB8238.eurprd04.prod.outlook.com (2603:10a6:102:1bc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.17; Sun, 19 Feb 2023 13:53:51 +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.018; Sun, 19 Feb 2023 13:53:51 +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 , linux-kernel@vger.kernel.org, Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Wong Vee Khee , Michael Sit Wei Hong , Jacob Keller Subject: [PATCH v2 net-next 07/12] net/sched: mqprio: add extack to mqprio_parse_nlattr() Date: Sun, 19 Feb 2023 15:53:03 +0200 Message-Id: <20230219135309.594188-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230219135309.594188-1-vladimir.oltean@nxp.com> References: <20230219135309.594188-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE1P281CA0136.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:7c::6) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PAXPR04MB8238:EE_ X-MS-Office365-Filtering-Correlation-Id: a9926974-8e8c-47e0-6bbe-08db1280bb39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d0N8RBZTt902sWXu6sp9JZ4sQ89d7pOv6MmPYRpTCje00D+qbICCk86w0ml1N2PE9RNdMk/UM7J8I5UPvG0uLdoPGyO+OtH/4oMev8d794Fw/NQCni1Yw1LSZ4ebNBtsCIci4KRDFnyjsAbrtnEVrlbkcUIVvxmv6Y5P9VgcJC71cb+GAqyUylq6nv8pgyA/GU4mwgbDoAsU3yUxIMpuTbnkw7H4i5wyNEf3dLkr+U0+X6P/dTQ6zv6kC9b+kWSxMWjH8rwbEHf0/BPlbuh1euNDim9yL7czhmG9bfjL6WCN7eFgQYbRIQSXlZyr0N/0Vc485dWNSlgd5wRx7IQ45Y3lZG12Up+gg2Q9Fm+1S1MCHkYHiNeTZAOLxKzz6Itf1QSHf0HpcLkGFWr5Nt/YcTCYwYRKHwWsbnAsS5A2fw1aTFOGJUkzeWyCwo5n7LUCWF8EmuP0XXDj7K2XovA8Ib4jk05ohoMmffDD0Lx5hLe4XiXRkQmNWSoRC1U+WYbxddJgWdBckGVHTn85lSflw3ruvgZUhYVJG5YSSQ+HdKXeAqd7w2qC8RIguiyIeNn5ZNS64ODEUF72YpqZ1y129VLrL+sNgRkc79BwuSUOyY5lj35i9l9NQYqmd7+y4Z48ttUx+ir/Cwqv83taYj433AKMtDVO6ak00HluWVXRfsCJbAk3R2XI1WEZIFd9YGdTJ44F7zULY5PWgrjzPkM4pQ== 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)(396003)(346002)(136003)(39860400002)(366004)(376002)(451199018)(8676002)(66556008)(66946007)(66476007)(5660300002)(7416002)(4326008)(8936002)(41300700001)(6916009)(44832011)(86362001)(38100700002)(38350700002)(6512007)(6666004)(6506007)(186003)(26005)(2616005)(83380400001)(52116002)(6486002)(478600001)(1076003)(36756003)(316002)(54906003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nWfks/8YSEOwOzS5WgJgLqoSq2jJnP5BYOHVdd6EJdQD6sJdyTP/n97rf3PIOpaPFIfHOcpshbxxR92c6lThA/0vQsySseDvWHnD2TIiqXnXRDW4wQfa0/3Ohd9VdEC0qJivP+xEJiyVmoIGQgTILD8RiPw2eu1pn+IPISedU8gtxiM36eDLzenaHu0QvAPdiKmSMHl1Nb/d5gqALD7cKhlnHIemtpnJLZNY+r4zUieTFLyNaxC5nmJ2PJ9qFmEaYcSGiLSvmocktOfDYz99MXl+UK5uKM6VTFzRV+8kPMNNsD3lo28j5Tozd/xMEqutCmvdL7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kGOty9avlFOJH1uOVbwUWfcVzP85yzWwZb+YY3Eld1Ttb2ocFpu3OWdynbqXof3VGZQtzQ9DO+CSd695o7AN2u9I4+Y91dhXHV1lBTs22Rp4YxRjticJPJZOMScLx3J5KlgKDNcN5imCRmneIggbHEZhGdK2rsaiwe83AOsuPCBn54L2M0vR1iNHG4jn3489ALHwqicbUaOxIvoODC5J5Mtw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9926974-8e8c-47e0-6bbe-08db1280bb39 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2023 13:53:51.1773 (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: cdkyWdBaI3hK/kMF3Q50cGSTQFWCFB3gG5p/ohjJZiVMs56Lip67/2NqacQJSTgmsVBj7ewJmVF/7gXf7pHCEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8238 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?1758267950742476260?= X-GMAIL-MSGID: =?utf-8?q?1758267950742476260?= 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 --- v1->v2: 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; }