Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3545568pxb; Wed, 14 Apr 2021 07:57:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYJ890TP2/GmMTuTkVC562crUr+FfmHOdg8iM1MqOArmnLloqPhV8cSvFH6+rIgBtI6RbX X-Received: by 2002:a63:1d1:: with SMTP id 200mr34476343pgb.375.1618412258432; Wed, 14 Apr 2021 07:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618412258; cv=none; d=google.com; s=arc-20160816; b=ImS1XJ3GPya0NN/ieMK/6mjgKMcj2yAPnlY56eniHTkq3u5EWIpmr6uPe/kW8UFL9J jg1WXeBpQt7sl8Lrf13IKvuwQbGwzE3GcsjOq9/hzKM9myAL91cBjH/IVf5/uQGIufcW OLTCHkaVCbLwaOwpdPcZfr48RTLikg6Gr+I4JHm5u8Xaw4xJYOpLXztHcSeQ1Ebxj0kA yKgDOpaQZ08dJUpIn3MHVUix9Cb++cE6NJQmV/amWhiq+7qbFvZpPhvQWiV9amPJZI8Q 9ingjKlpBcbvj5EXbDibgK1KGC98+4hNVP+sv/zEbkE+pwxQ7Pfjhszor0PguenEyDqD 9Sjw== 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=bHpie5HpZgHlzw3ULYYgfK8HzQppRmaDIQ+JyFmm3tc=; b=GeWexy5BwgvQCiqWMjO2/ypUi6IuEAzsJmnHcYONnlxKitaM70EuvbH/dQStkY5p+O znTQSdsiru1+29FsPmGeRc7lHp9u9QdSLDKMkJm2DzZIxoyLkt7/9LAaCCI+D5MD5bsC wocvc2SoMOsBlcwHE+1dtW47HrSeilOtjrZRGU1OpEE20eacRQOEHPXBYQS88i0lHqUH h2TDrn1kAHBiID10VZWVfDn/CZtlqZRCicpU7z2+QWWoCy5uXDVglH5xV1AjEVx7Kg2n IijcG2oE6BulzEM35BW9XnuBSYebejR5WR0lLUQmsiU/hC+e8/b85TQbDp+b10edlzNp cEVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QlOQDTDC; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si7521300pjv.114.2021.04.14.07.57.26; Wed, 14 Apr 2021 07:57:38 -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=@chromium.org header.s=google header.b=QlOQDTDC; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347622AbhDNJV6 (ORCPT + 99 others); Wed, 14 Apr 2021 05:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347494AbhDNJVz (ORCPT ); Wed, 14 Apr 2021 05:21:55 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6795C061574 for ; Wed, 14 Apr 2021 02:21:33 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id c3so10411426ils.5 for ; Wed, 14 Apr 2021 02:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bHpie5HpZgHlzw3ULYYgfK8HzQppRmaDIQ+JyFmm3tc=; b=QlOQDTDC6+TFMXbxL4bxceCqvjswx//Lmdk4CAO1oE//dHahhT8jOfftD/CV4t5y47 HmNr0TY1RLAy9fNL1hzmQsvrCqMB8p0xE7GaT8rIJJPQrxyV33A0L+bPI51NcJE/OuvE uOZNBxO2u/9URtGWy3edZaWD8cqW7AXUapOLY= 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=bHpie5HpZgHlzw3ULYYgfK8HzQppRmaDIQ+JyFmm3tc=; b=QScaiaAWOkYYHrYZm7QAgQBYEjA+/EFeWlLYdd7jZGJDIYH9XZwPuvD6+mHZeqelse QNg33cTRpE7HpuX2zUDZq5Wjmyqs6awE282hr/B/KG4jwKk6Ot0b23cufBgQwUTqFUoX c/992CGizRdWbi0VsI0h8vX7beBK4vRbZkmwQLNd6ApEGGFcPjcPlnBfs3mggnJ7Cdy5 Ioyr+hTuOFUrwFkXgn41seXdo1sLxKmSoku8amySK02FZBHpcIPnjp/gxlqXP0dhBdOO FRYvyQhYNbksqMt8pQ/1kbbnisPnVB1E/Bk4HqRTESimXKGJ23tATJmyGRjkoAj8CCMe WfEg== X-Gm-Message-State: AOAM532GP2LuqUzETy2QTyyOD5JHCG7mPQhftC80j1DOVL0cFHUpDGRA cujD9o5KG4OPrBLZOzTmwTLgU9rhZzrdgokAECwzlw== X-Received: by 2002:a05:6e02:2182:: with SMTP id j2mr32034994ila.89.1618392093374; Wed, 14 Apr 2021 02:21:33 -0700 (PDT) MIME-Version: 1.0 References: <20210412153754.235500-1-revest@chromium.org> <20210412153754.235500-7-revest@chromium.org> In-Reply-To: From: Florent Revest Date: Wed, 14 Apr 2021 11:21:22 +0200 Message-ID: Subject: Re: [PATCH bpf-next v3 6/6] selftests/bpf: Add a series of tests for bpf_snprintf To: Andrii Nakryiko 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 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 > 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 > > > > [...]