Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp357634img; Thu, 28 Feb 2019 00:12:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IYnUTMAO7pNUY9hexstWS7kCM5nRHrqn3qd0C6EI/v+tceYyaPjuqvsoV8uAezcKepBpJ5E X-Received: by 2002:a63:e050:: with SMTP id n16mr7249304pgj.210.1551341530765; Thu, 28 Feb 2019 00:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551341530; cv=none; d=google.com; s=arc-20160816; b=zJh86GEnVd2CqLZsD7IbR92jThux0KGtpjjg4lJgRwiIlX1MTCOGcOZIAxNXeRkj7d 8Mn/BXKpZhejMkppNxCGEEqHY+mEXHPB2LBWHx+6PYhMcydKIZ8YyZnUXtsS414HH8P3 W/rpHaPt1JkwvxkRpf7+iglwjB016pr4aPxo6ffo4wtA4/YyLR1u3VdYZfsLhr7lSMRs mCxusPqEW3XaYraBVYEZVY+5+k4hZvPxIBdepwcUTyrRt7a3LONah1aFGlejL1L4FTEN LIdJQIUrua9Pav8ObofmyIazPMg6NMZGXs8W+ax6Z3F9nf0rJCUu1zCe61h8ystW7poO omAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=cSZLTDzIETnZEmSoX7ePHRMJ+3Gc7qUHS0MIwtdKHME=; b=QxjihXrujkPvLWORVbHJcLSuf9aZ5gzFj0zhY11Kitd597G5Ut/aS4fm5vykfFwcei ansb8vstaT2rusti5EI+tCL11HwARulaFBLyRECx7TBW1Nkpf+gHjsYPEkwebY5/uwMJ krT3hMfExp4oHLCJe3KYGy20fyns06Xhjxx/ErByiCcey04d/GTM6B5eZOFS4JxVREdL U1GkdhbnWVu/DcU2MNRZ8q9rYLu+3vMsKX48L3Dv6f7igHAQ6kq3s8FXE1t5hydH1qDZ e2tMFZadza0r+CrWJroeeKnZ9XwzEIn0ysip5DeClt48P6zZVBECCUexBrtPT8/T9BU5 09aQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si18099629plb.38.2019.02.28.00.11.54; Thu, 28 Feb 2019 00:12:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730956AbfB1Hwl (ORCPT + 99 others); Thu, 28 Feb 2019 02:52:41 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:43062 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbfB1Hwl (ORCPT ); Thu, 28 Feb 2019 02:52:41 -0500 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1gzGUa-0007Sx-PN; Thu, 28 Feb 2019 15:52:32 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gzGUV-00023R-25; Thu, 28 Feb 2019 15:52:27 +0800 Date: Thu, 28 Feb 2019 15:52:27 +0800 From: Herbert Xu To: Yue Haibing Cc: steffen.klassert@secunet.com, davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH] xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink Message-ID: <20190228075226.hza3hydllddj65nd@gondor.apana.org.au> References: <20190228071859.17768-1-yuehaibing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190228071859.17768-1-yuehaibing@huawei.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 28, 2019 at 03:18:59PM +0800, Yue Haibing wrote: > From: YueHaibing > > UBSAN report this: > > UBSAN: Undefined behaviour in net/xfrm/xfrm_policy.c:1289:24 > index 6 is out of range for type 'unsigned int [6]' > CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.4.162-514.55.6.9.x86_64+ #13 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 > 0000000000000000 1466cf39b41b23c9 ffff8801f6b07a58 ffffffff81cb35f4 > 0000000041b58ab3 ffffffff83230f9c ffffffff81cb34e0 ffff8801f6b07a80 > ffff8801f6b07a20 1466cf39b41b23c9 ffffffff851706e0 ffff8801f6b07ae8 > Call Trace: > [] __dump_stack lib/dump_stack.c:15 [inline] > [] dump_stack+0x114/0x1a0 lib/dump_stack.c:51 > [] ubsan_epilogue+0x12/0x8f lib/ubsan.c:164 > [] __ubsan_handle_out_of_bounds+0x16e/0x1b2 lib/ubsan.c:382 > [] __xfrm_policy_unlink+0x3dd/0x5b0 net/xfrm/xfrm_policy.c:1289 > [] xfrm_policy_delete+0x52/0xb0 net/xfrm/xfrm_policy.c:1309 > [] xfrm_policy_timer+0x30b/0x590 net/xfrm/xfrm_policy.c:243 > [] call_timer_fn+0x237/0x990 kernel/time/timer.c:1144 > [] __run_timers kernel/time/timer.c:1218 [inline] > [] run_timer_softirq+0x6ce/0xb80 kernel/time/timer.c:1401 > [] __do_softirq+0x299/0xe10 kernel/softirq.c:273 > [] invoke_softirq kernel/softirq.c:350 [inline] > [] irq_exit+0x216/0x2c0 kernel/softirq.c:391 > [] exiting_irq arch/x86/include/asm/apic.h:652 [inline] > [] smp_apic_timer_interrupt+0x8b/0xc0 arch/x86/kernel/apic/apic.c:926 > [] apic_timer_interrupt+0xa5/0xb0 arch/x86/entry/entry_64.S:735 > [] ? native_safe_halt+0x6/0x10 arch/x86/include/asm/irqflags.h:52 > [] arch_safe_halt arch/x86/include/asm/paravirt.h:111 [inline] > [] default_idle+0x27/0x430 arch/x86/kernel/process.c:446 > [] arch_cpu_idle+0x15/0x20 arch/x86/kernel/process.c:437 > [] default_idle_call+0x53/0x90 kernel/sched/idle.c:92 > [] cpuidle_idle_call kernel/sched/idle.c:156 [inline] > [] cpu_idle_loop kernel/sched/idle.c:251 [inline] > [] cpu_startup_entry+0x60d/0x9a0 kernel/sched/idle.c:299 > [] start_secondary+0x3c9/0x560 arch/x86/kernel/smpboot.c:245 > > The issue is triggered as this: > > xfrm_add_policy > -->verify_newpolicy_info //check the index provided by user with XFRM_POLICY_MAX > //In my case, the index is 0x6E6BB6, so it pass the check. > -->xfrm_policy_construct //copy the user's policy and set xfrm_policy_timer > -->xfrm_policy_insert > --> __xfrm_policy_link //use the orgin dir, in my case is 2 > --> xfrm_gen_index //generate policy index, there is 0x6E6BB6 > > then xfrm_policy_timer be fired > > xfrm_policy_timer > --> xfrm_policy_id2dir //get dir from (policy index & 7), in my case is 6 > --> xfrm_policy_delete > --> __xfrm_policy_unlink //access policy_count[dir], trigger out of range access > > Add xfrm_policy_id2dir check in verify_newpolicy_info, make sure the computed dir is > valid, to fix the issue. > > Reported-by: Hulk Robot > Fixes: e682adf021be ("xfrm: Try to honor policy index if it's supplied by user") > Signed-off-by: YueHaibing > --- > net/xfrm/xfrm_user.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Acked-by: Herbert Xu -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt