Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1435396rwl; Wed, 5 Apr 2023 17:42:05 -0700 (PDT) X-Google-Smtp-Source: AKy350a4nRNFop3ZBZxsMURkWnQo3T91o3w8+4W85NG7oAMk8hWNj0fXCQz2olrFNhDkX+K5aPfT X-Received: by 2002:a17:90b:4a4d:b0:23f:c096:7129 with SMTP id lb13-20020a17090b4a4d00b0023fc0967129mr9216591pjb.26.1680741725209; Wed, 05 Apr 2023 17:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680741725; cv=none; d=google.com; s=arc-20160816; b=EObyRKQMBaLl3rA0w3nMFjEQWvWTylX509T1joyd0Y4x6PSEYzMYuvjKtFyVcud98o eYz2mSvKakQwtxLfVfJPJy+hRTRmJWoB3XxfYCrWe1D3xpXfHfRfdr5X+WQuu5eTfe0m 5hRiLxiXY7ziFEJOD0jcEdgA5f8LR/DcjjolsqgDt/7UTOh4/ndFRfD5s0lWX5PqZ7jE 9vAAK9nn/rTi8LaDmNW7TgHRUH89YtJMgbhCOp8Mq5llYMA7iYpl/BQaNjO4c14wwnyF Of/kIkKah+4H/96LajYYGI54dfZI7Fm06UhnJZmBSVQcw4lUrPOLXJ3IAPbD5vodBbhR qYrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=McDcXFBeTpRROxQUqMA2pgjkFzg3DM0Jer8s1DpCFu0=; b=uuykb4+r4Jw8CDMTjqegccNj3G3oYCQUV+3YxU58vVdkToHYj6zK1GyHEVSifeJQXi tMhDqWUr/4EcPYX0yuThgr0o9Gvgqyj9qIk7Mq+dFWVlHWn+K/n6J3vqx5zSQbPHQJjQ W5smwHpNTUsuLUNbzHIvflNFtIuh5/IQAqmYrANR/R7RBEm+L9M8QjXnTzpk0x9NAqJt vAt4SZ03UQmAfte4VVmJpJhvjdX+lmncsZclnUb/EixW603/U79LNOLauEvLM26kFa6c 3uIXcxkkk9MkWRhkEWjOTb84zjwjiJe8m3EglEh6Z+NNnq227CW9EwSiojKH1TXuU6oU l4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=k6n8mW0A; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902a40100b0019a78d4c761si344037plq.93.2023.04.05.17.41.53; Wed, 05 Apr 2023 17:42:05 -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=@google.com header.s=20210112 header.b=k6n8mW0A; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234581AbjDFAky (ORCPT + 99 others); Wed, 5 Apr 2023 20:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234396AbjDFAkt (ORCPT ); Wed, 5 Apr 2023 20:40:49 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F66768A for ; Wed, 5 Apr 2023 17:40:41 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-546422bd3ceso199691697b3.21 for ; Wed, 05 Apr 2023 17:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680741640; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=McDcXFBeTpRROxQUqMA2pgjkFzg3DM0Jer8s1DpCFu0=; b=k6n8mW0A9t/ctuMHEzGCgb/5wxgpyQ5jaCdkYx8TZ1jyPWjcmMfd4/5a7xdPJ7enxv i6p2+isHp8Qg0KGWx3DnJa0nLQYm67mK4V+T+/O2O8Jw4X04X0osjYtQZhCU08gXjXCk rNfSEiCcH5hxmP3Okc/9TNGb7EbYdpnTgsgC8rOB5fsWJe86pmDimQ4/JHFfmt2JWfIT 4+w0KwFg97MC7sTzOC2YFeE/SaejQBNBB5gDhyf0sIpuKngXGnqbp3Vms59AB6YDcSz7 +bbmEnegVj8U592jfJ8TMuMw1MuZwJaGllugkf5y692Kw8YYrTXZJuDKUmdg9D9nBWcd 0WnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680741640; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=McDcXFBeTpRROxQUqMA2pgjkFzg3DM0Jer8s1DpCFu0=; b=Aj73tU2cAclI0hkSLyXcl1/yRDbsAI/h7nDqA24z1uWR5gtO7B/8IOl872fLKRLZ/r zO6DPRjG+yYgIS+Y6RjIr1URdS/UpF8SbfoKt4eFqlKryEq2PY/PVaagpxDl/DtVRAlS cnIk8FiBPtClwmbSb3YJ9tcpyHGeMDgl1HNDPSsQX/X1mmaFIyCs1BJeagxieeCqMrO+ cF+ilf7tw0BwmTT66PZLa9MLnhJUg1MTCR6p5AH/c3zF1J8IdIVTHhHG5I5WUpC6az+R GTLF76Cwt3vNplu0LjAaiwJn6vfmPY2WHrzmDiNnGcTAOA5Bkb7SkPwu2uJzDvxXg9Wz kNUQ== X-Gm-Message-State: AAQBX9dQ3zvS/BTvk3KXWbyXI78f5WC623G6oeyg/aCx27/l2TJyMkKN HHm8Pl8wydTwwWfOIrWtQiGafqnlAWQ= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:694f:f21b:c6de:aead]) (user=drosen job=sendgmr) by 2002:a81:b609:0:b0:541:8995:5334 with SMTP id u9-20020a81b609000000b0054189955334mr4835018ywh.3.1680741640430; Wed, 05 Apr 2023 17:40:40 -0700 (PDT) Date: Wed, 5 Apr 2023 17:40:16 -0700 In-Reply-To: <20230406004018.1439952-1-drosen@google.com> Mime-Version: 1.0 References: <20230406004018.1439952-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230406004018.1439952-2-drosen@google.com> Subject: [PATCH 1/3] bpf: verifier: Accept dynptr mem as mem in helpers From: Daniel Rosenberg To: bpf@vger.kernel.org Cc: 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, Daniel Rosenberg Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 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 --- 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 with a dynptr type. + * * Therefore we fold these flags depending on the arg_type before comparison. */ if (arg_type & MEM_RDONLY) type &= ~MEM_RDONLY; if (arg_type & PTR_MAYBE_NULL) type &= ~PTR_MAYBE_NULL; + if (base_type(arg_type) == ARG_PTR_TO_MEM) + type &= ~DYNPTR_TYPE_FLAG_MASK; if (meta->func_id == BPF_FUNC_kptr_xchg && type & MEM_ALLOC) type &= ~MEM_ALLOC; -- 2.40.0.577.gac1e443424-goog