Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1050421rwl; Fri, 7 Apr 2023 09:10:29 -0700 (PDT) X-Google-Smtp-Source: AKy350ZIVR+snXYFh49V9965SbnziAOonLLWjxyaSqW32uViFA5fbPnEWkUZ59cKBlIoAQht/5lZ X-Received: by 2002:a05:6402:1605:b0:504:7fd2:85d4 with SMTP id f5-20020a056402160500b005047fd285d4mr1311312edv.41.1680883829272; Fri, 07 Apr 2023 09:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680883829; cv=none; d=google.com; s=arc-20160816; b=LSxmxtgc/f3sXpINt5l2Xlsj9mXfiTartvndGcvyln7HBQIKe+mimOZsZte0oJmX/F k1CpGE4O1aX2vX0+8CSmFSN8baoFAEXQzHfqVTGmop7dIPa7XsW1ncbpfSt+z7/lrO6u d5XdDcFtF0PalD2qY8biBj+HmCVsxTjL7f7Ty2IiWAWdkseV0Jv3jBThDdaGz451DhCf RLn7T6TsTFxbxEcjLof7NslhfyufCIFeHm7we4JBkmzwtadmtCe11pGBaJ712uEvQdNR 3vuuaVvf/PHbeMFYgDrWyDO19Fmec/TsvTGpMiivC+JbvBwaZPctji2Sb30vfVT2rfNs WghQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=krZ9WXVd+XUYGaJUuD4z7K2OnYayfwpJS65M3AnYm68=; b=CDhAchMCXVoMripKMkghbFBy1k2TXhxVNve/tA1gpd3DX/0wS7W2uOgXAsla4T0aet tHmq885wKimRYRQkyXhhf+HrSG4gGN1eSV8lu2kAHZfdfXWRA4w1662zbil6dTrfrM2L ZhDmKdEewURNTtidIYVG5fz5qkM5K07fmhmsJytHh1kVEQnsORSS8lIPGgMNmOhwRjUm Z+H2IVUfye8/J1a63OPSdUxTvKJCypBYMbvIbKBgv0yqbhkA0854OAUUm0vnpm+UhulU YacDn9LNsBLm0LhF/qaNXAcJ6fWQSG4ZtYlBdE9g9sPZwQlfIAtwKiizscjcl/KY3irE 05HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b=Owkl2alq; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a170906488400b0092e8abc18a4si2566023ejq.965.2023.04.07.09.10.01; Fri, 07 Apr 2023 09:10:29 -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=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b=Owkl2alq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233134AbjDGQHG (ORCPT + 99 others); Fri, 7 Apr 2023 12:07:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjDGQHE (ORCPT ); Fri, 7 Apr 2023 12:07:04 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079B2B469 for ; Fri, 7 Apr 2023 09:06:37 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id p203so49390241ybb.13 for ; Fri, 07 Apr 2023 09:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1680883593; x=1683475593; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=krZ9WXVd+XUYGaJUuD4z7K2OnYayfwpJS65M3AnYm68=; b=Owkl2alqiRS1TfrgjEEXHOxmEzJEWwi4rpTQnjh/YgyiF5An50fY2F3b7dZoqdeEsD 7bmR7fJ6NCy1aLdpsSPEtakrkrUveU+7TfY/snJE0s14DFRA7WtxjyT78aIiQfRyHJG8 vWr9a7oVHa72TqtECZsflb2yUPQrYuGhLXpSJCWQ96tIWy7+ej8URSFJFO4dXsBQVpge 3MTWbONXGH5AZLopEIs496Sl4fKQ0/ytiEyvRhYF/g6V4BLFIHRfS+CHmQO0bVq5G5Gl 9S8N7J0XRjLWWA8rdpUEg7WOBB+Js4mHVqBtoSyeqslAQAsjxWrsTpt2V0fvobbgjXmj wmIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680883593; x=1683475593; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=krZ9WXVd+XUYGaJUuD4z7K2OnYayfwpJS65M3AnYm68=; b=Oom3BnOYiYAi0tXJ9bUUoOqZ+QwIkSc7SFaYAjjmGLiWjqhX+sZiff6IO7R60LDdpm Zgq1H09M2km+KTwsHiyTCkfN9s7ysnzIQvDyF6qYqOTZlUQnVb98PPVLlkGQMRJQXwog edcRyayXlBx8GNdXFd1Losmr8Y4kXv2J24BLCxDyavZTMZ99G8ZUcLOVaXseTwOTDafH AUsl/fUekoSHwYKOOteIsqAXWZTrh3LaikYq02ctX/oOSh+RtNheaYQJyiFy/UIPqevu wA7iTw91ZXqThTb3STHM5CPLTUUZiDCoH/xGngvjXyFhFw8Jmfv1iycfT1Bn6R9qCxy5 5SYQ== X-Gm-Message-State: AAQBX9ewLBJjsptgT2NiU5saAM8tLpqvnRvk9WE3ay8RkoJEy+xyHUla F2UQDigVrOPV+/uiexrZ1CZ8XJP2nyIWowNFAJhEfw== X-Received: by 2002:a25:c907:0:b0:b39:b0d3:9a7f with SMTP id z7-20020a25c907000000b00b39b0d39a7fmr1601845ybf.7.1680883593480; Fri, 07 Apr 2023 09:06:33 -0700 (PDT) MIME-Version: 1.0 References: <20230403103440.2895683-1-vladimir.oltean@nxp.com> <20230403103440.2895683-4-vladimir.oltean@nxp.com> In-Reply-To: <20230403103440.2895683-4-vladimir.oltean@nxp.com> From: Jamal Hadi Salim Date: Fri, 7 Apr 2023 12:06:22 -0400 Message-ID: Subject: Re: [PATCH v4 net-next 3/9] net/sched: mqprio: add extack to mqprio_parse_nlattr() To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 On Mon, Apr 3, 2023 at 6:35=E2=80=AFAM Vladimir Oltean wrote: > > 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 cheers, jamal > --- > 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_MQPR= IO_MAX + 1] =3D { > * 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 =3D nla_data(opt) + NLA_ALIGN(sizeof(*q= opt)); > int nlattr_opt_len =3D nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); > @@ -167,8 +168,11 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, st= ruct tc_mqprio_qopt *qopt, > return err; > } > > - if (!qopt->hw) > + if (!qopt->hw) { > + NL_SET_ERR_MSG(extack, > + "mqprio TCA_OPTIONS can only contain netli= nk attributes in hardware mode"); > return -EINVAL; > + } > > if (tb[TCA_MQPRIO_MODE]) { > priv->flags |=3D TC_MQPRIO_F_MODE; > @@ -181,13 +185,19 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, s= truct tc_mqprio_qopt *qopt, > } > > if (tb[TCA_MQPRIO_MIN_RATE64]) { > - if (priv->shaper !=3D TC_MQPRIO_SHAPER_BW_RATE) > + if (priv->shaper !=3D TC_MQPRIO_SHAPER_BW_RATE) { > + NL_SET_ERR_MSG_ATTR(extack, tb[TCA_MQPRIO_MIN_RAT= E64], > + "min_rate accepted only when = shaper is in bw_rlimit mode"); > return -EINVAL; > + } > i =3D 0; > nla_for_each_nested(attr, tb[TCA_MQPRIO_MIN_RATE64], > rem) { > - if (nla_type(attr) !=3D TCA_MQPRIO_MIN_RATE64) > + if (nla_type(attr) !=3D TCA_MQPRIO_MIN_RATE64) { > + NL_SET_ERR_MSG_ATTR(extack, attr, > + "Attribute type expec= ted to be TCA_MQPRIO_MIN_RATE64"); > return -EINVAL; > + } > if (i >=3D qopt->num_tc) > break; > priv->min_rate[i] =3D *(u64 *)nla_data(attr); > @@ -197,13 +207,19 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, s= truct tc_mqprio_qopt *qopt, > } > > if (tb[TCA_MQPRIO_MAX_RATE64]) { > - if (priv->shaper !=3D TC_MQPRIO_SHAPER_BW_RATE) > + if (priv->shaper !=3D TC_MQPRIO_SHAPER_BW_RATE) { > + NL_SET_ERR_MSG_ATTR(extack, tb[TCA_MQPRIO_MAX_RAT= E64], > + "max_rate accepted only when = shaper is in bw_rlimit mode"); > return -EINVAL; > + } > i =3D 0; > nla_for_each_nested(attr, tb[TCA_MQPRIO_MAX_RATE64], > rem) { > - if (nla_type(attr) !=3D TCA_MQPRIO_MAX_RATE64) > + if (nla_type(attr) !=3D TCA_MQPRIO_MAX_RATE64) { > + NL_SET_ERR_MSG_ATTR(extack, attr, > + "Attribute type expec= ted to be TCA_MQPRIO_MAX_RATE64"); > return -EINVAL; > + } > if (i >=3D qopt->num_tc) > break; > priv->max_rate[i] =3D *(u64 *)nla_data(attr); > @@ -252,7 +268,7 @@ static int mqprio_init(struct Qdisc *sch, struct nlat= tr *opt, > > len =3D nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); > if (len > 0) { > - err =3D mqprio_parse_nlattr(sch, qopt, opt); > + err =3D mqprio_parse_nlattr(sch, qopt, opt, extack); > if (err) > return err; > } > -- > 2.34.1 >