Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1209586rwr; Wed, 3 May 2023 11:35:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bz4opCTelncYixxpGg1pbuHljY5iIyCitodn7StHRaJmVIss/Jao2qKREk2Sb+vGwv5zN X-Received: by 2002:a17:902:cecd:b0:1a6:dc1f:6230 with SMTP id d13-20020a170902cecd00b001a6dc1f6230mr788598plg.55.1683138915041; Wed, 03 May 2023 11:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683138915; cv=none; d=google.com; s=arc-20160816; b=OZH84juFssVzoMYQcVV3FjiFPbkfx7sTdG+gHhp6FhsN4GA/y1hweIDVoOF+RUP5cm w+ReF0PXLlSo3Xx924ZS48lIIGldNnmveU+uLQfGMMJKNMMgWj1Tmx9CCbt+V0qr/Jmg zNGi9zzSDxyyn6hgjkrmEgoGACnQEYQr8LTVhPFog9lRYgqGxvC8Ck1fWrLwiQ2YU7cS y0BWMyjpjVKi7R+giAqUEHsGfh692d2bGkwLTTQIXwJG71GpQIZzh/FeckT8NhdSVQWP /GlEYC3n7Xkmt8dbKoMdLIqUMITvLIrHzQJQpyI75POGEIY657q7W/co1g6PZMcIH34j RXUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xyL6ErGxtGK4gbcrXbY7+L3d/vbQkgK7HxYu2bCcYGY=; b=N7mk5bxfFHTWyt3Os0LzP1yfxvH+iq1dTneamIOw9Yfvbz2DnRLEgvn3pAVJeQ44JX yCPunDgyJGEvkB6fY7O8cpjad+og1ai3sHnRbYkp2UI46g26I8XBG/Z/1SVIPgXfJXP+ hyvRO8W+oyftGkZ9MqUGeX8uyJvVCZykP2Wn16ZRKYa8LWrnCl0gnY1Dg7fZXbTjvAXc BWP3Wdrw4sNZmVlox7mU3XV/2jRgreWdtZ4rwq60Hd50T4XriIS1M+GAUYzGbppU4NkU SI36XHqdxuIjfSUc7rK2hxwEMa1rLjUAOu4gdKuEZTSyifAVEL50eXmfEKzllsAmEB+O D7Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Hyfqv2D/"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a170902ce0b00b001a6d4eab493si34437240plg.26.2023.05.03.11.35.02; Wed, 03 May 2023 11:35:15 -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=@gmail.com header.s=20221208 header.b="Hyfqv2D/"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbjECSfA (ORCPT + 99 others); Wed, 3 May 2023 14:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbjECSew (ORCPT ); Wed, 3 May 2023 14:34:52 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E155583C5; Wed, 3 May 2023 11:34:31 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-94a342f7c4cso1063902666b.0; Wed, 03 May 2023 11:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683138870; x=1685730870; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xyL6ErGxtGK4gbcrXbY7+L3d/vbQkgK7HxYu2bCcYGY=; b=Hyfqv2D/Vmdm2qFvoJ0/03cG9FwKp7F/gSIeqr4sgYcvejyBB87r94IUaNBhST7yVE npRmmDaVs6LIVUbsUBG9t7M/UqpLPq+eftmvOBtGnYdRyHTXJjwJ6zesj+es8PaF5XHU wQyE6sZfQ7VrBdLweKkk5Klq17iffIxZntoTmFywSrNt3Svyed2Eo8eiPNrba4aDEOPV fPhImEWYSmvpS/IeAHtnG66QU3GSEUBLm9uq0DfOdC4NwBIDciwxNCEznXKkCIQQXj9X vsupHh8Lu1hhe2h13Z4vKrlmL1PwA+QCTlrB+U2QRdVT/mGKSnD03QdOChUCv6figHdh QUOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683138870; x=1685730870; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xyL6ErGxtGK4gbcrXbY7+L3d/vbQkgK7HxYu2bCcYGY=; b=Fx7aXC0okIDAFpEsl9oq03lQgVGRbZFF9iPzu+ARlyXCpBNn0GCsDYe8+cPJ8hl8pZ W5bhOymR15V62UWzJTbTDe1204jBG+dOay0u9FfA148Av9l5/DMfFdli63nULRdqxftR TiIiTz1uK68WW2TmaPbH+pn5qcO7juBRTaXUED0bd19IWFSiCZlJcwqpRn1vQzRQCuHK 3MLabC1o4Zoa56W3Yj88mVhMTBXqtNuw3rXKEnycOvjPzzesWPePEX2+7pu0R2D5Xy2q ZUkFE60bhIZGDWBaNAqHBcaa3dmIHLVXR0GL4SvtvtynxqGEgEVvkLIDiW/fFvPDUfkj btKA== X-Gm-Message-State: AC+VfDyEkAo5O04FlTkjb4map6LSVND7FCSdHjp+zXmU3YCCqQRC1KuR 7cQvMZa1IK+1wTzKyum9KF+w+W3w6TisLQWKznZMC9M/ X-Received: by 2002:a17:907:9705:b0:94e:1764:b0b5 with SMTP id jg5-20020a170907970500b0094e1764b0b5mr4372303ejc.69.1683138870113; Wed, 03 May 2023 11:34:30 -0700 (PDT) MIME-Version: 1.0 References: <20230406004018.1439952-1-drosen@google.com> <20230406004018.1439952-3-drosen@google.com> In-Reply-To: From: Andrii Nakryiko Date: Wed, 3 May 2023 11:34:17 -0700 Message-ID: Subject: Re: [PATCH 2/3] bpf: Allow NULL buffers in bpf_dynptr_slice(_rw) To: Daniel Rosenberg Cc: bpf@vger.kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Fri, Apr 28, 2023 at 6:58=E2=80=AFPM Daniel Rosenberg wrote: > > On Thu, Apr 6, 2023 at 2:09=E2=80=AFPM Andrii Nakryiko > wrote: > > > > would this work correctly if someone passes a non-null buffer with too > > small size? Can you please add a test for this use case. > > > Working on a test case for this, but the test case I wrote fails > without my patches. > I'm just declaring a buffer of size 9 on the stack, and then passing > in bpf_dynptr_slice that buffer, and size 10. That's passing the > verifier just fine. In fact, it loads successfully up to size 16. I'm > guessing that's adjusting for alignment? Still feels very strange. Is > that expected behavior? pointer to stack is trickier (verifier will just mark part of stack as overwritten with random data), it's best to use map value pointer as a source of buffer. So try using ARRAY map with small value_size, do lookup_elem, check for NULL, and pass non-NULL pointer as a buffer.