Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp25879rwl; Thu, 6 Apr 2023 14:08:34 -0700 (PDT) X-Google-Smtp-Source: AKy350aENnh52/k56qp6QUmNVcjtvF2Z8sLA+jADcAnTL8gfUwdmj6BrzflTQfhASy+eB2PFkggz X-Received: by 2002:a17:906:260d:b0:947:c201:df9b with SMTP id h13-20020a170906260d00b00947c201df9bmr303892ejc.9.1680815314244; Thu, 06 Apr 2023 14:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680815314; cv=none; d=google.com; s=arc-20160816; b=s1BI5jyHpV/EN6qmA/7nUQPuYNaTAhT3blU6Frkh/8JjyK8nANeOEAmWFXkUzAv179 1WF9Qp3sVMbnFsjhN5MMfyHc2pYy76oA+9r2Noh/B3zUtcloLv0NtNuDbfiut1FpUAk+ h2ZQrqu85rjyXAbiO2KvmP+iFXcDfKhZ5T03owOcO2hABSCfx1589Q3UpYzqKrl0aXB9 LfsBGOzqUPhDXHhAtQet0Ch4VM7KZX/yc+YJr+0/XBdjptW3LBv7/17hpgYzHpk6uvtU hcHHO7YiRGOrHhcB3XGg5M+1wMdd5SauWsLgJ9yKmneFIeCDabEqoSLZ/nxzCvnCzudF tjsw== 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=ZH+Py50y9vo4DMUtUbK/cR4JBKneDucbAHS4uMgQV/Q=; b=HRktBkjH7pCdF82jBeLeooIKPOmevnhr/2ApS6F0lHevmgCwunVqEmF7irC2quiwgY i84vts3a1wQQ5gCXr2sRNwfqx5yCdQlNbGlv5Io6PAo8AcYD3zCf8awv6cA94kvFJcbX IaQXr6kjRQw75p3OrY+96LDnx/9cx/j9UkegvZ/lxxjqJBNMI5Ek2m3/Y44ll0OtO0Gz eGlAZhsvScD8WuWO2yWeIiUVNvMijRVb0lHrY81SugurHW32VPRJQdrqgxGsZxY3CRCJ 0rrENO5ULi0uKg91G/RYfXfFZVwdYfoHW20N4rLH754vBqnTVSEZ/Fj0kSvyDyeZ0ztF WzIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KRVuosrj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a1709063a8900b0093d8207777esi1818971ejd.858.2023.04.06.14.08.03; Thu, 06 Apr 2023 14:08:34 -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=@gmail.com header.s=20210112 header.b=KRVuosrj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236879AbjDFUzi (ORCPT + 99 others); Thu, 6 Apr 2023 16:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjDFUzh (ORCPT ); Thu, 6 Apr 2023 16:55:37 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B1364ED6; Thu, 6 Apr 2023 13:55:36 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id qb20so4337932ejc.6; Thu, 06 Apr 2023 13:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680814535; 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=ZH+Py50y9vo4DMUtUbK/cR4JBKneDucbAHS4uMgQV/Q=; b=KRVuosrjlXoDxku6toLdouLKwUM658atx1aVXMcmtkqbiSm752xfpO6UFVT8mxCkWH wrhehxhP0Fw5WOSD5/gFPXvUijBJkpkHZqTNFQdebJUuhsJEhmPhALa4iUAKTyfK3qnJ NL5/EpePbdo6U4N1m1g1nNj6Clqm8O6RjgwEAuqGhGmZGZjZIFZEJI0x0m5V9GpQO65D Xo6FyvT7NV59g7JsJrfAhdqqyFDRBHqxHYE2EDy7MYIY8azcs4gpOPVRdZ1sJMxDgW41 XVdsbTZTcBjrT/PgCnd0YuNMhxCJGu/WI2mvzwUIfsINc+V+NWbarY8+JQWjp3OJ4OeA UDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680814535; 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=ZH+Py50y9vo4DMUtUbK/cR4JBKneDucbAHS4uMgQV/Q=; b=ZCOhSookSbSuTeiS+vPMMLyUfyPbCuQIDIFysemkYTh8SYDAgiF0YBP8giwKmDHCAf Bpl2fP7iE6eWzLS+KViohtyDNWsxflt/ec5Xo9cPbIZX5l2UgEHas/E8avuGabFDH7F4 JARmyfakyatjF9nICcuXElsi9qR7zKSm8kDBo928vj7pTAk4veO76/TFpPEbvp8r8/GY SQQbV3VF4m0VGzhYt/TnNZCOpiWnJLUP/oeLmUWQjpUG3kRggbYcyJQCwHd12+9hM1Y3 X6C6Sybxv5IZtI0eEzPdKZspF88LSbHrS7lcXBt5qNLbATjbTJi53JLAbvEF8pHKtGae 3GlA== X-Gm-Message-State: AAQBX9c64NE42675bQjsmpS8wcygT5VCZG2Rntwd2wATBWMYAD0ji8Iy lz+yNF8T/te6dMduFS+c9hSlEk2Goy0+QO25rZyT7Ra2 X-Received: by 2002:a17:906:1ec7:b0:949:8e10:31c1 with SMTP id m7-20020a1709061ec700b009498e1031c1mr96576ejj.5.1680814534863; Thu, 06 Apr 2023 13:55:34 -0700 (PDT) MIME-Version: 1.0 References: <20230406004018.1439952-1-drosen@google.com> <20230406004018.1439952-2-drosen@google.com> In-Reply-To: <20230406004018.1439952-2-drosen@google.com> From: Andrii Nakryiko Date: Thu, 6 Apr 2023 13:55:23 -0700 Message-ID: Subject: Re: [PATCH 1/3] bpf: verifier: Accept dynptr mem as mem in helpers To: Daniel Rosenberg Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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 On Wed, Apr 5, 2023 at 5:40=E2=80=AFPM Daniel Rosenberg = wrote: > > This allows using memory retrieved from dynptrs with helper functions > that accept ARG_PTR_TO_MEM. For instance, results from bpf_dynptr_data > can be passed along to bpf_strncmp. > > Signed-off-by: Daniel Rosenberg > --- I think patches like this should be targeted against bpf-next, so for next revision please send them against bpf-next tree. > kernel/bpf/verifier.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 56f569811f70..20beab52812a 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -7164,12 +7164,16 @@ static int check_reg_type(struct bpf_verifier_env= *env, u32 regno, > * ARG_PTR_TO_MEM + MAYBE_NULL is compatible with PTR_TO_MEM and = PTR_TO_MEM + MAYBE_NULL, > * but ARG_PTR_TO_MEM is compatible only with PTR_TO_MEM but NOT = with PTR_TO_MEM + MAYBE_NULL > * > + * ARG_PTR_TO_MEM is compatible with PTR_TO_MEM that is tagged wi= th a dynptr type. > + * > * Therefore we fold these flags depending on the arg_type before= comparison. > */ > if (arg_type & MEM_RDONLY) > type &=3D ~MEM_RDONLY; > if (arg_type & PTR_MAYBE_NULL) > type &=3D ~PTR_MAYBE_NULL; > + if (base_type(arg_type) =3D=3D ARG_PTR_TO_MEM) > + type &=3D ~DYNPTR_TYPE_FLAG_MASK; Something feels off here. Can you paste a bit of verifier log for the failure you were getting. And let's have a selftest for this situation as well. ARG_PTR_TO_MEM shouldn't be qualified with the DYNPTR_TYPE flag, it's just memory, there is no need to know what type of dynptr it was derived from. So if that happens, the problem is somewhere else. Let's root cause and fix that. Having a selftest that demonstrates the problem will help with that. > > if (meta->func_id =3D=3D BPF_FUNC_kptr_xchg && type & MEM_ALLOC) > type &=3D ~MEM_ALLOC; > -- > 2.40.0.577.gac1e443424-goog >