Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp248057ybd; Tue, 25 Jun 2019 20:42:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqziazBO+G1Cmvx+06rBT2vmdhFuGKL3aTMQY4ReASuALUuDWpH2f3XSaW3Lsg9M2EF/2i65 X-Received: by 2002:a17:90a:3544:: with SMTP id q62mr1786087pjb.53.1561520530193; Tue, 25 Jun 2019 20:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561520530; cv=none; d=google.com; s=arc-20160816; b=bwxrE01MxPpnx3IxggjQncc2F5cF9uAF5ws7wC5IhEX3xIMGUFwy0IRf+VMHjle3yZ 5CfQBLunK1/yUuzOeXzsZefpw06zNJEkbcXvMU+xw3/JSoRX/FEbxkYGiHqamTwd+xBV RFMP+C/ztZnqT619ADWzD/rNVhjDF/8gBiQDi4pNGpOQT5VumiE+tc67689NpgaiNyM4 VD24EIb3PBtzmzpKVzWV92Om3HL7FKbwpvdO08W/TBH5NBZtSNm9/osawbmBIs8DKiia 4ciHB3iP0wwQ5GYosHagsoOtWdBLTN0cJr9VeAAK8GtN4Y6NxHQ+dJmV3CHe3vW+Rcs3 +kaw== 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=/3n9pViBonuMq6vRxEpKUI4V3EEtsldgypUUu46aPwo=; b=tQCdI8gaLanSbVzzDA/HWi9QMC/OmqzQiKB1Sod1ptwdOS9OvEZzKSwM5R8QxC8uN/ 6luw7rrLZ/OoTd2EvPtT0x4vH63Tm56BRe8oSwRAMlMTxhx+YgJPiR5CHhSuh/AJo97C 2Yv5Fn6s28ww06r0TJaXFIGKbUIGF7IfEYlUWw8KhfumrnlvI/1ywIkxnVWPUUCUipYx ggY1zE/5FblKSYFhT34th4vRIBXa3jN+uL34IFWT5Ii8kp6d5E2xvO7jW8c/hnp6ZB2z kScLyP8j221vHJYNWyHa9hocf6jWQRr9F2Q3LoZb4ZvGxD8cVWFRoaMiISc/I9aIqTjZ sn1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RV2jKSFp; 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 w1si2027072plq.125.2019.06.25.20.41.54; Tue, 25 Jun 2019 20:42:10 -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=RV2jKSFp; 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 S1726793AbfFZDlg (ORCPT + 99 others); Tue, 25 Jun 2019 23:41:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:51924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbfFZDle (ORCPT ); Tue, 25 Jun 2019 23:41:34 -0400 Received: from sasha-vm.mshome.net (mobile-107-77-172-74.mobile.att.net [107.77.172.74]) (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 D629E214DA; Wed, 26 Jun 2019 03:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561520493; bh=uuppBSg3eza1xx49952zPvGnZggmxSRSfmH5l1GAxdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RV2jKSFpNYVBRtT0BSvu7FCT6vwExbXKzKMBuk/PBL8Tk2PqzjRtom5tLtuzfjXCD VqFE2WnT5N1Cy2K4ss4SfUO9Rno+vPa6+CUfRNBfgb/enqcUfvI81cVzbG2JAp7pnj WiiXS6qZUiB/w1Z5j4OSxgBr1y1IPosqYkDtd0L0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: YueHaibing , Hulk Robot , Geert Uytterhoeven , Axel Lin , Mukesh Ojha , Mark Brown , Sasha Levin , linux-spi@vger.kernel.org Subject: [PATCH AUTOSEL 5.1 06/51] spi: bitbang: Fix NULL pointer dereference in spi_unregister_master Date: Tue, 25 Jun 2019 23:40:22 -0400 Message-Id: <20190626034117.23247-6-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190626034117.23247-1-sashal@kernel.org> References: <20190626034117.23247-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 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 dd9a8c54a693..be95be4fe985 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -403,7 +403,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