Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1659885

[RFC PATCH net-next 1/5] selftests/bpf: add test for mixed signed and unsigned bounds checks

From Edward Cree <ecree@solarflare.com>
Newsgroups linux.kernel
Subject [RFC PATCH net-next 1/5] selftests/bpf: add test for mixed signed and unsigned bounds checks
Date 2017-06-07 17:00 +0200
Message-ID <tPKBd-7Z0-31@gated-at.bofh.it> (permalink)
References <tPKBd-7Z0-25@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Currently fails due to bug in verifier bounds handling.

Signed-off-by: Edward Cree <ecree@solarflare.com>
---
 tools/testing/selftests/bpf/test_verifier.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index cabb19b..5074cfa 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -5169,6 +5169,32 @@ static struct bpf_test tests[] = {
 		},
 		.result = ACCEPT,
 	},
+	{
+		"bounds checks mixing signed and unsigned",
+		.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, 7),
+			BPF_ST_MEM(BPF_DW, BPF_REG_10, -16, -8),
+			BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_10, -16),
+			BPF_MOV64_IMM(BPF_REG_2, -1),
+			BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_2, 3),
+			BPF_JMP_IMM(BPF_JSGT, BPF_REG_1, 1, 2),
+			BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
+			BPF_ST_MEM(BPF_B, BPF_REG_0, 0, 0),
+			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)

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH net-next 0/5] bpf: rewrite value tracking in verifier Edward Cree <ecree@solarflare.com> - 2017-06-07 17:00 +0200
  [RFC PATCH net-next 1/5] selftests/bpf: add test for mixed signed and  unsigned bounds checks Edward Cree <ecree@solarflare.com> - 2017-06-07 17:00 +0200
  [RFC PATCH net-next 5/5] selftests/bpf: change test_verifier  expectations Edward Cree <ecree@solarflare.com> - 2017-06-07 17:10 +0200
    Re: [RFC PATCH net-next 5/5] selftests/bpf: change test_verifier  expectations Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 04:50 +0200
      Re: [RFC PATCH net-next 5/5] selftests/bpf: change test_verifier  expectations Edward Cree <ecree@solarflare.com> - 2017-06-08 17:30 +0200
  [RFC PATCH net-next 3/5] bpf/verifier: feed pointer-to-unknown-scalar  casts into scalar ALU path Edward Cree <ecree@solarflare.com> - 2017-06-07 17:10 +0200
    Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 04:40 +0200
      Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Edward Cree <ecree@solarflare.com> - 2017-06-08 17:30 +0200
        Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 19:00 +0200
          Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Edward Cree <ecree@solarflare.com> - 2017-06-08 19:20 +0200
            Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 20:50 +0200
              Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Edward Cree <ecree@solarflare.com> - 2017-06-08 21:10 +0200
                Re: [RFC PATCH net-next 3/5] bpf/verifier: feed  pointer-to-unknown-scalar casts into scalar ALU path Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 23:20 +0200
  Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 04:40 +0200
    Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Edward Cree <ecree@solarflare.com> - 2017-06-08 17:00 +0200
      Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 18:50 +0200
        Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Edward Cree <ecree@solarflare.com> - 2017-06-08 21:40 +0200
          Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 23:30 +0200
        Re: [RFC PATCH net-next 2/5] bpf/verifier: rework value tracking Daniel Borkmann <daniel@iogearbox.net> - 2017-06-09 15:30 +0200
  Re: [RFC PATCH net-next 4/5] bpf/verifier: track signed and unsigned  min/max values Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 04:50 +0200
    Re: [RFC PATCH net-next 4/5] bpf/verifier: track signed and unsigned  min/max values Edward Cree <ecree@solarflare.com> - 2017-06-08 17:30 +0200
      Re: [RFC PATCH net-next 4/5] bpf/verifier: track signed and unsigned  min/max values Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2017-06-08 18:50 +0200
  Re: [RFC PATCH net-next 0/5] bpf: rewrite value tracking in  verifier David Miller <davem@davemloft.net> - 2017-06-08 22:20 +0200

csiph-web