Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3495102pxy; Mon, 26 Apr 2021 03:11:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZPRRMwA1td8uHAYB4UqyeDEMLSUYUUuDYTYhhQ5MKiWaXAOSG0zCERU4/Tjk2ytfKJcJ1 X-Received: by 2002:a17:906:1e49:: with SMTP id i9mr17686384ejj.536.1619431904919; Mon, 26 Apr 2021 03:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619431904; cv=none; d=google.com; s=arc-20160816; b=iuzkP7aTMLtsVvVU2chBJe71uvqEzB07MhnNSTz5M6Eg7cr2i5faKzvMgXfSbt4yy/ 3DICfEuQ0taH5uIkJIGafCQ+2uMh93nor4TdYQvO0IpbhUnQKv0PLzdYf/p5ASsKr2xD poCkjas5tcoys7qFiX9RCVaY+uFemYellj1dLziBjXTHCodmj/HXFH4JqcemjmT+6lVO 6vxEIWfvsPXc7zDhE2cQOAgsn5xBYePRnSB9uGy3sqjULAUNgKLi+rDfqs9Dyflbe1c6 Bc3imEE+aGOwdw9i9IPT7QvYhVLSWm1CFWj6Mw4KiF5kuB1JMshn8ABOS8LDIS1ADmre xBqA== 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=+fN1CnJTyw4SnuzW6DBA9Vu0o0I1yNjEi0kq9D/Z/LQ=; b=cBKsMYg8CZ3+/uFR4yYHWXz2i/jFScgMm3eMiqFXHhb+xod4Hc25NGPj3LhXgv0ckn VZbtkJOirqrTeWF+ihLBHMsA5lPNEYxSMEJhXNwyzH+SZOg7qO+JOILFWWTBrcOtYwYt T3bd3/2IpJtrOyy8/MxIzkKXvi3bsEWJkaIheJewFKSTeO+g5e7f0VS7u9aakIQzp0iq 9aVUHV2ATOqVgDr5tyl+Us/ktwpOyNhutmjoF9dy2M7mk+JVvgAMs87I2IqRGUTOMrBT ammu/LmwB36HnCc+At0TxEJrsOsEPay0LYN5h5PmHDI8iC9hn0s7wF9T3umkLG+KKN4M LZ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VC5Jbt1m; 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 a42si7637296edf.319.2021.04.26.03.11.21; Mon, 26 Apr 2021 03:11:44 -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=VC5Jbt1m; 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 S232547AbhDZKK7 (ORCPT + 99 others); Mon, 26 Apr 2021 06:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbhDZKK5 (ORCPT ); Mon, 26 Apr 2021 06:10:57 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5A5C061574 for ; Mon, 26 Apr 2021 03:10:16 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id e186so2352913iof.7 for ; Mon, 26 Apr 2021 03:10:16 -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=+fN1CnJTyw4SnuzW6DBA9Vu0o0I1yNjEi0kq9D/Z/LQ=; b=VC5Jbt1mUZhRJa1ZD/9L/LbwQ5aW97mMI1TZ/3Td6ktOlGoYQVNPE7WaGDo/cTgrhG rHXRlzfr2sRQoAkwwC78WuaYeYATWmQLvI/7Yk6UnCohEEtwLG429skjYJI7Fm3yqlO6 AK38rjEuSzLGwA50eHF516Yiu234Il1D7XIys= 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=+fN1CnJTyw4SnuzW6DBA9Vu0o0I1yNjEi0kq9D/Z/LQ=; b=OSURT2otsEX/YKKRe/aBxM3+4wtDxwVytNkhbSqIpcaIE95gld/cG48ULQm2INRGXd fUTzXWbGSvwlc2neKOrYrBCxb3ePzuHYASBaEN7R8vMl0UKJ3KhRiwLFApI6DYTDORXd hd4ZCHV2kBW0Sd0rZhUbwzsVRYkapCFQa1R8Vg4LT3xBk8BDIXa7m+aUthXjiNv3qwaj 9PGlG3g+UUUuo5AxQ8jX48gAx0HquxPsk4XtxJ0nTn6qONQ3n/ICJr1J62mpeXhvPi7B V6y0ybQ4jify4QecNq0s+3zP0I1vzCcvVHtaHHtwjJgynoWGUTlW5sGUY0nZcMsGqWxy wQsQ== X-Gm-Message-State: AOAM532ijFG9fd++GmaIEn4aZ4g5mzEUW+fG0Eaf4F9+6+GTBXf+CaWJ 8JWdTthBAKIPHz4VzwE1aFX0exzbXV1avTDWB2Dv+A== X-Received: by 2002:a05:6602:218a:: with SMTP id b10mr13945010iob.122.1619431815692; Mon, 26 Apr 2021 03:10:15 -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 12:10:04 +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 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