Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp299130rdh; Mon, 18 Dec 2023 21:53:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtApPvORCYzW4Mp+GPCHX8TxOJRKOz+e0SKO+xgxHxD0c7rVWnbp+SAX3B85OlNdKmzCQ/ X-Received: by 2002:a17:906:250b:b0:a23:2c38:6356 with SMTP id i11-20020a170906250b00b00a232c386356mr2070924ejb.30.1702965198040; Mon, 18 Dec 2023 21:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702965198; cv=none; d=google.com; s=arc-20160816; b=L5WMIH6cqc7CHPHSsPp9s7IhVQ4mgbwptcFpAd/x8obZcjDkDSZhzfG2Bbg/KPbdpi dMoW1b8vJVrLWa7dmLpxRXXhqPJw6pq1OzvXAsboPvmIfkHHXchJee7mZ1SDWHrIwx9z +6zcdNdtzCBGYDT0yVfX8QVVHgkbhpq5ORZ7HGsOGYY3f5TzwAo/pa8DD0KqB4lzlJsQ Nuc1ZXR/pM2rg+H148FeM7OJ4X/0ynRtfLLgOw/LflnWEhl1Z5zFruLn/cIDcsebMtme sHZhlb02QMNcWJIWGn3Wi/hZmsMB5uIxWMMo2lgQ9yTIj9g4GA+025xIwL2Uz7w/g3oD GaEQ== 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=4gaURpT7NV/Brr6JBDJIIcjGXCm84WBBQp9TOCcnomg=; fh=mYCmn9fAxaNQc2Z7axU9+nh8Gu+lERrJPnuNECRO5bY=; b=vpG/cilh7doKO2D1wzZtpcHKxBVsRN9jrlqptshj+97zuPyOoRVvocJn+zDuFPMBWy vUG+opJe21ZPoctv8D4IvNQfQtVqQg10/SD+4EBU3q3BmAHiFTCJGuk0pUEpvoKY6Zdc MYOtpL2t9dhxo+zfOsRG5Zu7zUhq3EU8ZFjhD6qRKbVAVsRK3KFk0oj0FV+PcoUq13Gm FC8mGezndlTaxIj2NwkTeEYcJv09JNRSRE0blqypX+7P7/OaaYVkG3Vye473Mj+COfx6 erdtqDQS7VrJ5ZIIrCnJi2nKLqtu92xGkNTXWsS6RZYcO3H6sWdFSVM0bUT0X3CVDBSZ w/8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R0HSxaQe; spf=pass (google.com: domain of linux-kernel+bounces-4723-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4723-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o25-20020a17090611d900b00a23569f1451si107005eja.631.2023.12.18.21.53.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 21:53:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4723-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=R0HSxaQe; spf=pass (google.com: domain of linux-kernel+bounces-4723-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4723-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 6DFFD1F23EB1 for ; Tue, 19 Dec 2023 05:53:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A79C746C; Tue, 19 Dec 2023 05:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R0HSxaQe" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 F3E008829; Tue, 19 Dec 2023 05:53:06 +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-f47.google.com with SMTP id 4fb4d7f45d1cf-55193d5e8cdso4673279a12.1; Mon, 18 Dec 2023 21:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702965185; x=1703569985; 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=4gaURpT7NV/Brr6JBDJIIcjGXCm84WBBQp9TOCcnomg=; b=R0HSxaQeOVBwQqvyO3Ir3TOr+NWAF4DZixYb3ojZH67EMc1rqY98FTh0gjrLiQ1bwW +OUKCz4ChwlgNlBnwgO1ZrVfvgueO5Gq3BpzS0dq3+NO28FJsd/jj1GDOidb1qJrfPyy eu8qAzvvJThSq7xoxQR52tIaEY+zWXOb+UPyQU+Y71xfBnLepP8rHM538sRSXNbPwiip LSAAisGlUxdoWZxSBK7DOBH9SncsXE0TawYLBZhyZqC7PnQa/DmbJK4G9L+oI81ZIE6U mIeEL4tYvegTHQuiaJRiv33YzEPbYOYbxmP4HSWypJC+6JKHr5Fv2xcdtJmnWjA+RLr+ HLug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702965185; x=1703569985; 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=4gaURpT7NV/Brr6JBDJIIcjGXCm84WBBQp9TOCcnomg=; b=bl+pWbrCbwNsIDOUQ8TAo2mq5QZqB5GignkZ5G0veWGEeTJ3y3d4zsZvMuwbtQEJIe d1Pg6NvbOpivvqdGvEEM0VAyhkIaJ/8dF3mGM9cywIwYa8guIejaDpBvpi9PZ1VIhpn8 Xm06li5nAnjaOEwDqswe4dnxOvEsp//H4nfObSXZJI5ofdjO/Gmv46ZDVFLkiQ9rSE/M AjbKXk999YT7rYMn7DGnMKgOix1dpzgLl6AaZUCWFMlnvwIJgoH5Ab88HJ8PHga4Xudr MD++35Vy2cF0T0FYhl2rIg3bqTRezAf8GFYSI9crdRzTTVnM5ebWTvk70UsyONsDgjTC KPdA== X-Gm-Message-State: AOJu0YyZNxQahgV8TiN5YFEDGcGLv61NoxlBI06jzCDKU5pV9g+Aqvpt JsdtTC6E/Uc43Az8zHsGpE48+Sw4+inL7O4FpJI= X-Received: by 2002:a05:6402:798:b0:553:7e49:206a with SMTP id d24-20020a056402079800b005537e49206amr727623edy.65.1702965185012; Mon, 18 Dec 2023 21:53:05 -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: From: Andrii Nakryiko Date: Mon, 18 Dec 2023 21:52:52 -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 Mon, Dec 18, 2023 at 6:27=E2=80=AFPM Menglong Dong wrote: > > On Tue, Dec 19, 2023 at 2:03=E2=80=AFAM Andrii Nakryiko > wrote: > > > > 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 r= egs. > > > The assembly function "reg_not_equal()" that we add is exactly conver= ted > > > 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. > > > > Okay, sounds great! BTW, should I add such a comment to the > commit log or to the assembly function? > I'd leave it in the code, next to the function itself > > > > > diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/to= ols/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? > > > > Yeah, that makes sense. I'll add such a test in the next version. > > Thanks! > Menglong Dong > > > > +{ > > > + 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 > > >