Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3360558pxb; Wed, 14 Apr 2021 03:49:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEHZtZIYdhhGuMEdnUiyTAiSgUqxTfJuxJFhzNXdb0DjHx70XIDTvqTKqQGyc4Zh1tFGkJ X-Received: by 2002:a17:90a:64c9:: with SMTP id i9mr3048398pjm.213.1618397381181; Wed, 14 Apr 2021 03:49:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618397381; cv=none; d=google.com; s=arc-20160816; b=Tg8ylOm8R2IMqiAU9AOkvB94Sec7a/HrAJmxd38omD0N9asI1CQsdQclSyvFbORqjg 9ZEZWzp6S4EfgAsMAN6ab1ZB3ys5crB4+6gwv/r80MH7JmG8TeBOO1c3bS8XrfoMG7bp 4edLptv/ln4hC0zfQ69CxN6wFJbmWeauEdIqKCR0EPrVCOKA9x6yUnOmtAn0wWs7lF5/ E7bNG3nUM4BdjluPbWzHDkgb2fZH3+0CLrirz3ada9YwcSe2SN6K42ngbgSBZmaBjWZ8 +jo9juZ3h+CreePHDng4KTo5Eymg8nlMwngK9AWTZNjRD0Gi8X3xJ9WyKVOPTS50W3jd 8xkg== 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=PZ33GHUolIcGXlX+GDSqMLORxQxMH8kcsnM1VwmyJE0=; b=J5oR+E4Y1M7H5nEiQTyMSv5jtayzOEmm7sSK7wfolnXrmRKF4GHmOicTzTsgd2ADU3 I189sZcucvA4S9uPWZsmEL7tVJMW+3MPHkD885OVi3imlluxfKMzHAlv9Dl7uBa+oram 5ab2g/av3ln3gw4J6IMfS9YiDuu62ItyzMHaD8RU0dP8NEB5Vf/hmgtQVGYdR6r0yCvR WlF7erQLD5pX9tKD/0+pKpQvzhnf3lE5DtmXvvuKJdLOdiLpnKVIO5yEohsN9aT13/rR 9MdeslN6FXr0BuEYF1iO5vecHoK+7k5jEjsWOpflGcfxbnTvsCS3fENRM222j04QQHuv UQow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pcgTk9q5; 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 s2si25440113pgo.250.2021.04.14.03.49.26; Wed, 14 Apr 2021 03:49:41 -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=pcgTk9q5; 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 S1348030AbhDMXWO (ORCPT + 99 others); Tue, 13 Apr 2021 19:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbhDMXWN (ORCPT ); Tue, 13 Apr 2021 19:22:13 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8AAAC061574; Tue, 13 Apr 2021 16:21:53 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id g38so20017419ybi.12; Tue, 13 Apr 2021 16:21:53 -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=PZ33GHUolIcGXlX+GDSqMLORxQxMH8kcsnM1VwmyJE0=; b=pcgTk9q5Ujx/lOsiwbIz+nnFHh7Cc2rX4wsOgsw0xzSZn4h1GJuxLL/2988hl4WHFQ WQkB37yZpth35nz0w17aBg/RuXqR2PQ24eCmlWh9jIM7V2JFKm8FqGoSzwzRsM3PmqSB joAqGnFP8IGWm4BCFegSH4aznDPRQMntMLO4fiyw6OZvMFGXwoHn5YLV36kinPnaegfh R2LatYCxaemEsWMdQyIlVmx+1zBsADOUh/7q5dg8MkXZKtY/RzUT2alSeRgCrNpohKNz 5LUWF8pbP7ufV5QQ+GbDzZ5YwXGRgGFA2xHa5ijC11jTmG+cs8jinw0PIefBzodjw1i/ STgg== 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=PZ33GHUolIcGXlX+GDSqMLORxQxMH8kcsnM1VwmyJE0=; b=a3XZsVnfbO3pXbwHyw69rApF6Cot6feO2teHK6bEIWGFuN26SvhL+3Qzx1oX3QQicZ LZlLVSHBIfRG/OFG7N6/pN1KQxZT2h1z7llpCVFPI9Zh6b57QnXVSacINHwn2Dbf35cm jwKF1SqK2LJ7c4xbX/ATZO6BTgcSbXu6DbYOscqAk+isgzpcIXQu1uNBiXw+JHcHsf+w UI2Ik9VVaBiOfWMJ3Xe4Jh4HJpBbKtbZR+7uPZyn3Fdtge0ZBhuwOzGuPyeM6eNO26Bl 0CT3pUHj0613GF+0z2YrrpHWfC2WhzqXE77FEcdT9yO/meeI689VEx3IKpeg6njgfSuv ei4w== X-Gm-Message-State: AOAM531E1TQoKlt7kiNMbdYNWWqOUaHc8K14pQzw+g4W2gNztK7lPbst rrVPHa2ln9+N0R7oFQhi1vPCSMGpi0ha6yxGB1Q= X-Received: by 2002:a25:dc46:: with SMTP id y67mr23254940ybe.27.1618356112955; Tue, 13 Apr 2021 16:21:52 -0700 (PDT) MIME-Version: 1.0 References: <20210412153754.235500-1-revest@chromium.org> <20210412153754.235500-7-revest@chromium.org> In-Reply-To: <20210412153754.235500-7-revest@chromium.org> From: Andrii Nakryiko Date: Tue, 13 Apr 2021 16:21:42 -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 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. 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. 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. > .../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 > [...]