Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4754832rwe; Mon, 17 Apr 2023 18:41:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YK87wCxuKf0UR+RS+LO5BJ8ML77H1uhw0H1bEZImhn+Hs1wnTZDLi4W9sIJMPBd97ZhkzS X-Received: by 2002:a05:6a00:80f:b0:633:8cc7:bbd5 with SMTP id m15-20020a056a00080f00b006338cc7bbd5mr19897278pfk.11.1681782113883; Mon, 17 Apr 2023 18:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681782113; cv=none; d=google.com; s=arc-20160816; b=RAyOvLsm/YCETBauAXdLW3XN0YIWc6yEtUbjntT8kfUDwGwSlcMyU/bHVwEJucWUEh BFivmtDZGR8awKVN63iLNV/OdJnTYjwRxfyWisfOpdV5Fwdwmgv6Uhg7pTremYSLHGIg BGcRzZqsO8a4fOKtxYpi20SmUlnc32NVK0GDqdn27QmY0nwdyjWJud8B/0ZeqjhVVTgS KT/QCXS6rA2Lik49DicMB+7QsmxX/sF0yAJ2+gOUkHQ5MgMy6djuDOUC4VnbD44miGVl oluBSYsfllI3WxHbxUQ1VmJOPvn9lI+iGFGNK761zMhokGpT/i8e5hT7R3B6XOnQxooh 7koA== 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=XBLJQNnM/sLgs4vCqBW41kO32Rg1yqnQ90D80Go8URk=; b=SyQ56NCeeKfQ5U43mLDEsGg6669p6sejk30PvvRXi6mu0qxjt4fZ+JFQMayW1HNT2g qS6o4qdCXT3E3hHel7OmpAdR1cGnjwnX5pJvHhP3QGYa8CcuesWsl96GAcRuKbyDclEl w6y7vBZ/WhQsvR+/j0ApBxRJ3eFHCIvbm7B3ClNd50R7m8PDq91JRa49vHc8WHsalo10 RculVy8AB+aOJcaDwjfJb6RDherCUnBYgMD7BtCHwoqphdA1n/8hrmcVKT+e7WeWRzuq MDgmNc7Gi4cBMZN4//8qSxRMd4XZOCZvUlTF3Ye5DHoGsUsNWesYQDfesLV/NCp5Z7TK kQnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=SnlbZJLk; 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 q19-20020aa78433000000b0063724ddd779si12827566pfn.313.2023.04.17.18.41.40; Mon, 17 Apr 2023 18:41:53 -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=SnlbZJLk; 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 S230282AbjDRBlS (ORCPT + 99 others); Mon, 17 Apr 2023 21:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjDRBlO (ORCPT ); Mon, 17 Apr 2023 21:41:14 -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 880525FD6 for ; Mon, 17 Apr 2023 18:40:58 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54fba72c1adso123374547b3.18 for ; Mon, 17 Apr 2023 18:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681782058; x=1684374058; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XBLJQNnM/sLgs4vCqBW41kO32Rg1yqnQ90D80Go8URk=; b=SnlbZJLk5Z7OPvXPJ7Etlra3omvGygVLH4yu2u9bDq4nCNczqjAQAtQj22wZ5lGEym a2kgjgQG7BqI5HdR0cpPUsEdGAS9YmKkxAht+4KyhF01JzBn+Q5S7f6M6omvM0kkv6X/ evFfdOnXQGFj9+0aeZ9WMkNy0KSNFXRwAthNf6y5bZ8rWO/w27CqQ5dQ154gW44ArDBX LVcYLjt6nZT7hh2nhtXt7Y7pRN6WJB/9+wNxQ55m08D8GmFVYpj4xvYPc2V9ZA197fka hn+T6Z4cpwohIn0+D00N0XUIWGvmcKaMk9jEbjb1w7J1OC1OpxepDIj+esRwnqQA0EyG F+LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681782058; x=1684374058; 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=XBLJQNnM/sLgs4vCqBW41kO32Rg1yqnQ90D80Go8URk=; b=dJJqq4X4wvy4rB4HIG2SRtmdpe7d5mhz+102Rv5ah/eK1fhRO6glQQwB2U8mp/u9xZ qjPgtwLKKsQGd77dXE7tjdRGcCljw05bddL8Cy5oEzhTdmDLfYV1wBqpfHECkFxTf82s zWhtCpoMjuZej5j/lVfd6BzFI/xtYukuuxQVwd9O0wxxgTOm9C12GDvK6wat+56Ee7J9 0Rh4de3FlVeUVxth4UgFXyFPIiAoLKb+Id8g7MmTwL7SnSO3XNUxwf83raFtIYzBkwDI HE853vJySjRvISHLKMHhphq+mfImzJliLueNjldW6LJ5KXqJPn6RrByjdzx7hAYMuBN1 FleQ== X-Gm-Message-State: AAQBX9eDaqiSZa3JUlKdffZi5xlwiZ+yzpWB3yl8ucTOw5DoL/wXKyYw mvwcz7HBWT7QqosKqhQGoIW4LCAFmsk= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:e67a:98b0:942d:86aa]) (user=drosen job=sendgmr) by 2002:a25:d7d3:0:b0:b6d:80ab:8bb6 with SMTP id o202-20020a25d7d3000000b00b6d80ab8bb6mr11010336ybg.1.1681782057858; Mon, 17 Apr 2023 18:40:57 -0700 (PDT) Date: Mon, 17 Apr 2023 18:40:03 -0700 In-Reply-To: <20230418014037.2412394-1-drosen@google.com> Mime-Version: 1.0 References: <20230418014037.2412394-1-drosen@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418014037.2412394-4-drosen@google.com> Subject: [RFC PATCH v3 03/37] selftests/bpf: Test allowing NULL buffer in dynptr slice From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, 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 , 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=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 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 --- .../testing/selftests/bpf/prog_tests/dynptr.c | 1 + .../selftests/bpf/progs/dynptr_success.c | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/dynptr.c b/tools/testing/selftests/bpf/prog_tests/dynptr.c index d176c34a7d2e..db22cad32657 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_nobuff", 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..a059ed8d4590 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_success.c +++ b/tools/testing/selftests/bpf/progs/dynptr_success.c @@ -207,3 +207,24 @@ 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 should return NULL. SKB may require a buffer */ + data = bpf_dynptr_slice(&ptr, 0, NULL, 1); + if (data) { + err = 2; + return 1; + } + + return 1; +} -- 2.40.0.634.g4ca3ef3211-goog