Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4501332ybx; Mon, 4 Nov 2019 14:26:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzhBDq4DABr2aVVSku0mQ035iIcLgtDy3odI3NEkwcplLR/7PTo0Pk7NZtxG8F+W365d79e X-Received: by 2002:aa7:df8c:: with SMTP id b12mr22350475edy.166.1572906419744; Mon, 04 Nov 2019 14:26:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906419; cv=none; d=google.com; s=arc-20160816; b=Z8OQH6pZ0Cld9BICDK/P4SvNAEhkD/wGowS3NUoBe7P1jaVFPpxchU+YRkxFDGbK7E fMPEsGn9ruJfyPfR5ehbu4mfr53i99oR87gEOzUb0BU6Uxxz/hUoiKSCbZRkv9+SDlz/ +TjGHIltF0MgvKDci8LI8j3Qkd1vL+I8Ip/Dse6C19M9nYkCzqlll3apW0YcS98FF+mS +P411+TgDbv7cczRFHTjOQDjLu8KUOZsoWCjNPm2ht6En40oKzEQL5N57r/Eg1ODy4vc JWI64DOCZwZa+7TBCFq2dP+hICIvDTcrAzuGuU/QHeJA5YeCfQhS65RLFuuI5p9pNPSa GABg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bFITGhY1JoHr2t8KCwyZk8tBStgYo59JaHLpN8FZgzg=; b=Sdrxnp8QdnqhaN0ynzSgisTIW4dGaI9HIqozrfbcrSsUDQWqCjWYvTJ/lQSOClYFLl R0IJIMIcQ3E6y5oEazdpusUuevh7MfAibh/ZQJojcBqHglXNCNbEmyk1owfSDRvFwF5r VSBexEaTMgXRm/qa5tsIctCblfCmbGX52aNQGYY/uqMyQP1NIeO1TLFlnQ7jC1mRoN0N MF/pTcLoqUMw/mONg4xuPxwutMVyO048yIV7m8YKqI0BNj/NyksTCKxbPml2qXpMfE1F 24dBYF1CS+E2/+vAQKcVmkfJ4P2mFigg8plJCitOQrTlj0EI82TyGR9wB2yykTNCDRKC IJRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dWZA8DGk; 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 g1si4788793ejj.26.2019.11.04.14.26.36; Mon, 04 Nov 2019 14:26:59 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dWZA8DGk; 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 S2388497AbfKDWZo (ORCPT + 99 others); Mon, 4 Nov 2019 17:25:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:44530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730547AbfKDVvb (ORCPT ); Mon, 4 Nov 2019 16:51:31 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFEEF217F4; Mon, 4 Nov 2019 21:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904291; bh=amwiZazbFCzmGdcy7wJmN5hK9XOXC1IYu73p5ph2XXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dWZA8DGk4ZSr8LMNZqYRclFKAiaq6VFjghRxd23CaSbWUR4/S0Trzjw/qWYr2XhW0 8qvAAn/5ihHiN05/TF0uCOCsjpckhkfm9nXRAjSkZyn+9m+QYLeWgrjQy6GH/Hk6Gv s0LPE+7UQ7QkGPn4TnWBibayZ5vqyvFjPC1tgi+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Mahesh Bandewar , Jakub Kicinski Subject: [PATCH 4.9 53/62] bonding: fix potential NULL deref in bond_update_slave_arr Date: Mon, 4 Nov 2019 22:45:15 +0100 Message-Id: <20191104211954.599976834@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211901.387893698@linuxfoundation.org> References: <20191104211901.387893698@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit a7137534b597b7c303203e6bc3ed87e87a273bb8 upstream. syzbot got a NULL dereference in bond_update_slave_arr() [1], happening after a failure to allocate bond->slave_arr A workqueue (bond_slave_arr_handler) is supposed to retry the allocation later, but if the slave is removed before the workqueue had a chance to complete, bond->slave_arr can still be NULL. [1] Failed to build slave-array. kasan: CONFIG_KASAN_INLINE enabled kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] SMP KASAN PTI Modules linked in: Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:bond_update_slave_arr.cold+0xc6/0x198 drivers/net/bonding/bond_main.c:4039 RSP: 0018:ffff88018fe33678 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: ffffc9000290b000 RDX: 0000000000000000 RSI: ffffffff82b63037 RDI: ffff88019745ea20 RBP: ffff88018fe33760 R08: ffff880170754280 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffff88019745ea00 R14: 0000000000000000 R15: ffff88018fe338b0 FS: 00007febd837d700(0000) GS:ffff8801dad00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004540a0 CR3: 00000001c242e005 CR4: 00000000001626f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: [] __bond_release_one+0x43e/0x500 drivers/net/bonding/bond_main.c:1923 [] bond_release drivers/net/bonding/bond_main.c:2039 [inline] [] bond_do_ioctl+0x416/0x870 drivers/net/bonding/bond_main.c:3562 [] dev_ifsioc+0x6f4/0x940 net/core/dev_ioctl.c:328 [] dev_ioctl+0x1b8/0xc70 net/core/dev_ioctl.c:495 [] sock_do_ioctl+0x1bd/0x300 net/socket.c:1088 [] sock_ioctl+0x300/0x5d0 net/socket.c:1196 [] vfs_ioctl fs/ioctl.c:47 [inline] [] file_ioctl fs/ioctl.c:501 [inline] [] do_vfs_ioctl+0xacb/0x1300 fs/ioctl.c:688 [] SYSC_ioctl fs/ioctl.c:705 [inline] [] SyS_ioctl+0xb6/0xe0 fs/ioctl.c:696 [] do_syscall_64+0x528/0x770 arch/x86/entry/common.c:305 [] entry_SYSCALL_64_after_hwframe+0x42/0xb7 Fixes: ee6377147409 ("bonding: Simplify the xmit function for modes that use xmit_hash") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Mahesh Bandewar Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/bonding/bond_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3963,7 +3963,7 @@ out: * this to-be-skipped slave to send a packet out. */ old_arr = rtnl_dereference(bond->slave_arr); - for (idx = 0; idx < old_arr->count; idx++) { + for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) { if (skipslave == old_arr->arr[idx]) { old_arr->arr[idx] = old_arr->arr[old_arr->count-1];