From: Edward Cree Subject: Re: [PATCH v2] bpf: verifier: MOV64 don't mark dst reg unbounded Date: Tue, 31 Jul 2018 19:02:11 +0100 Message-ID: References: <20180731171722.6122-1-afabre@cloudflare.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: Arthur Fabre , Alexei Starovoitov , Daniel Borkmann , Y Song , Return-path: Received: from dispatch1-us1.ppe-hosted.com ([148.163.129.52]:45592 "EHLO dispatch1-us1.ppe-hosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727135AbeGaTnv (ORCPT ); Tue, 31 Jul 2018 15:43:51 -0400 In-Reply-To: <20180731171722.6122-1-afabre@cloudflare.com> Content-Language: en-GB Sender: netdev-owner@vger.kernel.org List-ID: On 31/07/18 18:17, Arthur Fabre wrote: > 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 > --- > v2: Add mov64 tests, always use DST_OP_NO_MARK > > kernel/bpf/verifier.c | 6 +++-- > tools/testing/selftests/bpf/test_verifier.c | 26 +++++++++++++++++++++ > 2 files changed, 30 insertions(+), 2 deletions(-) Acked-by: Edward Cree