Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4471443ybx; Mon, 4 Nov 2019 14:00:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwdNg/p+J2yOf14OruZ+Mhv6jzfgzTdzBPkI/oYT/SkUT+MYufRe90QpcZwJ4GwST8NWUWV X-Received: by 2002:a17:906:6d8a:: with SMTP id h10mr8452476ejt.224.1572904819559; Mon, 04 Nov 2019 14:00:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572904819; cv=none; d=google.com; s=arc-20160816; b=NLSa6kwfCqnjEcf5woncMCyQVKP7nPASu2YRghbl+2KhgwhOkPsCbY/Y7fEmAx8mpU OZXV3J+H+YiCpXI6B6sZBtfppyHVPF49IcnOwhgR4RqPwgKcA2/4Liz93fHDIMhslSkr IY8/GxLIvykKkvxlEwHUL36e03zkV36Kxqt6MGc+C9xu0wsljR8N3vgpTwW/f0DXH6cs oNOScMuwM91ja4k+2A1GoMo/h1yLlD9O3LZ+xuXdPSMQnVzONQlLCBCHe9JcbsNkYxtp JdRsCmnlCmnps2Ix8xumihFMZJNYVcC5gZh/HqgUzwSmHuI7EsvlfDFKkhqVRbyJ8QPh PW8g== 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=XRjDl5YK5ybp1tsOGFQpIWCA8hGQIyCYlMp05bl6pIY=; b=OLKjpByKrHN9RnRXxdEMRMKUE5z44rSt5fgEyOyAwEum2k3Pya23Q3fT3EXQUUEYuY 6swv/RJBT1ucKB6zTeybnd++t8qKUs59VYF5PZ+e/g6m8TA2vP/0FvIM0NznDwENgYIg ZEQ82wwMaSVqlT6DP/9B7KUuZjh8wbglKG2iZuU3jxzQ8zWEoeHeWXnAimBILHEJICan 4OMWJZWxsmbfaqX5khwNJ3bL/jycDlX0n1OQDXJ/2xNr0C0OTA/aHNnCZz4WinSE51la Yq2xxfb2X01TA6vhGErmV1EvZsdLAj0ohCvoE3CSQ8IX6KKqP2uFI/U4SAt7QkmzvbIs Fbzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ljqXueob; 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 ca22si5131035ejb.22.2019.11.04.13.59.56; Mon, 04 Nov 2019 14:00:19 -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=ljqXueob; 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 S2388295AbfKDV4I (ORCPT + 99 others); Mon, 4 Nov 2019 16:56:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:51580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388289AbfKDV4G (ORCPT ); Mon, 4 Nov 2019 16:56:06 -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 2E93A21929; Mon, 4 Nov 2019 21:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904565; bh=zNgvHkjkPpdoW9YQnqtufN6jgYMMwz+ZHqic7ef+HrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljqXueobu/aguqVLN51SAcrDP+YnFSQqylujbSydbZnMsBwr+9wPBuVVlrxiBwU2p ztolwe15tDoWFztlkI3wpaKuIXoiMxsxsOR9El71hL2b4rFX8oTCHSIuhNwY+CPAzc snYzVUFKFzbmUU2Vh9RW2LIrRwsc609Xp49yozCM= 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.14 88/95] bonding: fix potential NULL deref in bond_update_slave_arr Date: Mon, 4 Nov 2019 22:45:26 +0100 Message-Id: <20191104212123.620848226@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212038.056365853@linuxfoundation.org> References: <20191104212038.056365853@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 @@ -3992,7 +3992,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];