Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp665063rdb; Thu, 8 Feb 2024 18:27:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRX58quN3ZLV/ooJLJb2WtOElDQ2E/3aJYT8UVUm6hTmjRooxvPPkdys71Ex5idfHl4fKS9Pc/55eIiMZZ6c6DyXfniSM3K9hm/RK2ig== X-Google-Smtp-Source: AGHT+IF4AuM9tIl7tgdThypyyZr03IlpHKfrlli03/EcWb3J75Jr069exTdB7b9ruqP87jxx5VlS X-Received: by 2002:aa7:d1d6:0:b0:560:e82e:315c with SMTP id g22-20020aa7d1d6000000b00560e82e315cmr204885edp.42.1707445666426; Thu, 08 Feb 2024 18:27:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707445666; cv=pass; d=google.com; s=arc-20160816; b=RM2p+/h4OeZ1Vw3LAVGOX2KGLuoW57wH7moBTE5XFJwtXzZkjVFNZVwuNxhPW5KaNU aybUiCTkigZDySZNzaO1OTbMlWUH3GaKEHRoKmC3gJHYL15+O0Sm6D9SWUa0RmHA3msM /nnCFPyhmNTqju+uYt6BcP8+OQWfPbrnqe//zlJHoPO6M8QafVzSqDawisJEX3teHd4v X1UIlbk2ZBxTvO+4mq7d2IfJpuu7ENbCw3JzSvyOWDkdk1BA/ydR/gKFs+yjPTWYSTRi 7xTBNP6qflEbZRkzLyJMgy2fof8wIowmmkt8oLkMzAeJgEtW3g62t0+yn2C1hsNxfip+ w6Mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=B79mrecJ7457kN9xOt1swBv8yJJDWbEeFoSIj7r900w=; fh=MdzHckkbgmBFhUhxTEzpfpR+VMJbuhD4jwmnFVxBKrs=; b=UrU3W+adDdwgM32t3qp/H5M+LBrQt4Pkjec7OZG1AWXbQctFV6C5yJFiMZH+Uy5rG+ MPbicB+S/qQk3zglmGP4COxFuP0bwrsPOo3E5UV4V/m7jK8NP1Ac4zoLX0bMrbH4YcRy ghRQJygFBPk5l8Zv+OdoXAJFlA9TnNqTUqzpY1FQw1LaLR/z9smNIBpn6gXYEoPMKoKz XzS7ZuGT5kO/s43dCviDYk6LAJ2YmdZbyBgfoqRPdf57eqaO+isF6Rz5wsFqZEefyV8Q EpVx4Bd9BlFCSuzvp5gK7OO/G46p5XtzDw6MaghaLnlvKFGO8kLXjkp1WjWaCpwlBUQT wGag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/NNPHYt"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXElsryENPVcqz0Yq4x5vTUmovoRt05r7fLmu8pd+8NGeaGMNImTDhO/9WKZpoNvXyT53XdYtr+GUkzW8PsKGzqwR56MMi3nrAID4ZEOQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f4-20020a056402150400b00561207ef594si341760edw.55.2024.02.08.18.27.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 18:27:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/NNPHYt"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EFDD21F23ABF for ; Fri, 9 Feb 2024 02:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A81DF1865; Fri, 9 Feb 2024 02:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q/NNPHYt" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C121215AF; Fri, 9 Feb 2024 02:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707445653; cv=none; b=kQ2Uz7YaBsJ+LQivzTjvPQ4QS/X8McMcG9tYkaNE0o7SlblPw4bmi64iwb3mhJRuux51UPjqlPKflG2sDySaV/P+he0VCxccnOKgS/ssdwHahc+MdLTfbzhpSEMXI1SC7jS7bw5OWAJNuUbGgelfEZP2eZ88gOml+18lzGVFjgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707445653; c=relaxed/simple; bh=ns/Mvlqwop9xUQ+s6HUrxZXwL1LrVIE2gNKocZqIGZs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C5r7kZ1QzvGBTv6CZVLPI75kDvcytXrqOEVLEZMH5yENZidOOv+OCTflBz3l6M0SZaZshIHAePeRmZnh395xD1LncYu/ctsOU7xK+iqUZtkO382Tsb0SZ308pDzTEXWGwiKPVlptMWFXCPzEBlZD2d8bXekWyAzwSNYcRB4UscA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q/NNPHYt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369AEC433F1; Fri, 9 Feb 2024 02:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707445653; bh=ns/Mvlqwop9xUQ+s6HUrxZXwL1LrVIE2gNKocZqIGZs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Q/NNPHYta14WToW10B1jDtf5GB71d020cOck6SAiVs0HxnVHub+JpbRUc15VBhWSV V0Xkl6/f3+xE2W2K3syL2s98cvi5JicoIUoXeFs0Bng4raT4MJ16l3wEXxczxJ4jet x+NV/1T3ib99o8aaqTxIKuGLUYy4W9T2oB510D0Oh7ayljAjCsslKEs8v5HQqxA0Ho cecWZQfXc40jjyqKPoO/i2Y9XuCaSzS2Zw8ml2zdA2fxO8bEXAvqsbNNgaWS1649nh Xny8qjuqDL4LLnpiavfCXKgj5mduYbXU/UDe4HT50WJboYrVh7dvSG1CLXt7E9vPBP 9Jxs8eCX1K3Lg== Date: Thu, 8 Feb 2024 18:27:31 -0800 From: Jakub Kicinski To: Stephen Hemminger Cc: netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Paolo Abeni , bpf@vger.kernel.org (open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)), linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH net-next v2] net/sched: actions report errors with extack Message-ID: <20240208182731.682985dd@kernel.org> In-Reply-To: <20240205185537.216873-1-stephen@networkplumber.org> References: <20240205185537.216873-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 5 Feb 2024 10:52:40 -0800 Stephen Hemminger wrote: > -static int tcf_bpf_init_from_ops(struct nlattr **tb, struct tcf_bpf_cfg *cfg) > +static int tcf_bpf_init_from_ops(struct nlattr **tb, struct tcf_bpf_cfg *cfg, > + struct netlink_ext_ack *extack) > { > struct sock_filter *bpf_ops; > struct sock_fprog_kern fprog_tmp; > @@ -193,12 +194,17 @@ static int tcf_bpf_init_from_ops(struct nlattr **tb, struct tcf_bpf_cfg *cfg) > int ret; > > bpf_num_ops = nla_get_u16(tb[TCA_ACT_BPF_OPS_LEN]); > - if (bpf_num_ops > BPF_MAXINSNS || bpf_num_ops == 0) > + if (bpf_num_ops > BPF_MAXINSNS || bpf_num_ops == 0) { > + NL_SET_ERR_MSG_FMT_MOD(extack, > + "Invalid number of BPF instructions %u", bpf_num_ops); out of range seems better than invalid. In fact it should be added to the policy. > return -EINVAL; > + } > > bpf_size = bpf_num_ops * sizeof(*bpf_ops); > - if (bpf_size != nla_len(tb[TCA_ACT_BPF_OPS])) > + if (bpf_size != nla_len(tb[TCA_ACT_BPF_OPS])) { > + NL_SET_ERR_MSG_FMT_MOD(extack, "BPF instruction size %u", bpf_size); Doesn't sound like an error. Something about number of instructions not matching the program size would be better > return -EINVAL; > + } > > bpf_ops = kmemdup(nla_data(tb[TCA_ACT_BPF_OPS]), bpf_size, GFP_KERNEL); > if (bpf_ops == NULL) > @@ -221,7 +227,8 @@ static int tcf_bpf_init_from_ops(struct nlattr **tb, struct tcf_bpf_cfg *cfg) > return 0; > } > > -static int tcf_bpf_init_from_efd(struct nlattr **tb, struct tcf_bpf_cfg *cfg) > +static int tcf_bpf_init_from_efd(struct nlattr **tb, struct tcf_bpf_cfg *cfg, > + struct netlink_ext_ack *extack) > { > struct bpf_prog *fp; > char *name = NULL; > @@ -230,8 +237,10 @@ static int tcf_bpf_init_from_efd(struct nlattr **tb, struct tcf_bpf_cfg *cfg) > bpf_fd = nla_get_u32(tb[TCA_ACT_BPF_FD]); > > fp = bpf_prog_get_type(bpf_fd, BPF_PROG_TYPE_SCHED_ACT); > - if (IS_ERR(fp)) > + if (IS_ERR(fp)) { > + NL_SET_ERR_MSG_MOD(extack, "BPF program type mismatch"); > return PTR_ERR(fp); > + } > > if (tb[TCA_ACT_BPF_NAME]) { > name = nla_memdup(tb[TCA_ACT_BPF_NAME], GFP_KERNEL); > @@ -292,16 +301,20 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, > int ret, res = 0; > u32 index; > > - if (!nla) > + if (!nla) { > + NL_SET_ERR_MSG_MOD(extack, "Bpf requires attributes to be passed"); You use "BPF" (capitals) elsewhere. Also not sure the "BPF" prefix is actually needed, given the _MOD() will prefix this with cls_bpf already. > return -EINVAL; > + } > > ret = nla_parse_nested_deprecated(tb, TCA_ACT_BPF_MAX, nla, > act_bpf_policy, NULL); > if (ret < 0) > return ret; > > - if (!tb[TCA_ACT_BPF_PARMS]) > + if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_ACT_BPF_PARMS)) { > + NL_SET_ERR_MSG(extack, "Missing required attribute"); Please fix the userspace to support missing attr parsing instead. > return -EINVAL; > + } > > parm = nla_data(tb[TCA_ACT_BPF_PARMS]); > index = parm->index; > @@ -336,14 +349,15 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, > is_ebpf = tb[TCA_ACT_BPF_FD]; > > if (is_bpf == is_ebpf) { > + NL_SET_ERR_MSG_MOD(extack, "Can not specify both BPF fd and ops"); bytecode would be better than ops > ret = -EINVAL; > goto put_chain; > } > > memset(&cfg, 0, sizeof(cfg)); > > - ret = is_bpf ? tcf_bpf_init_from_ops(tb, &cfg) : > - tcf_bpf_init_from_efd(tb, &cfg); > + ret = is_bpf ? tcf_bpf_init_from_ops(tb, &cfg, extack) : > + tcf_bpf_init_from_efd(tb, &cfg, extack); > if (ret < 0) > goto put_chain;