Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4339300rwl; Mon, 3 Apr 2023 03:38:15 -0700 (PDT) X-Google-Smtp-Source: AKy350Zq17jn7zQ1fBhLQp6vamDR9w65UztCGkur8tuAdd90eODhATer2yxzCKm6GoAX+jVE6s+N X-Received: by 2002:a17:906:fa0b:b0:8b8:c06e:52d8 with SMTP id lo11-20020a170906fa0b00b008b8c06e52d8mr34878158ejb.36.1680518295520; Mon, 03 Apr 2023 03:38:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680518295; cv=pass; d=google.com; s=arc-20160816; b=CtygEjmG7jOx7yabdEa2LxUE21UWCqFEfa68ZNlZ/PaQJfRRCI7I9moOLZCQZykrG3 OWbZY774Zvlt475MxQQw1qFnHgE/DHTA6xCfiJVNcxBPxQaV07i8dHkZoKDwx+6g61pZ iyC0ZuUyaa056MXnjsPY2iPVbfqXBtLVjeATBYquNXSJZ7vSAeYbO+yVCpirgMlmPh4t Rpjr/j+Jtks5TrB3IPwNafjQjHiMEpEcqTfiJjoG5eVRgQOwpmFGu3QzfScyrDJuCVjY xtHrgHJjQ4Z1Cvc8L+hvHzMa78um0WOiJWmO8B/NkLyTihTP4mYjnLPIE+TTGwNDwjpC Sm8g== 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=pvzSie3aWoYHN/vBqu+xf4Et325hToTaMuTZofsfdvk=; b=y2CwjxjNMZnBxb1HF50UAMpgI3WnHPyb+KYLg8iErY1GDw8t7VTrACxrndKqkcl0AF YwcHW0ve4wCVi0qFrfcNvkLffJFS8nq+isvFROGew+9KbYx6F716YFxIAyHVsCD/U7oV fB+yeQLjBX5Ki7i/g9rYIlbs2wVkrZanP7iFvgAY7N2YMVNF0K61SfbokC7loEv3C8ic G7U50vBDfNuf2hDQSyPxx7njjbJs+YSGi8VVnLygXXoxsceYIMtYw/Pn79URgIuY/9iX 7/Mu+sUsfkAnf7KG0cobQPk71j0pWctwi93rCXtcbx9FnZPl2HJkyctM0vHqd6b0tjLC VNqg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Eil0GJ+R; 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 m17-20020a17090607d100b00947a72931edsi7349275ejc.397.2023.04.03.03.37.51; Mon, 03 Apr 2023 03:38:15 -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=Eil0GJ+R; 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 S231833AbjDCKfU (ORCPT + 99 others); Mon, 3 Apr 2023 06:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231899AbjDCKfE (ORCPT ); Mon, 3 Apr 2023 06:35:04 -0400 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2064.outbound.protection.outlook.com [40.107.105.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40F7030C0; Mon, 3 Apr 2023 03:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yf/2dyxkOyn/S+4cG3C87CRMFoPG7Gw8SX/q7javzp6nJ3qMjFiRqQavnbHIIB90gk+XoV06q81zRI6jH/h6ckl+wYzI7gFGfYBweqfZbnc+ccLwsg4qwUZBi5gL4Y7VO7bKkw/TeC2Aq6WKKPrUVs3zFSC57BvMEx2TEiyRiMl4ydiLIv6Hzl4unMk/wLe+BCiD0e+EN1DGLqhLVQTD/AQPQbWrMOnei6tHkzepMxq5lw+tB9HTeuZGOOublSGHwGcKb/vhrHqdNEiUYB44uKHRU0bwiAT41Iajn8JauoyXnX1bbXjqYrZjw16cLBexH/pTIn2GE9mUzEd1HgoTHA== 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=pvzSie3aWoYHN/vBqu+xf4Et325hToTaMuTZofsfdvk=; b=Sz92Om1D0C43meAbsLctHrtzUhThL/hN9muBRwS+gdGQID1rmUUv6fC49tlCoOmh3ZwAMFzZgO1Pn6KI74uk5zaTmI2mdlYFkGh0GN3kD0cjpX5btWRDyIaiDuVMYNfnsWXc93YpY9V2epcpxAlTo3ivaXe/eKCcN0jMXr9Egwb5rEGGAPKFUEv18hBK4EkGRe/AQTLW61i2eioCAjKWE4r11Ae3AyKXHN7yMYmPbTunltG9OB2WHzwPd7jZ6fE0sMjgJ7pOJe2sKJqnc+yUe4nNejQGT8gcFE8dJiFEBopWTqc8u4HrSNyaPuWwmT+1rLQl0RclZ+l4iJShe2/saA== 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=pvzSie3aWoYHN/vBqu+xf4Et325hToTaMuTZofsfdvk=; b=Eil0GJ+R9fBly/QxFJpzn5RZ2DrrPtfqHoNKl2RIlwcUvuNlDYv4Q4cXx1e7X+HSJcwCitJUyNPc1LosL2dxM86A1VaAOsBiF9rszzn4JyuqE0fg7TQtNLr+0d0q1JoVGZdWJaNzJfBxQ7GL7pdbd++XlQQzJrnYHISVPwsHYuM= 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 AS4PR04MB9292.eurprd04.prod.outlook.com (2603:10a6:20b:4e7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.29; Mon, 3 Apr 2023 10:35:01 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Mon, 3 Apr 2023 10:35:01 +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 v4 net-next 3/9] net/sched: mqprio: add extack to mqprio_parse_nlattr() Date: Mon, 3 Apr 2023 13:34:34 +0300 Message-Id: <20230403103440.2895683-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230403103440.2895683-1-vladimir.oltean@nxp.com> References: <20230403103440.2895683-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR0P281CA0221.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ac::17) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AS4PR04MB9292:EE_ X-MS-Office365-Filtering-Correlation-Id: 94a5e21a-1a9c-45f9-5de8-08db342f148d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4aEywu5ol0sOeD/ew5WZyJ0Y/9DSfsDB31++3NGGK6xgE/3bF0uOs8dfgcvHjsD08o0Y3ZO+lBTRG9ZxytebVKGiuvb6qQ3Q9EJd0h4iYz9OPQcmivnl0F9x1Gy7ukjVpG8oFFeHBd1TGKC8kUQnpDRBDqcqPU2Jq2pJ9749TQiilYEjqyLgFHxVBrR7HK7pbc+bDJBZDkahs3sF5+ghbUXCxcQk96HtjLrCKIXRBszfNYFNMcl69A04RP3sf62UMVnp6j0tnMw5S0J+cgvsqKHUU5UPCNYH3+QIJ7JOJvW0nCcAa0iBbrpf59OEKwdJUL/mj13+yKGPnqFkfNwikdfs39kd5KzZGw60zOoebh88q1fUPd3Kh+xTc7ApeKCBTbydput9yrRGElwYX9fBH80Keynr/ncCrgv6lJ1Vbhsj3ydhSdnQUg/W86xB9pB2y/5QyDdgr7mFwVznpC3rmiGulXyrtU0v5N9fKktROee5tKAH+NxECtbTZ0DMGI3tRCM4aHofXVhwj8j/C4ILjFtRsUZMcTbTmEWP6m9HqEQX/pTURdavAH6rV8ipyPm/mLmHMpMt3hciyxMoe3Dj2i8Jw0bIrKWwy1EC40jjy5zP9IC1iz9YCDrlmLHzMRL8 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)(136003)(39860400002)(376002)(346002)(366004)(396003)(451199021)(26005)(1076003)(6506007)(186003)(38350700002)(38100700002)(6512007)(86362001)(316002)(54906003)(41300700001)(7416002)(5660300002)(44832011)(66556008)(66476007)(4326008)(66946007)(8676002)(6916009)(478600001)(52116002)(8936002)(6666004)(6486002)(36756003)(2616005)(2906002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?IyQDSRtLsb/0IIj7tOKIF6EC/yG87gNVH5XVXtVXF+He9ZY16v5gZOCC9Vbe?= =?us-ascii?Q?JzPzyWCDLbJEs9hjOmyOMq1MQGrut+BHvCjeKHmVbZbhuo6YmnOSfEeu+53v?= =?us-ascii?Q?FFCDTQcHh9OdmAunk22ftzRM2X8p1lsH9TG2CNri91NgYhzfry6iOUpGFSiT?= =?us-ascii?Q?JIOG52ftrlrPveTfwCAg06ZskDyUvB4fmFnJMz8lqpTJWMc+dHL75YGn5dYi?= =?us-ascii?Q?uYeXImnF8o0sQNYiyuTIZdVEBl9xWeuh+aRfJmfno68549Aibn5Wx2FJ0Htd?= =?us-ascii?Q?KCWlvTR154z1dw0UhHFlO78icPPJCq+tbRGUnZplZ2MJcOnFUyJmAPPP0Yu5?= =?us-ascii?Q?aoHyJN4jKhKyDIgPGVmdaiyAtZRAkRIKlf9qLoeEPqWTZnYwpNKBPlE7M2U1?= =?us-ascii?Q?g78UCpVZJLxql9WnN8//+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?us-ascii?Q?vh8n5y/5pUdemsZZGml8FzQKUiFhdb1qJimty0AZHRvuBVoxv8w2QwCYa+H5?= =?us-ascii?Q?jOvz9Z32VJLzSoGKn4/t8YtV6me3WX6askeP8A3jfe7sJ7c54NP2fdK/ksD8?= =?us-ascii?Q?uguXae5av/ZBLV5lD6JbJuDPkVaaw1cARAV61ScGOFaHt4Q8yR2uPg1IYi0q?= =?us-ascii?Q?6o17ET7QKcsa6XwBNaG7VEWFdJEKYYozkb2PakNzq4NcCkbEabP+HMsYWB+t?= =?us-ascii?Q?5hLsmQBMTrjlgUEabm3e1Tu3BcafwMy9NDKD8Uh2VYa2gU/Hf7f6sD0LNRJg?= =?us-ascii?Q?oQ=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94a5e21a-1a9c-45f9-5de8-08db342f148d X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2023 10:35:01.8507 (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: 2TB4azNzzguMTLWmZY322CTnzHWk1kwtcsE767PXfe0lcL2Mx3PtnioNV6132oOweJvA7+obB7Q3TNrSbA1TJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR04MB9292 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 --- v1->v4: 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