diff options
author | Alexei Starovoitov <ast@fb.com> | 2017-03-24 18:57:33 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-03 11:36:35 -0400 |
commit | 0ea3c235779ac1eb132ba15e754995090e18a26b (patch) | |
tree | d89f14a8384d6225e315ec4595a8f692b7e345f6 /kernel/bpf | |
parent | d60d4e8c1b73608b6af3bc384e88c062485fd95e (diff) |
bpf: improve verifier packet range checks
[ Upstream commit b1977682a3858b5584ffea7cfb7bd863f68db18d ]
llvm can optimize the 'if (ptr > data_end)' checks to be in the order
slightly different than the original C code which will confuse verifier.
Like:
if (ptr + 16 > data_end)
return TC_ACT_SHOT;
// may be followed by
if (ptr + 14 > data_end)
return TC_ACT_SHOT;
while llvm can see that 'ptr' is valid for all 16 bytes,
the verifier could not.
Fix verifier logic to account for such case and add a test.
Reported-by: Huapeng Zhou <hzhou@fb.com>
Fixes: 969bf05eb3ce ("bpf: direct packet access")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/bpf')
-rw-r--r-- | kernel/bpf/verifier.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 85d1c9423ccb..7c9f94c53441 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c | |||
@@ -1829,14 +1829,15 @@ static void find_good_pkt_pointers(struct bpf_verifier_state *state, | |||
1829 | 1829 | ||
1830 | for (i = 0; i < MAX_BPF_REG; i++) | 1830 | for (i = 0; i < MAX_BPF_REG; i++) |
1831 | if (regs[i].type == PTR_TO_PACKET && regs[i].id == dst_reg->id) | 1831 | if (regs[i].type == PTR_TO_PACKET && regs[i].id == dst_reg->id) |
1832 | regs[i].range = dst_reg->off; | 1832 | /* keep the maximum range already checked */ |
1833 | regs[i].range = max(regs[i].range, dst_reg->off); | ||
1833 | 1834 | ||
1834 | for (i = 0; i < MAX_BPF_STACK; i += BPF_REG_SIZE) { | 1835 | for (i = 0; i < MAX_BPF_STACK; i += BPF_REG_SIZE) { |
1835 | if (state->stack_slot_type[i] != STACK_SPILL) | 1836 | if (state->stack_slot_type[i] != STACK_SPILL) |
1836 | continue; | 1837 | continue; |
1837 | reg = &state->spilled_regs[i / BPF_REG_SIZE]; | 1838 | reg = &state->spilled_regs[i / BPF_REG_SIZE]; |
1838 | if (reg->type == PTR_TO_PACKET && reg->id == dst_reg->id) | 1839 | if (reg->type == PTR_TO_PACKET && reg->id == dst_reg->id) |
1839 | reg->range = dst_reg->off; | 1840 | reg->range = max(reg->range, dst_reg->off); |
1840 | } | 1841 | } |
1841 | } | 1842 | } |
1842 | 1843 | ||