bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH bpf 2/2] selftests: bpf: test that dead ldx_w insns are accepted
Date: Thu, 12 Aug 2021 17:09:20 +0200	[thread overview]
Message-ID: <ad395f50f2a717aefbdfafca042c34ae538ce40c.camel@linux.ibm.com> (raw)
In-Reply-To: <20210812140518.183178-3-iii@linux.ibm.com>

On Thu, 2021-08-12 at 16:05 +0200, Ilya Leoshkevich wrote:
> Prevent regressions related to zero-extension metadata handling during
> dead code sanitization.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/testing/selftests/bpf/verifier/dead_code.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/verifier/dead_code.c
> b/tools/testing/selftests/bpf/verifier/dead_code.c
> index 2c8935b3e65d..c642138b7fc2 100644
> --- a/tools/testing/selftests/bpf/verifier/dead_code.c
> +++ b/tools/testing/selftests/bpf/verifier/dead_code.c
> @@ -159,3 +159,16 @@
>         .result = ACCEPT,
>         .retval = 2,
>  },
> +{
> +       "dead code: zero extension",
> +       .insns = {
> +       BPF_MOV64_IMM(BPF_REG_0, 0),
> +       BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 0, 1),
> +       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, 0),
> +       BPF_EXIT_INSN(),
> +       },
> +       .errstr_unpriv = "invalid read from stack R10 off=0 size=4",
> +       .result_unpriv = REJECT,
> +       .result = ACCEPT,
> +       .retval = 0,
> +},

Please disregard this patch: the test does not fail in absence of the
fix. What rather fails is:

	BPF_MOV64_IMM(BPF_REG_0, 0),
	BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4),
	BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 0, 1),
	BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -4),
	BPF_EXIT_INSN(),

The difference is that here the dead ldx_w is actually safe. I will
send a v3 shortly (I also realized I forgot to tag this series with
v2).


      reply	other threads:[~2021-08-12 15:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 14:05 [PATCH bpf 0/2] bpf: clear zext_dst of dead insns Ilya Leoshkevich
2021-08-12 14:05 ` [PATCH bpf 1/2] " Ilya Leoshkevich
2021-08-12 14:05 ` [PATCH bpf 2/2] selftests: bpf: test that dead ldx_w insns are accepted Ilya Leoshkevich
2021-08-12 15:09   ` Ilya Leoshkevich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad395f50f2a717aefbdfafca042c34ae538ce40c.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).