Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp360585pxb; Wed, 14 Apr 2021 17:50:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygUvRtFWg/enpEfrC5DpSgwamEKiv2e2lx8KjCAJ98m4lUqeHanEFqNz9aEX+cN83GfSJv X-Received: by 2002:aa7:8389:0:b029:209:da1c:17b5 with SMTP id u9-20020aa783890000b0290209da1c17b5mr727774pfm.29.1618447808037; Wed, 14 Apr 2021 17:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447808; cv=none; d=google.com; s=arc-20160816; b=YbUUl1zKZP3h83ME2ka78ntwHqinUzUWJ5bi9Lf8D1WehV308HK7rynaJQ4tWqUjFA 4A8RqEtEnw8jI3gHqrgYNIPiwqGeByvzLmbNXBoXUglDSwpYuY7yqVR+bHXR/J1F0CKP ywNDrPpGOcAYgt8kEM07WmqCtDlDSBGugjT2koDMXg+bVQOp8y7AJyYxV2N6cphfME02 YT0tJfffbeVU5VL0bH7XqwcSqzqcS2DJPQwqMd2zg9BPGs2RYZI0UNElT+Fu2NfSN6Ez EG3vveQlgL6Fx8m3nKpKj/5jveNVONwQmXHGUHmpvjhaB1JarS/AD43EMzci07a7N1Ta +seg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+7hm/hYBN74dkMimz7YGlCgiS2CU1XMz0exGEgDhOfU=; b=WcjKXfIFm85qK/Ww75v9GHdh3SClBrrMEvf/zoAeXXkqLFJTO0O9v29Lz6Uggg6KEA FOW7+qLhcq5li/wKll/7VB4wYb0Sn4fVZNR6C+L4mdItzYTxqW/v30oY0hxgKLbdN2O3 2R6tfmywxjV4Vb466z0A8fvbQKBXJMfpI7/H7atEXxW51A6TZMH7/XzU4o92CMHAC/iH RlqwDhO8/yxM2JRHVc62apsrP8BOnz4TJMYrebuz509LypMl4axcbFutURO85l+XGn4W 8VQVmFRsNvv7KcNAo6zVB0rDf5n9ZmEOfsBLnnLV7JnivM9BqkMOt69jpVxYUr8pTFKy 0Dkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="CsnPgB/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si1332287ply.115.2021.04.14.17.49.56; Wed, 14 Apr 2021 17:50:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="CsnPgB/7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231545AbhDNWQe (ORCPT + 99 others); Wed, 14 Apr 2021 18:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhDNWQd (ORCPT ); Wed, 14 Apr 2021 18:16:33 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5DEC061574; Wed, 14 Apr 2021 15:16:11 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id o10so23861328ybb.10; Wed, 14 Apr 2021 15:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+7hm/hYBN74dkMimz7YGlCgiS2CU1XMz0exGEgDhOfU=; b=CsnPgB/7PlYNZZdvMiEuh3vNGYmCMqFHW32rXGZCOO/xsM8xv0E3JcRjSCmSjPTOkU zOy+thUKgInCpwcCmNtElPl3KXNxv0SNzOiQhLe5LQry5othokMhBO+BxnQVehSf3HIM 4lAXTziwdnWAil3zOBaRLHIssWMQV3gyIxSSjV6KWGQJ+iQ0INlXEp6Et2uosNcUEvuI gCy35dOjw9kvkRv/bDYOR1xrjVBpfUBi4kXsuyncm7KWP1So0uBB5H7iXsexGJ5t9RHx Ap3tyCUb6Gd07eu9f3FzXM2gYubz+DOQLTmbFRAH2bM4ZmOIUKUUf2W4KsxUhSlHTPlS 3jsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+7hm/hYBN74dkMimz7YGlCgiS2CU1XMz0exGEgDhOfU=; b=FJ8CZaBV/aZhPvTn9IWNGvVwmBqv9rVY87KU+9ubolU422f+7toZjPViXq9M65xUOL k7c3ytZzez/umaV68Y1sRbCNXDfeEDofTTTEBjGRR5kECYwJCch5bNuKczTovbW1yWDQ QoGdCVsD5FBb1ThlbS0W2Pkv0WlpmvimEkmyMKowhlbboZmm2i/hnkXCdX45q/PNCkyN UzfrTIOzToRk1WECghx/mv38AdXbe70nBUt+Iyb9V9bwmskbJgeCmrgmf8b7+B4JAF8e qTZIpobX7P/0+RUlOtcuITmxLTUU4FdTDRQDxz2t+7vN2dbvXzbpGOcB/+liRhpyr4Jz R3UQ== X-Gm-Message-State: AOAM5326WK/8uboJUrTZrQFGAHQUyJCGwaPd7k/88LWRH9c+DF5oWIL0 1+2Mme8UYlEn09xo5ByHls2IOo+2+Jar3UwaCgY= X-Received: by 2002:a25:850c:: with SMTP id w12mr232751ybk.347.1618438570895; Wed, 14 Apr 2021 15:16:10 -0700 (PDT) MIME-Version: 1.0 References: <20210412153754.235500-1-revest@chromium.org> <20210412153754.235500-7-revest@chromium.org> In-Reply-To: From: Andrii Nakryiko Date: Wed, 14 Apr 2021 15:16:00 -0700 Message-ID: Subject: Re: [PATCH bpf-next v3 6/6] selftests/bpf: Add a series of tests for bpf_snprintf To: Florent Revest Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , KP Singh , Brendan Jackman , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 14, 2021 at 2:21 AM Florent Revest wrote: > > On Wed, Apr 14, 2021 at 1:21 AM Andrii Nakryiko > wrote: > > > > On Mon, Apr 12, 2021 at 8:38 AM Florent Revest wrote: > > > > > > This exercises most of the format specifiers. > > > > > > Signed-off-by: Florent Revest > > > Acked-by: Andrii Nakryiko > > > --- > > > > As I mentioned on another patch, we probably need negative tests even > > more than positive ones. > > Agreed. > > > I think an easy and nice way to do this is to have a separate BPF > > skeleton where fmt string and arguments are provided through read-only > > global variables, so that user-space can re-use the same BPF skeleton > > to simulate multiple cases. BPF program itself would just call > > bpf_snprintf() and store the returned result. > > Ah, great idea! I was thinking of having one skeleton for each but it > would be a bit much indeed. > > Because the format string needs to be in a read only map though, I > hope it can be modified from userspace before loading. I'll try it out > and see :) if it doesn't work I'll just use more skeletons You need read-only variables (const volatile my_type). Their contents are statically verified by BPF verifier, yet user-space can pre-setup it at runtime. > > > Whether we need to validate the verifier log is up to debate (though > > it's not that hard to do by overriding libbpf_print_fn() callback), > > I'd be ok at least knowing that some bad format strings are rejected > > and don't crash the kernel. > > Alright :) > > > > > > .../selftests/bpf/prog_tests/snprintf.c | 81 +++++++++++++++++++ > > > .../selftests/bpf/progs/test_snprintf.c | 74 +++++++++++++++++ > > > 2 files changed, 155 insertions(+) > > > create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf.c > > > create mode 100644 tools/testing/selftests/bpf/progs/test_snprintf.c > > > > > > > [...]