Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7152111ybi; Mon, 8 Jul 2019 15:41:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqw68I3TWpKTkW6oyKVDRiValqJ2QRkPi52MjK2RWcsfFdidt2JWdRAfTXeiIY9ix0GgLbu1 X-Received: by 2002:a65:51cb:: with SMTP id i11mr25740800pgq.390.1562625715688; Mon, 08 Jul 2019 15:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625715; cv=none; d=google.com; s=arc-20160816; b=rFXoMTDrZf+4gpvwLOqTUy21eF/xF8rMHeY/XysLpbMPoR+ksQT34XgxArMAgSm3N2 jZRVUnr9sFv4lU6OIZRU6xmlsU45rRfsHl0DDmVECbxDbTKU6RHKQJlRAPuP6l5ks1QL uBwJBWjYVK1z0+V/ZSxx7J0bbYelcISE8/sXXLdrt1vDtLgQ0qHPrkg0fZn1jENwyCX4 LK51uNZliWP7fJ5e8k2WAfIR39SDKBY+npDNHgGuy+Sx2T+YNBgR53h4lerXI4+yiKwh ku6UgcPvTISnygWPEcnR/RIB7uTtXmS05kYwV+mUY9khrvxCo7OD6TN8FiX+7XGi2TD4 CuSA== 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=e0b4VHiSvc6QXkA51JSSb+z67BBAD4vh1ky3ULhmDNE=; b=C5Mn9SKWnyYlivFzIxs4DOiKDR+jI2OkG4fBHn002986D+EhJME6nAU0eCpfdxcwYi Es20nXqwJ7lB+n5WY52k9wOVz5bouOK0rAc4AnSQpJdjwAxeYYQ9ksCLSb1CWQVdzcGk 3xmI1BwNVx2Hbm2H/5kMp4sJaFk5nXzP2wnlOR7kzKbeYuz86oMKJwtAsx1ubmRc5wKV qYtHbGtfvZclYYQn6GTGiZERKfSM/hOF47j8E6HW+VEc7EicPni/PTKSEZYR0hb4rUc8 GZZHmxnCKH9uqU9TOvRDlbdOc1+rA/BC6uKs/e228chUTToNPHbBhgjlHeK7REPYYR7W IypQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J2UZFyQ6; 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 136si18794289pgg.354.2019.07.08.15.41.41; Mon, 08 Jul 2019 15:41:55 -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; dkim=pass header.i=@kernel.org header.s=default header.b=J2UZFyQ6; 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 S2391184AbfGHPny (ORCPT + 99 others); Mon, 8 Jul 2019 11:43:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:50954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388249AbfGHPXs (ORCPT ); Mon, 8 Jul 2019 11:23:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 5BD62204EC; Mon, 8 Jul 2019 15:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599427; bh=UqYaX4fyRfNX1yoi0yvqj0iqzoEcaynzbhGcyc602uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2UZFyQ68o5TqHmT8dFbCS7ii/w+tuynzg3LRSLOHRiC8d6N4moExhruAWZge6L+2 lfUhl75Ie90BhROy7R8PHu/K5fO/2kaxAL5ITwEVI9uAQN6MDepZnVkx1+civ69wyD pti4LvZMi4aGLyNERpFEB1he8Q/DtutWwm/3CQnQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , YueHaibing , Geert Uytterhoeven , Axel Lin , Mukesh Ojha , Mark Brown , Sasha Levin Subject: [PATCH 4.14 04/56] spi: bitbang: Fix NULL pointer dereference in spi_unregister_master Date: Mon, 8 Jul 2019 17:12:56 +0200 Message-Id: <20190708150517.470067346@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@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 [ Upstream commit 5caaf29af5ca82d5da8bc1d0ad07d9e664ccf1d8 ] 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: Sasha Levin --- drivers/spi/spi-bitbang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index 3aa9e6e3dac8..4ef54436b9d4 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -392,7 +392,7 @@ int spi_bitbang_start(struct spi_bitbang *bitbang) if (ret) spi_master_put(master); - return 0; + return ret; } EXPORT_SYMBOL_GPL(spi_bitbang_start); -- 2.20.1