]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: verifier: MOV64 don't mark dst reg unbounded
authorArthur Fabre <afabre@cloudflare.com>
Tue, 31 Jul 2018 17:17:22 +0000 (18:17 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 31 Jul 2018 20:09:33 +0000 (22:09 +0200)
commitae18936163c4d5c5c17cc26f55b343d32de2db40
tree18cda999382d4e19ab89c30221ffeafed8b26baa
parent36fe6318bbf380f23447921eb2336a55e1493013
bpf: verifier: MOV64 don't mark dst reg unbounded

When check_alu_op() handles a BPF_MOV64 between two registers,
it calls check_reg_arg(DST_OP) 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. For example:

BPF_MOV64_IMM(BPF_REG_2, 0),
BPF_MOV64_REG(BPF_REG_2, BPF_REG_2),
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_2),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),

Results in:

"math between ctx pointer and register with unbounded
min value is not allowed"

check_alu_op() now uses check_reg_arg(DST_OP_NO_MARK), and MOVs
that need to mark the dst register (MOVIMM, MOV32) do so.

Added a test case for MOV64 dst == src, and dst != src.

Signed-off-by: Arthur Fabre <afabre@cloudflare.com>
Acked-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/test_verifier.c