Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3811459ybi; Mon, 29 Jul 2019 13:05:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOEC8YsURn+KK/SnLUMRzLEAXPmXs064POqEoHddd6qbh5utJHwgcUSS/sXz0uSg6lRvMS X-Received: by 2002:a62:ce8e:: with SMTP id y136mr38911119pfg.29.1564430750280; Mon, 29 Jul 2019 13:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430750; cv=none; d=google.com; s=arc-20160816; b=GrS8hMUXYfUcjjw6sbOXMH09nZR6dug8zGmDtiDESGNZ+OT2Iw7ydm2e/P4vBp3Ig2 hxsGR8xjpzHfyQpKwspsgXP7EIStNkY+5aYxE6fmSNz1ByFgmPSHWbeSt+PEC7tj78y4 WhPh1A8rxhEVYdCemiEyZvTRleX1Ar6OiJfWd+00KotIyEm6RStbSGeXu/xCObm8nkCQ fkD9/1ddbunFFhX/7s95YPtNJq9IDOEnlh9GPosl3fUllviem6eIK+JUNEpyxwiv3YqO /ZMHVybY9Lbn/qkHYQLU99Tz518NFijQJSYGxFjFn5NNn8f/idE34eRrK+89LmcOzeFv 5Vqw== 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=DS5YT8uQpWKsSce5tIGj8aSJNMstmZg2Unhv43T40g8=; b=NM2cw4j6JX6iI6tYO+FVRWsCdYqWsouSBacBMTymdeDFrXggcIP7C/+kL4hu6x+3Vs p0FvkDYqz098sCaVjnSWZLXwYyvHtFl2pyLujVqr50ErFS8q94KCa/DNQRc/cjPqOLWZ wBkZyZ1AtzpjVLdri9Pl7VFooaQwKbD2HWNbww9aiddh3YUB3L6cfpl1Y3+d3uGjZmbu XaOABpNBC78fl8xb6iqCf7Q17I4TRchbNNNm8UYPXbPNbUaAK3TvJOxmFHeWXcObGUpX u1lMpbBRkynhOkZpIIz39/FYo3Ke+WfZoyYEfhrB2DyTdz3lbIQ+45IP4zrXKpsrq5NN iV8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jLmPTUBS; 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 u4si28814176pgb.218.2019.07.29.13.05.34; Mon, 29 Jul 2019 13:05:50 -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=jLmPTUBS; 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 S2390304AbfG2Tr0 (ORCPT + 99 others); Mon, 29 Jul 2019 15:47:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:37056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389476AbfG2TrW (ORCPT ); Mon, 29 Jul 2019 15:47:22 -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 A49FD21655; Mon, 29 Jul 2019 19:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429642; bh=DwiTYpHToriGmCvggj76p9zkk9aM82mDOnrbNXFfG/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLmPTUBSWUMguK02F5t50BUucVg3/MPmE91RoBNUDBpJ9Na6xXUR9jzihKG8rjma0 1UX7Y7O1i+W/RMv/8+EjzCGJEm6jlMe3AYZPMup8K7+gvkpDa2SfNDFZecDLpRM3qS rO3QCSJuaXWH4di7TQK7J7sw6TMNmtf86792f4pg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Wang Hai , Ulf Hansson , Sasha Levin Subject: [PATCH 5.2 049/215] memstick: Fix error cleanup path of memstick_init Date: Mon, 29 Jul 2019 21:20:45 +0200 Message-Id: <20190729190749.009083340@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 65f1a0d39c289bb6fc85635528cd36c4b07f560e ] If bus_register fails. On its error handling path, it has cleaned up what it has done. There is no need to call bus_unregister again. Otherwise, if bus_unregister is called, issues such as null-ptr-deref will arise. Syzkaller report this: kobject_add_internal failed for memstick (error: -12 parent: bus) BUG: KASAN: null-ptr-deref in sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467 Read of size 8 at addr 0000000000000078 by task syz-executor.0/4460 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xa9/0x10e lib/dump_stack.c:113 __kasan_report+0x171/0x18d mm/kasan/report.c:321 kasan_report+0xe/0x20 mm/kasan/common.c:614 sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467 sysfs_remove_file include/linux/sysfs.h:519 [inline] bus_remove_file+0x6c/0x90 drivers/base/bus.c:145 remove_probe_files drivers/base/bus.c:599 [inline] bus_unregister+0x6e/0x100 drivers/base/bus.c:916 ? 0xffffffffc1590000 memstick_init+0x7a/0x1000 [memstick] do_one_initcall+0xb9/0x3b5 init/main.c:914 do_init_module+0xe0/0x330 kernel/module.c:3468 load_module+0x38eb/0x4270 kernel/module.c:3819 __do_sys_finit_module+0x162/0x190 kernel/module.c:3909 do_syscall_64+0x72/0x2a0 arch/x86/entry/common.c:298 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fixes: baf8532a147d ("memstick: initial commit for Sony MemoryStick support") Reported-by: Hulk Robot Signed-off-by: Wang Hai Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/memstick/core/memstick.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c index 6cfb293396f2..693ee73eb291 100644 --- a/drivers/memstick/core/memstick.c +++ b/drivers/memstick/core/memstick.c @@ -625,13 +625,18 @@ static int __init memstick_init(void) return -ENOMEM; rc = bus_register(&memstick_bus_type); - if (!rc) - rc = class_register(&memstick_host_class); + if (rc) + goto error_destroy_workqueue; - if (!rc) - return 0; + rc = class_register(&memstick_host_class); + if (rc) + goto error_bus_unregister; + + return 0; +error_bus_unregister: bus_unregister(&memstick_bus_type); +error_destroy_workqueue: destroy_workqueue(workqueue); return rc; -- 2.20.1