public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Edward Cree <ecree@solarflare.com>,
	davem@davemloft.net,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Alexei Starovoitov <ast@fb.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	iovisor-dev <iovisor-dev@lists.iovisor.org>,
	josef@toxicpanda.com
Subject: Re: [PATCH net 1/2] selftests/bpf: subtraction bounds test
Date: Fri, 21 Jul 2017 16:29:22 +0200	[thread overview]
Message-ID: <59720FC2.9070301@iogearbox.net> (raw)
In-Reply-To: <a12c5a59-d2e0-5866-d225-501d19a3ec7b@solarflare.com>

On 07/21/2017 03:36 PM, Edward Cree wrote:
> There is a bug in the verifier's handling of BPF_SUB: [a,b] - [c,d] yields
>   was [a-c, b-d] rather than the correct [a-d, b-c].  So here is a test
>   which, with the bogus handling, will produce ranges of [0,0] and thus
>   allowed accesses; whereas the correct handling will give a range of
>   [-255, 255] (and hence the right-shift will give a range of [0, 255]) and
>   the accesses will be rejected.
>
> Signed-off-by: Edward Cree <ecree@solarflare.com>

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

>   tools/testing/selftests/bpf/test_verifier.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
> index af7d173..addea82 100644
> --- a/tools/testing/selftests/bpf/test_verifier.c
> +++ b/tools/testing/selftests/bpf/test_verifier.c
> @@ -5980,6 +5980,34 @@ static struct bpf_test tests[] = {
>   		.result = REJECT,
>   		.result_unpriv = REJECT,
>   	},
> +	{
> +		"subtraction bounds (map value)",
> +		.insns = {
> +			BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
> +			BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
> +			BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
> +			BPF_LD_MAP_FD(BPF_REG_1, 0),
> +			BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
> +				     BPF_FUNC_map_lookup_elem),
> +			BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 9),
> +			BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
> +			BPF_JMP_IMM(BPF_JGT, BPF_REG_1, 0xff, 7),
> +			BPF_LDX_MEM(BPF_B, BPF_REG_3, BPF_REG_0, 1),
> +			BPF_JMP_IMM(BPF_JGT, BPF_REG_3, 0xff, 5),
> +			BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_3),
> +			BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 56),
> +			BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
> +			BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
> +			BPF_EXIT_INSN(),
> +			BPF_MOV64_IMM(BPF_REG_0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		.fixup_map1 = { 3 },
> +		.errstr_unpriv = "R0 pointer arithmetic prohibited",
> +		.errstr = "R0 min value is negative, either use unsigned index or do a if (index >=0) check.",
> +		.result = REJECT,
> +		.result_unpriv = REJECT,
> +	},
>   };
>
>   static int probe_filter_length(const struct bpf_insn *fp)
>

  reply	other threads:[~2017-07-21 14:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 13:35 [PATCH net 0/2] bpf: fix verifier min/max handling in BPF_SUB Edward Cree
2017-07-21 13:36 ` [PATCH net 1/2] selftests/bpf: subtraction bounds test Edward Cree
2017-07-21 14:29   ` Daniel Borkmann [this message]
2017-07-21 13:37 ` [PATCH net 2/2] bpf/verifier: fix min/max handling in BPF_SUB Edward Cree
2017-07-21 14:30   ` Daniel Borkmann
2017-07-21 15:54 ` [iovisor-dev] [PATCH net 0/2] bpf: fix verifier " Nadav Amit
2017-07-24 21:03 ` David Miller

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=59720FC2.9070301@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@fb.com \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=iovisor-dev@lists.iovisor.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.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