Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1436455rwl; Wed, 5 Apr 2023 17:43:24 -0700 (PDT) X-Google-Smtp-Source: AKy350bZpF4fblOAEFLmSRQF3Jbu0qQFtGQFQD4eY0ze+FEmYHWV3D4qYutFzr71pUmD+x7G+Qv0 X-Received: by 2002:a17:906:edb3:b0:935:20d8:c3c with SMTP id sa19-20020a170906edb300b0093520d80c3cmr5518864ejb.61.1680741804384; Wed, 05 Apr 2023 17:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680741804; cv=none; d=google.com; s=arc-20160816; b=tx3ZMQ1AbVl8deVheqM7mvCTK8Nc0am6vVL9VKJBDaL49chf5ZOsXtsP2+2M1g1IOp CsCa9CBVbVSQc741RZR0koBR7PV5adelJl0EvZfQWuvJb7HmPR5spcWudHZK224cafwZ Em4w9xUQ6o5rj5Ox6Ap+BN6if55+6sthmjqP4qFCbA0WRJfdii70OGtqPvDeeAFAKZzO 0eKBklGY1AuL1/CkHpWOjWD8hnovGauZThniO1BPr70wiPNZNXaUfDaz5+zw0bmEIK5W oVripxsHeVTFMZ8Qne0QXV5qd1b5cqf/nxh+gT/rUYPuEFO3hmFGOLIWyTHHJBML1gYM 9pHA== 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=x8R/SEDfqF4QrtFeRx/u2abN72cLJ7gQ42FhuO/V5K0=; b=OTEZD21Mlv0J+9gvZukWK8mKdZavnCwg02jIraLrcpV/gBaRIGhQJAbaPH71+nD0Vr s+M47PD+QFBkHCF/Mkq9dILP5wX2y2GZ/PWQG90t6OFWsh7sYxyK5Z08GamIXywq68ef phxklLeWUbcKVRbkanlxZsbwMpmBP6SvM7XIhlmBTX3DIFPowqNOyzaGDy9Dq5mMBg05 F/UlTK2ZgeCZf1qEe1fy0XJTFcGqbTUJIRaDeMlt7gGv3HlxgeWcacFyXoeKiRHrtBDM 9+BLd9zbKg/cqq2iANHQUxmC+IjvCmM4VBwwoOIOROT+Zmv32RN7Ewg6giLmpBHf4S+m l3Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZCqkQYca; 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 9-20020a170906300900b008d89608d4a2si62705ejz.204.2023.04.05.17.42.59; Wed, 05 Apr 2023 17:43:24 -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=ZCqkQYca; 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 S234725AbjDFAlD (ORCPT + 99 others); Wed, 5 Apr 2023 20:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234438AbjDFAkx (ORCPT ); Wed, 5 Apr 2023 20:40:53 -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 842286A6B for ; Wed, 5 Apr 2023 17:40:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-541a39df9f4so378056667b3.20 for ; Wed, 05 Apr 2023 17:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680741644; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=x8R/SEDfqF4QrtFeRx/u2abN72cLJ7gQ42FhuO/V5K0=; b=ZCqkQYcafiAtvRvV3fHcQ/fGM6OE4T8iRV3w1fmZKzRWP42x57FdCTAbn2xhSCkS8D g7/sHITX3xpmjygzz850+hz+7Ofn3Ga29i16IQLKsvuDl/ARP0XS69IBvokQc1B/y7kj EQxUO30KM7p3z4QSgWyx3Y/XtS6cr8O8OiY23SPHPIV7y5SZucR1PBQaJFUk3nVogKey umNa/tl3tx8FFtyMktnCpJp4P21tuOkDjq4R1mI+bABEvC2PCUv4g/L2Ig8H9ne32mrO L7R0SzslBoH8PJ3dFikEKFHx3W+Uf2A5ns3c9zmYpx9t9NykulL6jkR+cNRJLm5KUmhK ofgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680741644; 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=x8R/SEDfqF4QrtFeRx/u2abN72cLJ7gQ42FhuO/V5K0=; b=4UbhLRrbqU5f38V8snhh/XunYQocuFx0EeZDWYck09cO5TD8/Db1xZvJnlalMa6TX0 GAYTXDLG2y7w/eqgQN2mnvSRF+lh5HWCn2ci/adQx++mpHCPExVmc2nTM9DgJ/rd3i3q lgGe2D1gJnTV61iTSMM7L9U8eROq6ygHNiiCScJ2pqO2hVFdHJFrADw4L95sYHVcbOhC 13scNuDrrGZw7H/VJ7uQLc7I0Pj1eZJjBGvwtwlQUEfKYS2RW5SrjtsP6DuLj50n3n4u zQs/tTStj8Smsj1TMPS+WG4QkcH2/36vx9b3/RyX1G8xB7il5uGSwhwFBd/VMCQZ1q+7 mXjg== X-Gm-Message-State: AAQBX9dZakkl5YjmlkE0xlAU+x9UB0A7j0+y2ICEHnFe7psyUER1Lyb1 WMAQ3ys05XaNOK5vGu8R+TvKBss5ves= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:694f:f21b:c6de:aead]) (user=drosen job=sendgmr) by 2002:a25:d4c7:0:b0:b76:126b:5aa1 with SMTP id m190-20020a25d4c7000000b00b76126b5aa1mr715873ybf.8.1680741644750; Wed, 05 Apr 2023 17:40:44 -0700 (PDT) Date: Wed, 5 Apr 2023 17:40:18 -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-4-drosen@google.com> Subject: [PATCH 3/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=-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 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.577.gac1e443424-goog