Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6157119rwr; Mon, 1 May 2023 17:54:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zQ4OVFbzOwNaMdQU7DhaP8YhCcHcFxe1O92+Zmv9eO7ZU6y/bUqyJr52FHjWMpEODXdih X-Received: by 2002:a17:903:1246:b0:19a:bbd0:c5cc with SMTP id u6-20020a170903124600b0019abbd0c5ccmr20778693plh.60.1682988849355; Mon, 01 May 2023 17:54:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682988849; cv=none; d=google.com; s=arc-20160816; b=R2dV5zxA50c8GgdzJCYq/MUA5q4wx+Qf+zu3grNwfSW8BINIJLOPHCP0unj2g6533e yMkrs8l55kV6FwEkAsRwpoMtJvibXPH6GRCWDB0qS2YVdhWjxD8+iPEbcBkqBSzkBD+d HxsCuM/BJknDRpP9WprAwmVQf78lBDVEEaARSixpiI1sCEEjX3IpZTxdJ7kUa9uoz04K BZp4ITjqFQwRyrJ1KsExarbbiuKHuuG0yGbgLUdYmuULlegjkxiMhxoWOR/7A6Igwe9M 73E+B7lzImVK154jgpB7uem/QZXRbBaDfPk8GBrx9MDi3aK2axWnY2Z5/x/UXuZ7yj0Q 1/Ww== 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=rijO/xqtP62+kTHQFbkJP5lful9qOa3cZ4WzW7LFpEs=; b=OK2qn/Tzn5S0/6dXlYzBFMdq2I2Ph2ACZUk1nIUSsdbEvWIPSZRKkwr3IWmtNQzkGL qpFqJcWdzAMkYUWaHDUr0ZS53b2xV3yQPTVaYEGwpTeqfy64VhociKZx15JJ9hh1GZua 8PnmFoNUYKAz+kcEHlVVR1mV68sNxr40lF7lCsNysOAWUUu4B4u+4wddfeCBxbqezxKF QqgnQUpk4RAtd+fQVlXXijP8UaPP4gj9Zvr4pni9m+KsgtswX8n1u6p0nCz7dd5bXe2D OXo6KH9IefzRIbQbTSb9GYgDOTY3E5XqiqG8AK40gHoFdyuG0F7sOeinCZ7hbeExjsbi x/Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=EjKbiPmK; 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 d22-20020a170902aa9600b001a6709378c0si27942493plr.333.2023.05.01.17.53.55; Mon, 01 May 2023 17:54:09 -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=EjKbiPmK; 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 S232803AbjEBAwg (ORCPT + 99 others); Mon, 1 May 2023 20:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbjEBAwb (ORCPT ); Mon, 1 May 2023 20:52:31 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60E0A30EA for ; Mon, 1 May 2023 17:52:30 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a75194eebso3844555276.1 for ; Mon, 01 May 2023 17:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682988749; x=1685580749; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rijO/xqtP62+kTHQFbkJP5lful9qOa3cZ4WzW7LFpEs=; b=EjKbiPmKz/D0CLJlw2T3t6DZlK1KGIuvF6NX00rIT6VVlKtCc0ynODJCR4qFM8CBpd Hykblxm7QyCqcgFJEFXv54jnEu+okCN5uYxLn6blk16FIBidZkK+Qtju7YgJ8by+lV2h 3YqiggxPw/S23UQl624JELMifTQDK9dxEqoiNj1yQsc35vOW8NOkn9NL2BpCiSYX+9+B F2mmq2nmNIVKj1/oLAPz8KARJGM47bqMUqXg2VuNfYiIV6nH8U2ECkD9/Axv3+bpikud SIWtGpJRg9mWZbQm9gzDsTz25yhmgaWOInyyn/vtqhHQtqH6Hwel1at4Wy+aLHhY+o7d HAxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682988749; x=1685580749; 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=rijO/xqtP62+kTHQFbkJP5lful9qOa3cZ4WzW7LFpEs=; b=SSqaCEi7juBEArxq8tiUp9d+8K/JC7qPES0VHWXBZ+Y8DX0ManL11utwyfhUs8M90z nKTvkszLsBbUHZiF9NWYCH0HA5Mwjy1kBjyYogeAG41bSK6j7AVcso6m7VI3V/149GMQ i4efO/LpxXr3F8RqJMK6Kko7wYDalnhjihd7RwQS32LLX0e1SaBOO4cf4kvSU77F7K3r 7mBEBF31qq90ng5vAqRURpm9fu6HeGXe1XCH4ED5JHVhO5nqSMIXqnU8bS4agNIPVd18 494Z6p+Z1dTzhV6Ce2GUMKq1ZJhqTo7JibnPNBim2IW4Q6B1k2+TGf2m0TFlOdLAgqHi 4uMw== X-Gm-Message-State: AC+VfDyYL+Ncp6BFBsb0L3iLXkwZLaAPDpJpjqet5fY/lbR/UiTRlzsb iCpzc6lS6hWC0hKztjZW9JceSZ03G3g= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:908a:598a:7b5a:d40b]) (user=drosen job=sendgmr) by 2002:a25:4683:0:b0:b92:1f3c:a212 with SMTP id t125-20020a254683000000b00b921f3ca212mr9414301yba.8.1682988749577; Mon, 01 May 2023 17:52:29 -0700 (PDT) Date: Mon, 1 May 2023 17:52:18 -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-3-drosen@google.com> Subject: [PATCH v2 3/3] selftests/bpf: Check overflow in optional buffer 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=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 ensures we still reject invalid memory accesses in buffers that are marked optional. Signed-off-by: Daniel Rosenberg --- .../testing/selftests/bpf/progs/dynptr_fail.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/dynptr_fail.c b/tools/testing/selftests/bpf/progs/dynptr_fail.c index 759eb5c245cd..ee98f7ce0b0d 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_fail.c +++ b/tools/testing/selftests/bpf/progs/dynptr_fail.c @@ -1378,3 +1378,23 @@ int invalid_slice_rdwr_rdonly(struct __sk_buff *skb) return 0; } + +/* Buffers that are provided must be sufficiently long */ +SEC("?cgroup_skb/egress") +__failure __msg("memory, len pair leads to invalid memory access") +int test_dynptr_skb_small_buff(struct __sk_buff *skb) +{ + struct bpf_dynptr ptr; + char buffer[8] = {}; + __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, buffer, 9); + + return !!data; +} -- 2.40.1.495.gc816e09b53d-goog