Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1193346ybn; Wed, 2 Oct 2019 12:13:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIJsId4gecNnaU3FD/UiffQSuk2hvnn9m6BCq+0M/Jvbv95yIVwMCUtRc4W//IhE2p2LJh X-Received: by 2002:a50:b7ed:: with SMTP id i42mr5453788ede.52.1570043634397; Wed, 02 Oct 2019 12:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043634; cv=none; d=google.com; s=arc-20160816; b=NpYLRRFflPXqbOsXiar7H0mpdzo8/r2U+vBXuyaffOh9cMG5ih+JE6/eAIq5S5XyWD c01YTMm38Wp4ry00ABh04V17BStD+McnRPB+WwynsGWkX9LS+35S5+zDKCpJTAUbtmi5 8GvhXSx6GGvXd2lTltL5kLg1tgChU8Q5wA4ytrxobuRPls14iOWmpdR8U+LANPPiJJF3 5pOn5pA/Jk8CLBgpnPjKZG2ysj3MKuNkkv7myHjRnzLXjlFl2cWk+ILfbMRN3xLrfld5 IVwIqcvGOrHVZDzFG/eYzYYCrHhtpVTAX3pl48GV7TGnvc32osbV12+xjFHSzooAcoI2 GoJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=2G2ZqH8EgmZJ94TTaWBLyfTq65it3T6NFcjAMF482No=; b=JMVsxNvXWo8tXEkjCHkCqPlqS6h1TcDSokyt+TWVh4KnmhfxvmDv7LEpeWmGdqWRBY 0dRg0dZ+/ljYsiK51587xzECiKsGNeiZPXk05qB3Ohx8eiAiM+fbcp1Ci03P7dWnAlOh Bq1BVrk8Z+jXl8vaCQU0DDGJvZ+ryvsOPkXLWm6L15vrEnNJNfQfkudkKcs8Vz18hzsN sqo5lQj9IBg/7Yx295zX9thdNXzZpydngbmgfHVj8jEy55ICLNGgZSqnmRbcprLIY9xP utNRh9IMHloWy2gW1q4r6xd+f2ZTT+7MBZ6GOObi9YxkocKsmofMMmOU+ZPoHQJ0sPVc KMWA== 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 g25si7539edr.71.2019.10.02.12.13.30; Wed, 02 Oct 2019 12:13:54 -0700 (PDT) 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 S1729170AbfJBTIL (ORCPT + 99 others); Wed, 2 Oct 2019 15:08:11 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35206 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbfJBTIH (ORCPT ); Wed, 2 Oct 2019 15:08:07 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyn-000357-29; Wed, 02 Oct 2019 20:08:05 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjym-0003Zw-Qw; Wed, 02 Oct 2019 20:08:04 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "YueHaibing" , "Mark Brown" , "Mukesh Ojha" , "Axel Lin" , "Geert Uytterhoeven" , "Hulk Robot" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 02/87] spi: bitbang: Fix NULL pointer dereference in spi_unregister_master In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: YueHaibing commit 5caaf29af5ca82d5da8bc1d0ad07d9e664ccf1d8 upstream. If spi_register_master fails in spi_bitbang_start because device_add failure, We should return the error code other than 0, otherwise calling spi_bitbang_stop may trigger NULL pointer dereference like this: BUG: KASAN: null-ptr-deref in __list_del_entry_valid+0x45/0xd0 Read of size 8 at addr 0000000000000000 by task syz-executor.0/3661 CPU: 0 PID: 3661 Comm: syz-executor.0 Not tainted 5.1.0+ #28 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 Call Trace: dump_stack+0xa9/0x10e ? __list_del_entry_valid+0x45/0xd0 ? __list_del_entry_valid+0x45/0xd0 __kasan_report+0x171/0x18d ? __list_del_entry_valid+0x45/0xd0 kasan_report+0xe/0x20 __list_del_entry_valid+0x45/0xd0 spi_unregister_controller+0x99/0x1b0 spi_lm70llp_attach+0x3ae/0x4b0 [spi_lm70llp] ? 0xffffffffc1128000 ? klist_next+0x131/0x1e0 ? driver_detach+0x40/0x40 [parport] port_check+0x3b/0x50 [parport] bus_for_each_dev+0x115/0x180 ? subsys_dev_iter_exit+0x20/0x20 __parport_register_driver+0x1f0/0x210 [parport] ? 0xffffffffc1150000 do_one_initcall+0xb9/0x3b5 ? perf_trace_initcall_level+0x270/0x270 ? kasan_unpoison_shadow+0x30/0x40 ? kasan_unpoison_shadow+0x30/0x40 do_init_module+0xe0/0x330 load_module+0x38eb/0x4270 ? module_frob_arch_sections+0x20/0x20 ? kernel_read_file+0x188/0x3f0 ? find_held_lock+0x6d/0xd0 ? fput_many+0x1a/0xe0 ? __do_sys_finit_module+0x162/0x190 __do_sys_finit_module+0x162/0x190 ? __ia32_sys_init_module+0x40/0x40 ? __mutex_unlock_slowpath+0xb4/0x3f0 ? wait_for_completion+0x240/0x240 ? vfs_write+0x160/0x2a0 ? lockdep_hardirqs_off+0xb5/0x100 ? mark_held_locks+0x1a/0x90 ? do_syscall_64+0x14/0x2a0 do_syscall_64+0x72/0x2a0 entry_SYSCALL_64_after_hwframe+0x49/0xbe Reported-by: Hulk Robot Fixes: 702a4879ec33 ("spi: bitbang: Let spi_bitbang_start() take a reference to master") Signed-off-by: YueHaibing Reviewed-by: Geert Uytterhoeven Reviewed-by: Axel Lin Reviewed-by: Mukesh Ojha Signed-off-by: Mark Brown Signed-off-by: Ben Hutchings --- drivers/spi/spi-bitbang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -462,7 +462,7 @@ int spi_bitbang_start(struct spi_bitbang if (ret) spi_master_put(master); - return 0; + return ret; } EXPORT_SYMBOL_GPL(spi_bitbang_start);