From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 DC3411AA8B for ; Fri, 4 Aug 2023 22:26:47 +0000 (UTC) Received: from out-120.mta0.migadu.com (out-120.mta0.migadu.com [IPv6:2001:41d0:1004:224b::78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D461704 for ; Fri, 4 Aug 2023 15:26:46 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1691188004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VlHvVn8ION/wYMTcwm/zIJedCAnl/hLvcfGQJkof7IM=; b=AjPHjOyQGFuAhWHcOt26P+iYoIVdygHw6jC/Fj8A4P1L9PvUP3Pd+gtbD7hknbpM1+fod6 ZEPoNOUz8mYkxOCAa7T0zaNJ9BKLb3kNZRk/NZKYSDHeGsFrFxT8TYPkBIgZjSzOrFSCE6 mpQ3ERTp1MuW9tqdXmcoKMIvk4QiB7I= Date: Fri, 4 Aug 2023 15:26:40 -0700 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next] bpf: fix bpf_dynptr_slice() to stop return an ERR_PTR. Content-Language: en-US To: thinker.li@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Dan Carpenter , Alexei Starovoitov , bpf@vger.kernel.org, ast@kernel.org, song@kernel.org, kernel-team@meta.com, andrii@kernel.org References: <20230803231206.1060485-1-thinker.li@gmail.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20230803231206.1060485-1-thinker.li@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On 8/3/23 4:12 PM, thinker.li@gmail.com wrote: > From: Kui-Feng Lee > > Verify if the pointer obtained from bpf_xdp_pointer() is either an error or > NULL before returning it. > > The function bpf_dynptr_slice() mistakenly returned an ERR_PTR. Instead of > solely checking for NULL, it should also verify if the pointer returned by > bpf_xdp_pointer() is an error or NULL. > > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/bpf/d1360219-85c3-4a03-9449-253ea905f9d1@moroto.mountain/ > Fixes: 66e3a13e7c2c ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr") > Suggested-by: Alexei Starovoitov > Signed-off-by: Kui-Feng Lee > --- > kernel/bpf/helpers.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 56ce5008aedd..eb91cae0612a 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -2270,7 +2270,7 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset > case BPF_DYNPTR_TYPE_XDP: > { > void *xdp_ptr = bpf_xdp_pointer(ptr->data, ptr->offset + offset, len); > - if (xdp_ptr) > + if (!IS_ERR_OR_NULL(xdp_ptr)) Considering the earlier bpf_dynptr_check_off_len() should have avoided the IS_ERR() case here, I think targeting bpf-next makes sense. Applied.