Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6156173rwr; Mon, 1 May 2023 17:52:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ72nbQ05m/ciPEVYX3W7W07yq/r+tSGpwgU9ESTnUJJh+LQ1aC2NWO79Og6ilOP8RVG6Vly X-Received: by 2002:a17:903:41cd:b0:1a1:cc5a:b04 with SMTP id u13-20020a17090341cd00b001a1cc5a0b04mr19687470ple.3.1682988776867; Mon, 01 May 2023 17:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682988776; cv=none; d=google.com; s=arc-20160816; b=MeFCjWJxkG21haVjJcGqkWbOhNMMD+MzmU8XAydwZXQgjIFiVPIKMN8KJbWNWYaXvF bDOeAEVFW6wFrSHvdSz9mxlSZIjc1fKf6rj2v3pD8cv0V/eT3CC4vdo7aWC1wnHBpnjI eHuR1Gudd58Mk6BPTGzCzUI/UmTw/rafDKT0ts9GvC0taqdNCPy/zyVI7RwLXg/gVrpC PJQkhDxX8054ZfAFEyrxEbsxYGF42m8k+c0fw4mmbZoNP9NirEBnUE5Isa5YSCu9GIbX syVgxwvHYe65mTafbrIy5pE6oESSWJ2wnBUGjnxUmYqilr4Q3O60MnBCKEwylc4z8/LT wDWQ== 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=jcg+ObY0uKE7Plv6+Kj2nIBfbZ7utIjukDPBrr4BYWc=; b=OSMT3i1VJ0zdxk7Tq5AfVYJGHo4TT145EHrqggQjoNkwVU9DhWembARkDgx2V9deq3 VtH/MMbp3tAgdVIG6tXFG8JZDBWTabQscZtFGgsfwUalLXH9XQ8kwShz7CIcYpaxPwnX pmGGTwlIJSQLP+fajHxycZ6Ib5807pQjnEDUJQi7liFF2D2L4T60PBKUYlt14ay1aFTY WG3Q+OhFWVOmK6vzW2Lp1uKAc/6bqkbhRZVZVsTRPISY5TUOh/pgDtQaPN3VqFd/lkRB 8AOupjWiLNjglK7TxBeXS1WuejnkSGDh+k2E2Bb1SOGxy1XLZpqYgMBn9aiziZfmO8TR QszQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=rYQSqPKo; 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 bt8-20020a17090af00800b00246d776cbdcsi2102275pjb.57.2023.05.01.17.52.43; Mon, 01 May 2023 17:52:56 -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=20221208 header.b=rYQSqPKo; 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 S232627AbjEBAwc (ORCPT + 99 others); Mon, 1 May 2023 20:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbjEBAw3 (ORCPT ); Mon, 1 May 2023 20:52:29 -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 4593E3583 for ; Mon, 1 May 2023 17:52:28 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-559d30ec7fcso66114617b3.2 for ; Mon, 01 May 2023 17:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682988747; x=1685580747; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jcg+ObY0uKE7Plv6+Kj2nIBfbZ7utIjukDPBrr4BYWc=; b=rYQSqPKozvop6FQA27tCKPMMocl2dT4bgtQrMsrykc/YWbzOREznkvJfsptxQWgLxw oO82Zx1edFTqiTXXK/v5aDAXURCmJ09vOhY+vO5I8xtNxt5WFfCp4m5EUphT4ZHKU3Ft VupyzUAvpbAYLoLeLRDy5Y2ZGrbi2CofICiADgLD0ZZ2tipa6AdBZVKxCySj9R6/+Uf+ 8M3XGSk9xQkov8XEL0PlXN3zdY6R2i+mz4kElqdnEh26AjfBdSb4khtwrKSf2QgJWFSa fs7UWy1gT0U988Ct3W6zTiWBgoi0XDTR/tJcLEWFxiVuuK8bqE/F4nznvKj0C9Zotm+B P5vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682988747; x=1685580747; 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=jcg+ObY0uKE7Plv6+Kj2nIBfbZ7utIjukDPBrr4BYWc=; b=MGwwRqf/0my+MVhkutyrr0gY+5fCLVL1VYSIGbDeT1PaDmE/6GbJcYPH0EgPSymYuy KOHDaBLieEOdQsTyYMQDssrWBDiYGXYD3J/4CWXzVIpoCaKIU2yV6yTEfKQHi7i5z+cm GJKFjgcTnyXfa/DrSSdrkHIiUyb/ZU2zLhIBKY/C5OpI01VnDqjN/pN9sxHMS9Z679XG kJmiQ8/u0hJwLSiwjgTUo+8BX7O8uopao/bYxBq7ec0BHsRnNUVAC5t9DX/AiaMSW4pD VKVWNDgoLbs+v+lS6yw6lirXqkEZldZ8W78VeOuwolIyacrBXJa7a/EAJ8LRgLm2DSab MHSw== X-Gm-Message-State: AC+VfDzYCXKXeFegLglObr/jKlmrJbYSNPyxvNlfg1HqUhyefp32D8A7 gZJzfyKk/sS15XdonaleHrV59CBkBXM= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:908a:598a:7b5a:d40b]) (user=drosen job=sendgmr) by 2002:a05:690c:725:b0:54f:bb71:c7b3 with SMTP id bt5-20020a05690c072500b0054fbb71c7b3mr9297919ywb.9.1682988747604; Mon, 01 May 2023 17:52:27 -0700 (PDT) Date: Mon, 1 May 2023 17:52:17 -0700 In-Reply-To: <20230502005218.3627530-1-drosen@google.com> Mime-Version: 1.0 References: <20230502005218.3627530-1-drosen@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230502005218.3627530-2-drosen@google.com> Subject: [PATCH v2 2/3] selftests/bpf: Test allowing NULL buffer in dynptr slice 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 bpf_dynptr_slice(_rw) no longer requires a buffer for verification. If the buffer is needed, but not present, the function will return NULL. Signed-off-by: Daniel Rosenberg --- tools/testing/selftests/bpf/prog_tests/dynptr.c | 1 + .../selftests/bpf/progs/dynptr_success.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/dynptr.c b/tools/testing/selftests/bpf/prog_tests/dynptr.c index d176c34a7d2e..ac1fcaddcddf 100644 --- a/tools/testing/selftests/bpf/prog_tests/dynptr.c +++ b/tools/testing/selftests/bpf/prog_tests/dynptr.c @@ -20,6 +20,7 @@ static struct { {"test_ringbuf", SETUP_SYSCALL_SLEEP}, {"test_skb_readonly", SETUP_SKB_PROG}, {"test_dynptr_skb_data", SETUP_SKB_PROG}, + {"test_dynptr_skb_no_buff", SETUP_SKB_PROG}, }; static void verify_success(const char *prog_name, enum test_setup_type setup_type) diff --git a/tools/testing/selftests/bpf/progs/dynptr_success.c b/tools/testing/selftests/bpf/progs/dynptr_success.c index b2fa6c47ecc0..16636a29242a 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_success.c +++ b/tools/testing/selftests/bpf/progs/dynptr_success.c @@ -207,3 +207,20 @@ int test_dynptr_skb_data(struct __sk_buff *skb) return 1; } + +SEC("?cgroup_skb/egress") +int test_dynptr_skb_no_buff(struct __sk_buff *skb) +{ + struct bpf_dynptr ptr; + __u64 *data; + + if (bpf_dynptr_from_skb(skb, 0, &ptr)) { + err = 1; + return 1; + } + + /* This may return NULL. SKB may require a buffer */ + data = bpf_dynptr_slice(&ptr, 0, NULL, 1); + + return !!data; +} -- 2.40.1.495.gc816e09b53d-goog