Received: by 2002:ac8:6d01:0:b0:423:7e07:f8e4 with SMTP id o1csp6919009qtt; Mon, 18 Dec 2023 10:14:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiHprE7ot0P8l+/uLjKiSWAm9pGcCAv1HQUfsTviMCZQHeV5KEnUp8yL3r9qgi6qugTEB+ X-Received: by 2002:a50:c94d:0:b0:54c:c68e:95a7 with SMTP id p13-20020a50c94d000000b0054cc68e95a7mr4867103edh.52.1702923270056; Mon, 18 Dec 2023 10:14:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702923270; cv=none; d=google.com; s=arc-20160816; b=CdwFcjJumYOhqMlkX8ldr0g+RQxmX/nZAnBBWc29e7EeWtu84n5bKuHlG4rwsqK1bW nXt8i4iiyF4me/XkFNhH4SuC8WBlSFjdCXyzwmfMI7DqwlJ2hA4FRFTYRVr9+tqSTTPU 5MYF1wVeEbPrF1PFBLr9LRL4L2PTa0AF0/jiYDn9/5JI3w5BrlTbSIBba6dcag6nVgVG Rou8bizoboT5bb+I8+w6QHzb2cHgJjqnfMFW5Klt03CQKRwNTul/hNTBdUTwduFhxUxQ +Tkqu6Oi+/6VmL3abcbdu8mHkJqK9zCoNiL4f8RoSQVFlecq8AfLhQBPk6xqoRBOUdBQ Ix+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=AXdqNZYmXLzUeBYg/YluJviWJ+yD19wV70WwK0p1fG8=; fh=mYCmn9fAxaNQc2Z7axU9+nh8Gu+lERrJPnuNECRO5bY=; b=z4595ED3x9rg1x9XOrSbH1VijlTWVI5VZVreGvoQkehH5UcpFpgzB10lWvLyJEEgYC s2YN0srfNARIPhY+szwsSCohc2y8qBXWp6vqhthWZIIG00NqISYn3rFwHDQ+cTIuDIdl 66Fkbjh1kmwBgaUh1OgarEBrV7Xb8K9xe987xBMvGxbFx/VejVho9U/thFIWI9n83PVL qFJJbLKhdn0t1BI0+qkMhFkDlriquXL5dlaiu1dK+BGM/8qEe+vYY0FRS5uAXP8MFO0f JDih7jNThAzB8TY34GteHVQbYwZ41ywr+nrjJpMUMZ95pqZMQ4IIu89CYGvzDW0x/pWu +4mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m8bYzy65; spf=pass (google.com: domain of linux-kernel+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id df1-20020a05640230a100b0055386ca9e0bsi29202edb.286.2023.12.18.10.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 10:14:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m8bYzy65; spf=pass (google.com: domain of linux-kernel+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C2BD71F25287 for ; Mon, 18 Dec 2023 18:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 111DF7146C; Mon, 18 Dec 2023 18:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m8bYzy65" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C58E65D74A; Mon, 18 Dec 2023 18:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5522ba3f94aso4147831a12.1; Mon, 18 Dec 2023 10:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702922599; x=1703527399; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AXdqNZYmXLzUeBYg/YluJviWJ+yD19wV70WwK0p1fG8=; b=m8bYzy65HtGMtq60Kairil4zTZJqOI1bdOnM4SQm9tBlMJ07d3PFJ6PM7qT7xkg4dr +X2OTC8Z3W2oW4Gq0Ig0DOe2uaJgc8PMtG2tfcgxBlCKVZ7dOjEax7g1dIbxUB61SHqS pt+ZXobeWvAoTNiruzksK8tb0x3wTb8x18RRydKWw1TzZd+fUo/SPcP9nqJWtmyMAada p+WCxoB3B83DLg4Da4QXN7c9Eyb2N+szZL70eNg0AUtih3FbQWczEVA20cHKQxZQDx88 fIH0KgIA6HM5bBY8rcPgSxzClRNCKw73WoT8X3J9NMuruHtRRrdcByWwD2h6testpLC4 EFyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702922599; x=1703527399; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AXdqNZYmXLzUeBYg/YluJviWJ+yD19wV70WwK0p1fG8=; b=uaii+gHShPY+SHwYo2ZA5EGUUI/qTGzrot45I4YEYvyCc3x1/TnjjTOtDCAEPIRvym 3gltrXeAShjdAq9rgWh7gHrNh5zJfrVm5o8BFAdGt0oU59nCCHiMePAVQHmV4my9rOry OZv1kTYOWR1WxKrjKJuBPhEZg9RZr7ISFKCHK3losVlonBPcHSLemkDBupP/dtYI4Th5 5A0+MhAyRjrdySuSKVSLrVoyWzJQj3cE5ZEGVH2ykwkDc+n1o/IKjSCehGx+b3mcdB7B kbxDWFleAqvOiE5J4QGRrEHaF7W44Jwig6Fotx9Sz0fs9kzgF5pWfMmiCU7Qdof8zXhX NIug== X-Gm-Message-State: AOJu0Yx0kCzpBv0wZ9czG5cNCElcHqgpvj8xPb03MQcO1km/MbrTGwo0 Web63YM6NR2SSte0MLYBcs5qWxJy4N3tzf81l50= X-Received: by 2002:a17:906:c14a:b0:a23:5780:6305 with SMTP id dp10-20020a170906c14a00b00a2357806305mr726692ejc.216.1702922598760; Mon, 18 Dec 2023 10:03:18 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231217131716.830290-1-menglong8.dong@gmail.com> <20231217131716.830290-4-menglong8.dong@gmail.com> In-Reply-To: <20231217131716.830290-4-menglong8.dong@gmail.com> From: Andrii Nakryiko Date: Mon, 18 Dec 2023 10:03:06 -0800 Message-ID: Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: add testcase to verifier_bounds.c for JMP_NE To: Menglong Dong Cc: andrii@kernel.org, eddyz87@gmail.com, yonghong.song@linux.dev, alexei.starovoitov@gmail.com, ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Dec 17, 2023 at 5:18=E2=80=AFAM Menglong Dong wrote: > > Add testcase for the logic that the verifier tracks the BPF_JNE for regs. > The assembly function "reg_not_equal()" that we add is exactly converted > from the following case: > > u32 a =3D bpf_get_prandom_u32(); > u64 b =3D 0; > > a %=3D 8; > /* the "a > 0" here will be optimized to "a !=3D 0" */ > if (a > 0) { > /* now the range of a should be [1, 7] */ > bpf_skb_store_bytes(skb, 0, &b, a, 0); > } > > Signed-off-by: Menglong Dong > --- > .../selftests/bpf/progs/verifier_bounds.c | 27 +++++++++++++++++++ > 1 file changed, 27 insertions(+) > LGTM, but please add a comment that we rely on bpf_skb_store_byte's 4th argument being defined as ARG_CONST_SIZE, so zero is not allowed. And that r4 =3D=3D 0 check is providing us this exclusion of zero from initial [0, 7] range. > diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/= testing/selftests/bpf/progs/verifier_bounds.c > index ec430b71730b..3fe2ce2b3f21 100644 > --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c > +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c > @@ -1075,4 +1075,31 @@ l0_%=3D: r0 =3D 0; = \ > : __clobber_all); > } > > +SEC("tc") > +__description("bounds check with JMP_NE for reg edge") > +__success __retval(0) > +__naked void reg_not_equal(void) technically, you are testing `r4 =3D=3D 0` :) so maybe call the test reg_equal_const or something. And then add similar test where you actually have `r4 !=3D 0`, called req_no_equal_const? > +{ > + asm volatile (" \ > + r6 =3D r1; \ > + r1 =3D 0; \ > + *(u64*)(r10 - 8) =3D r1; \ > + call %[bpf_get_prandom_u32]; \ > + r4 =3D r0; \ > + r4 &=3D 7; \ > + if r4 =3D=3D 0 goto l0_%=3D; \ > + r1 =3D r6; \ > + r2 =3D 0; \ > + r3 =3D r10; \ > + r3 +=3D -8; \ > + r5 =3D 0; \ > + call %[bpf_skb_store_bytes]; \ > +l0_%=3D: r0 =3D 0; \ > + exit; \ > +" : > + : __imm(bpf_get_prandom_u32), > + __imm(bpf_skb_store_bytes) > + : __clobber_all); > +} > + > char _license[] SEC("license") =3D "GPL"; > -- > 2.39.2 >