Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3963611pxy; Mon, 26 Apr 2021 14:11:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMotKoVRwDCSCK4ItKurF4GTCgevfGce09jNOMC98M0eyHPSQiQ8HgZr8XURTaYyPHNsjv X-Received: by 2002:a17:906:994c:: with SMTP id zm12mr8029109ejb.404.1619471471496; Mon, 26 Apr 2021 14:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619471471; cv=none; d=google.com; s=arc-20160816; b=g/aEwZgeAQ6bLDwtDO2UnznkanIqzJbjW+mkRqG6wzxGN+n8MgXWlbmRiaAyLCXJ4V Ie9tWCf2ShxlfwIsIvz5tV1Dbo1wvNqbfWxutFlCwMGd2DIN4AALTB+UmCTc4FoOSabE W38xFzjSbsdzjf0TlTNqfMF5h5R/VbuWLvvFX6QywbRmpNmaQbViM1U0mFK8Y7BQ5/oY bU0NVk3QTU2P+oQAE7FROxyY70FnPfoMigrl3M2REQyarVs1NyWZMIt9JU4oi/d/LknV oop8FtJ+BcKyaBsNbUUfkqXzw+x775ERt0xHvDSVF+N2Gay63QgVDhkYux5J7ppvjAYV 9z6g== 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=rZKnL2LhXfhO22PBqGzJHWltIvmcGy2nQuksWcQWSNE=; b=VsldGx4NQ32fQE2eu2K6L3umehXGjdy69xfQlZHQmorbgpy763A4WVVq0vC0q8Kf4d RfE8IFwBcCWcqqV421G3ydkGMLNXxGMkCNUxtWxUXZEStjwS/90pJyVfgg+i3RVoVBDr 6u1KOLfJ6f8BFjw35RQoZ5YD4Y1xdrbfnXRIpKZWI9zMMwPTGcFK1Drj/9FSyrJS/Xow eEqaJPmd4H2L9BFioHn3zm9nGP2tUywiEDljao4Yx5P47htsCIHaN8CfPpWo41vz0Nuw h0fejnceo9gJdQVCG/kpuUWF00c1qinGbD7WglJPV8FGngcAdn4UZZKgaKMRd6hxlP7F agHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Sg66DwQQ; 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 h17si14673733ejx.114.2021.04.26.14.10.47; Mon, 26 Apr 2021 14:11:11 -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=Sg66DwQQ; 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 S238191AbhDZVJx (ORCPT + 99 others); Mon, 26 Apr 2021 17:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238475AbhDZVJq (ORCPT ); Mon, 26 Apr 2021 17:09:46 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5CEC061574 for ; Mon, 26 Apr 2021 14:09:04 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id a11so5069165ioo.0 for ; Mon, 26 Apr 2021 14:09:04 -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=rZKnL2LhXfhO22PBqGzJHWltIvmcGy2nQuksWcQWSNE=; b=Sg66DwQQ/VGsayTE0eTodD5DfEC9bvdXoGVRyHg95e3LTyLn6f8MpGg0OQTSUaQCmw rfGT4OdFzFwcfAhwYIyj0nYQgt+7qXGsvv1yrqM5qgngdqQTqjdtN1xHZk2Ji5VEeLbV 4CAMVmJWFGisFE6VDTy1VGxY1NXMR1QLUMG48= 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=rZKnL2LhXfhO22PBqGzJHWltIvmcGy2nQuksWcQWSNE=; b=psLMazce4+cXTy+E85n4xzTW8XMCeMluP6vbifzdcA1Fu0HH+jzzNqa3QQbHoeKZyk 0fcd28aOsDFBmWMz9NRv0lA7vOl4IHk2MnDRBY8xX5jZxEiPi61RW/vnKsvA/fcE6kP3 U8Ooack/ABaA6feldq5TCfltWFiciz7W3vvu/Zy9XxbjFRKoyshYRuIz9BlV6oIprnJ7 jFKJZdHNUljErLH8D478Xmt/3A9AuMkbpOndUz4C3BwZn91kPKxxuKtsu7vJKl/db/ZE csNhvOfRRkkhtqUzx5ygOImIZ2FXh1Mbozdj3J2PuerrS+AkU0FisK99lfw2gLdGKlEJ i4uA== X-Gm-Message-State: AOAM531F7H6ml3FEkYC00qacZpeb2bKqOqhy8Pp08SubHTHOkJQ1guWZ dtDcjfvddtI4EsgPV1sp/dYWYwi92d60f/zaOCrPOw== X-Received: by 2002:a5d:8188:: with SMTP id u8mr10398975ion.163.1619471343622; Mon, 26 Apr 2021 14:09:03 -0700 (PDT) MIME-Version: 1.0 References: <20210419155243.1632274-1-revest@chromium.org> <20210419155243.1632274-7-revest@chromium.org> In-Reply-To: From: Florent Revest Date: Mon, 26 Apr 2021 23:08:52 +0200 Message-ID: Subject: Re: [PATCH bpf-next v5 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 Mon, Apr 26, 2021 at 6:19 PM Andrii Nakryiko wrote: > > On Mon, Apr 26, 2021 at 3:10 AM Florent Revest wrote: > > > > On Sat, Apr 24, 2021 at 12:38 AM Andrii Nakryiko > > wrote: > > > > > > On Mon, Apr 19, 2021 at 8:52 AM Florent Revest wrote: > > > > > > > > The "positive" part tests all format specifiers when things go well. > > > > > > > > The "negative" part makes sure that incorrect format strings fail at > > > > load time. > > > > > > > > Signed-off-by: Florent Revest > > > > --- > > > > .../selftests/bpf/prog_tests/snprintf.c | 125 ++++++++++++++++++ > > > > .../selftests/bpf/progs/test_snprintf.c | 73 ++++++++++ > > > > .../bpf/progs/test_snprintf_single.c | 20 +++ > > > > 3 files changed, 218 insertions(+) > > > > create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf.c > > > > create mode 100644 tools/testing/selftests/bpf/progs/test_snprintf.c > > > > create mode 100644 tools/testing/selftests/bpf/progs/test_snprintf_single.c > > > > > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c > > > > new file mode 100644 > > > > index 000000000000..a958c22aec75 > > > > --- /dev/null > > > > +++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c > > > > @@ -0,0 +1,125 @@ > > > > +// SPDX-License-Identifier: GPL-2.0 > > > > +/* Copyright (c) 2021 Google LLC. */ > > > > + > > > > +#include > > > > +#include "test_snprintf.skel.h" > > > > +#include "test_snprintf_single.skel.h" > > > > + > > > > +#define EXP_NUM_OUT "-8 9 96 -424242 1337 DABBAD00" > > > > +#define EXP_NUM_RET sizeof(EXP_NUM_OUT) > > > > + > > > > +#define EXP_IP_OUT "127.000.000.001 0000:0000:0000:0000:0000:0000:0000:0001" > > > > +#define EXP_IP_RET sizeof(EXP_IP_OUT) > > > > + > > > > +/* The third specifier, %pB, depends on compiler inlining so don't check it */ > > > > +#define EXP_SYM_OUT "schedule schedule+0x0/" > > > > +#define MIN_SYM_RET sizeof(EXP_SYM_OUT) > > > > + > > > > +/* The third specifier, %p, is a hashed pointer which changes on every reboot */ > > > > +#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " > > > > +#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr") > > > > + > > > > +#define EXP_STR_OUT "str1 longstr" > > > > +#define EXP_STR_RET sizeof(EXP_STR_OUT) > > > > + > > > > +#define EXP_OVER_OUT "%over" > > > > +#define EXP_OVER_RET 10 > > > > + > > > > +#define EXP_PAD_OUT " 4 000" > > > > > > Roughly 50% of the time I get failure for this test case: > > > > > > test_snprintf_positive:FAIL:pad_out unexpected pad_out: actual ' 4 > > > 0000' != expected ' 4 000' > > > > > > Re-running this test case immediately passes. Running again most > > > probably fails. Please take a look. > > > > Do you have more information on how to reproduce this ? > > I spinned up a VM at 87bd9e602 with ./vmtest -s and then run this script: > > > > #!/bin/sh > > for i in `seq 1000` > > do > > ./test_progs -t snprintf > > if [ $? -ne 0 ]; > > then > > echo FAILURE > > exit 1 > > fi > > done > > > > The thousand executions passed. > > > > This is a bit concerning because your unexpected_pad_out seems to have > > an extra '0' so it ends up with strlen(pad_out)=11 but > > sizeof(pad_out)=10. The actual string writing is not really done by > > our helper code but by the snprintf implementation (str and str_size > > are only given to snprintf()) so I'd expect the truncation to work > > well there. I'm a bit puzzled > > I'm puzzled too, have no idea. I also can't repro this with vmtest.sh. > But I can quite reliably reproduce with my local ArchLinux-based qemu > image with different config (see [0] for config itself). So please try > with my config and see if that helps to repro. If not, I'll have to > debug it on my own later. > > [0] https://gist.github.com/anakryiko/4b6ae21680842bdeacca8fa99d378048 I tried that config on the same commit 87bd9e602 (bpf-next/master) with my debian-based qemu image and I still can't reproduce the issue :| If I can be of any help let me know, I'd be happy to help