Netdev List
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Arthur Fabre <afabre@cloudflare.com>,
	Alexei Starovoitov <ast@kernel.org>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] bpf: verifier: BPF_MOV don't mark dst reg if src == dst
Date: Thu, 26 Jul 2018 02:42:28 +0200	[thread overview]
Message-ID: <bd65e777-8a8b-e382-c444-f1c44cd5e90b@iogearbox.net> (raw)
In-Reply-To: <CAOn4ftsY-MOMXYR3HVUaoWAyHxPj2sNNqUeP2tff4rCK8NvhDw@mail.gmail.com>

On 07/26/2018 12:08 AM, Arthur Fabre wrote:
> When check_alu_op() handles a BPF_MOV between two registers,
> it calls check_reg_arg() on the dst register, marking it as unbounded.
> If the src and dst register are the same, this marks the src as
> unbounded, which can lead to unexpected errors for further checks that
> rely on bounds info.
> 
> check_alu_op() now only marks the dst register as unbounded if it
> different from the src register.
> 
> Signed-off-by: Arthur Fabre <afabre@cloudflare.com>
> ---
>  kernel/bpf/verifier.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 63aaac52a265..ddfe3c544a80 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -3238,8 +3238,9 @@ static int check_alu_op(struct bpf_verifier_env
> *env, struct bpf_insn *insn)
>                         }
>                 }
> 
> -               /* check dest operand */
> -               err = check_reg_arg(env, insn->dst_reg, DST_OP);
> +               /* check dest operand, only mark if dest != src */
> +               err = check_reg_arg(env, insn->dst_reg,
> +                               insn->dst_reg == insn->src_reg ?
> DST_OP_NO_MARK : DST_OP);
>                 if (err)
>                         return err;
> 

Thanks a lot for the patch! Looks like it's corrupted wrt newline.

Please also add test cases to tools/testing/selftests/bpf/test_verifier.c
for the cases of mov64 and mov32 where in each src==dst and src!=dst; mov32
should mark it as unbounded but not former, so would be good to keep tracking
that in selftests.

  reply	other threads:[~2018-07-26  1:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25 22:08 [PATCH] bpf: verifier: BPF_MOV don't mark dst reg if src == dst Arthur Fabre
2018-07-26  0:42 ` Daniel Borkmann [this message]
2018-07-26 16:52   ` Arthur Fabre
2018-07-26 23:21     ` Y Song
2018-07-30  7:40       ` Arthur Fabre
2018-07-29 15:59 ` Alexei Starovoitov
2018-07-30  7:44   ` Arthur Fabre
2018-07-30  9:10     ` Daniel Borkmann
2018-07-30 10:58       ` Arthur Fabre
2018-07-30 12:03         ` Daniel Borkmann
2018-07-30 16:40           ` Edward Cree

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=bd65e777-8a8b-e382-c444-f1c44cd5e90b@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=afabre@cloudflare.com \
    --cc=ast@kernel.org \
    --cc=netdev@vger.kernel.org \
    /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