Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8331300ybl; Thu, 16 Jan 2020 14:47:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyFgWITdPEDGa5lZn71Qe74qmNnpPVlo1eS3ExbrIzIaVkPVcIGgoXkrk7bD5y/UqohEWes X-Received: by 2002:a05:6830:2147:: with SMTP id r7mr4077992otd.94.1579214822266; Thu, 16 Jan 2020 14:47:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579214822; cv=none; d=google.com; s=arc-20160816; b=J15oLfdneRns/9lhHzPdIFhu9r+UPbb3BPWVyeBisG8Vl9UAfWNgodJclBjOIfkI/U HzqycZzKtAL/q3R/3UM3U0dck2RIcrN16o8ep1cXFVJvdwVVw9cOI8/7DYlADGAT43Pq 5//a+ZX+OWROWdcAMfkKAWUbJ7ciuTmSldn61Qh1cdA+BmH4VrBGo5JcPghyNaQ/ZbxI BVSxMMflbjGt4lcyk2wKaHlmSuxsOaEcX++5IBOLbgrRL+s9f9fcPamEmv2/knPx89ci MZgP/3+tJdQUnO/FDFrzPqgRhDAGdhqd82Mb5kjdlVS8OBljv2dzHqq5Lp79e7uKLazs CFzA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1CTuYi/nkPqxCYqwBUo3eakOVkPzghcaZTPkuVejiU8=; b=DWvkzlgUdL03ZOd861zMl4SGw5C6aFiAMPgEkfJ8W5YJzsHebb0ZBsaBJj7+4/mx6g /4gC0gHFfhID74azSc6C5/UBiDwzdkRRTzpaxCE5HHSEWN85lSzuCjwHpLmhWITggpIh R515YvYStkuOww9StbIG0aI2z+OoG00X5GMAcTxw8msgpX9UPhyCN73vg8QteyTiVVd1 cxqkl7WJB3cuLAORUIoBp22ODYqD/Fwwd3AkfmsUhT8Wmo3rA8VYwbt2EqVkIqVu/2MW AD1q/Hpelb22mUFI9ifpFF9X/+bGBovjZnhuJK9vqmSBOx+lo8Z2IIhoxbWUgQyDXoTW zckA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BtSUPByS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si12237419oij.134.2020.01.16.14.46.48; Thu, 16 Jan 2020 14:47:02 -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=BtSUPByS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406994AbgAPSH6 (ORCPT + 99 others); Thu, 16 Jan 2020 13:07:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:54914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388258AbgAPRiz (ORCPT ); Thu, 16 Jan 2020 12:38:55 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 08E88246DB; Thu, 16 Jan 2020 17:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579196334; bh=9EByW0Nt+IUiPGvqLx5gFrNDD3okv7fpY2aM1UMJAOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BtSUPBySKCXjDrYW4ehjkqcVxHYhFeeFmQuNtBkrF1Q5zfWKVfIwRGJaRspiNgEGX ArCJStm2mfRFjDTiawXNjGZq+fntUFNz2AkbwX/paT0PJUhUU8CavxhrZBVUg1hy6R pA3ihfzLHcTdzR/y01GSg5lZvxrutpiDkgcRe7e0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: YueHaibing , Guillaume Nault , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 133/251] l2tp: Fix possible NULL pointer dereference Date: Thu, 16 Jan 2020 12:34:42 -0500 Message-Id: <20200116173641.22137-93-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116173641.22137-1-sashal@kernel.org> References: <20200116173641.22137-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: YueHaibing [ Upstream commit 638a3a1e349ddf5b82f222ff5cb3b4f266e7c278 ] BUG: unable to handle kernel NULL pointer dereference at 0000000000000128 PGD 0 P4D 0 Oops: 0000 [#1 CPU: 0 PID: 5697 Comm: modprobe Tainted: G W 5.1.0-rc7+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014 RIP: 0010:__lock_acquire+0x53/0x10b0 Code: 8b 1c 25 40 5e 01 00 4c 8b 6d 10 45 85 e4 0f 84 bd 06 00 00 44 8b 1d 7c d2 09 02 49 89 fe 41 89 d2 45 85 db 0f 84 47 02 00 00 <48> 81 3f a0 05 70 83 b8 00 00 00 00 44 0f 44 c0 83 fe 01 0f 86 3a RSP: 0018:ffffc90001c07a28 EFLAGS: 00010002 RAX: 0000000000000000 RBX: ffff88822f038440 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000128 RBP: ffffc90001c07a88 R08: 0000000000000001 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000001 R13: 0000000000000000 R14: 0000000000000128 R15: 0000000000000000 FS: 00007fead0811540(0000) GS:ffff888237a00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000128 CR3: 00000002310da000 CR4: 00000000000006f0 Call Trace: ? __lock_acquire+0x24e/0x10b0 lock_acquire+0xdf/0x230 ? flush_workqueue+0x71/0x530 flush_workqueue+0x97/0x530 ? flush_workqueue+0x71/0x530 l2tp_exit_net+0x170/0x2b0 [l2tp_core ? l2tp_exit_net+0x93/0x2b0 [l2tp_core ops_exit_list.isra.6+0x36/0x60 unregister_pernet_operations+0xb8/0x110 unregister_pernet_device+0x25/0x40 l2tp_init+0x55/0x1000 [l2tp_core ? 0xffffffffa018d000 do_one_initcall+0x6c/0x3cc ? do_init_module+0x22/0x1f1 ? rcu_read_lock_sched_held+0x97/0xb0 ? kmem_cache_alloc_trace+0x325/0x3b0 do_init_module+0x5b/0x1f1 load_module+0x1db1/0x2690 ? m_show+0x1d0/0x1d0 __do_sys_finit_module+0xc5/0xd0 __x64_sys_finit_module+0x15/0x20 do_syscall_64+0x6b/0x1d0 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7fead031a839 Code: 00 f3 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 1f f6 2c 00 f7 d8 64 89 01 48 RSP: 002b:00007ffe8d9acca8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 RAX: ffffffffffffffda RBX: 0000560078398b80 RCX: 00007fead031a839 RDX: 0000000000000000 RSI: 000056007659dc2e RDI: 0000000000000003 RBP: 000056007659dc2e R08: 0000000000000000 R09: 0000560078398b80 R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 R13: 00005600783a04a0 R14: 0000000000040000 R15: 0000560078398b80 Modules linked in: l2tp_core(+) e1000 ip_tables ipv6 [last unloaded: l2tp_core CR2: 0000000000000128 ---[ end trace 8322b2b8bf83f8e1 If alloc_workqueue fails in l2tp_init, l2tp_net_ops is unregistered on failure path. Then l2tp_exit_net is called which will flush NULL workqueue, this patch add a NULL check to fix it. Fixes: 67e04c29ec0d ("l2tp: unregister l2tp_net_ops on failure path") Signed-off-by: YueHaibing Acked-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/l2tp/l2tp_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 4ae758bcb2cf..394a1ddb0782 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1947,7 +1947,8 @@ static __net_exit void l2tp_exit_net(struct net *net) } rcu_read_unlock_bh(); - flush_workqueue(l2tp_wq); + if (l2tp_wq) + flush_workqueue(l2tp_wq); rcu_barrier(); } -- 2.20.1