From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark Rutland Subject: Re: [PATCH bpf] bpf: fix ldx in ld_abs rewrite for large offsets Date: Tue, 10 Jul 2018 13:27:31 +0100 Message-ID: <20180710122730.ufsz2mnqw2rwhcbl@lakrids.cambridge.arm.com> References: <1aaf318d0b40fc471a0d1705efd8c69d98fbf866.1531175919.git.daniel@iogearbox.net> <20180710101432.u5rdnmofd3imf5vu@lakrids.cambridge.arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: alexei.starovoitov@gmail.com, netdev@vger.kernel.org To: Daniel Borkmann Return-path: Received: from foss.arm.com ([217.140.101.70]:45362 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932910AbeGJM1e (ORCPT ); Tue, 10 Jul 2018 08:27:34 -0400 Content-Disposition: inline In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Tue, Jul 10, 2018 at 02:13:42PM +0200, Daniel Borkmann wrote: > On 07/10/2018 12:14 PM, Mark Rutland wrote: > > On Tue, Jul 10, 2018 at 12:43:22AM +0200, Daniel Borkmann wrote: > >> Mark reported that syzkaller triggered a KASAN detected slab-out-of-bounds > >> bug in ___bpf_prog_run() with a BPF_LD | BPF_ABS word load at offset 0x8001. > >> After further investigation it became clear that the issue was the > >> BPF_LDX_MEM() which takes offset as an argument whereas it cannot encode > >> larger than S16_MAX offsets into it. For this synthetical case we need to > >> move the full address into tmp register instead and do the LDX without > >> immediate value. > >> > >> Fixes: e0cea7ce988c ("bpf: implement ld_abs/ld_ind in native bpf") > >> Reported-by: syzbot > >> Reported-by: Mark Rutland > >> Signed-off-by: Daniel Borkmann > >> --- > >> net/core/filter.c | 16 +++++++++++++--- > >> 1 file changed, 13 insertions(+), 3 deletions(-) > >> > >> diff --git a/net/core/filter.c b/net/core/filter.c > >> index 5fa66a3..a13f5b1 100644 > >> --- a/net/core/filter.c > >> +++ b/net/core/filter.c > >> @@ -459,11 +459,21 @@ static bool convert_bpf_ld_abs(struct sock_filter *fp, struct bpf_insn **insnp) > >> (!unaligned_ok && offset >= 0 && > >> offset + ip_align >= 0 && > >> offset + ip_align % size == 0))) { > >> + bool ldx_off_ok = offset <= S16_MAX; > >> + > > > > Given offset is a (signed) int, is it possible for that to be a negative > > value less than S16_MIN? ... or is that ruled out elsewhere? > > This branch here handles only positive offset. Ah, sorry. I missed the "offset >= 0" check in the context above. > offset can be negative, > but in that case these insns won't be emitted and handling will be done > in 'slow path' via bpf_skb_load_helper_*(). Ok; looks good to me, then. Thanks, Mark.