Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3814015ybi; Mon, 29 Jul 2019 13:08:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2M7OkrersdiKyDK+AkgPfnGqmWQhf2mjsdH0FfjK78flO8yruKjnqBOmrtX0RIvuyeYNf X-Received: by 2002:a17:902:fa2:: with SMTP id 31mr113623848plz.38.1564430912523; Mon, 29 Jul 2019 13:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430912; cv=none; d=google.com; s=arc-20160816; b=TbTJOxeUmb2ZFJGHzqGLU0hji8NxcBxqxcmXwPuIVRQ0sUsrXXc3u9GnBSiTTeKnot eiPCPeADw5cdPX4SJ4chlL/ekP3U6omuzNcIw3nxvYiecus8I35I9xpsR7XWivY13UBy +Cu0tRujCFKApaNbROQ90xH9vBpwQ6Xp2ZrVPgzq6//wJYsPVno6ISOp12wIZ4IM08mz obLI9iC+m1cdeEncpMN4L8BXXmj+UDPZa0Q95tYnA5OUJrhHBxV+QF2sUYMxlpcgCp88 2R+GCZJEx8mDVKxIU4Mtzpa1fkHnjGyZxazMQoYwqEozypoWV8qhpwr5sMsv8oD+94DN 9Q9w== 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=ocljPhTiFfmWxuOYsGOfad5z/tUZalB5hwgm9kJB/iE=; b=el1yqWHnV6MIfVFlB0mGK1t4gSeJaBb6FuY2/2Kh8iVBHD63dz1oi2io9tB2CfCMXl Wt7gGQnYEf3LP92PzCEvIZI2mZhBS6cDfikuk+SQFHvcVqhKzeqa7jVNFJYl5VMibKs9 XmbyYMtvLbo2FPumF3DPLf6BPR9DSzIJ1WcF168P4HGPn5SSmWFc8zTU7SqRKEl/VSbW 6gQy9idyS05OdC0e8awDfHqRXl1fvhvjYxxQeDoqRyjcC2tNBOi1C/kmva7CtMm8t/5q CCGsMzDSJo+zQCSXDqbtPfYFnOQ781KzoqPjIKcCZm/aTV8ceIKNTn9hAg3T1zGCZCVx noaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZt1rStP; 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 145si27266326pgh.320.2019.07.29.13.08.17; Mon, 29 Jul 2019 13:08:32 -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=LZt1rStP; 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 S2389089AbfG2TkC (ORCPT + 99 others); Mon, 29 Jul 2019 15:40:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:55216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388267AbfG2Tj7 (ORCPT ); Mon, 29 Jul 2019 15:39:59 -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 9DE69217D4; Mon, 29 Jul 2019 19:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429199; bh=vPSgSOm/TM2mYA7OWKX8t8dWZRhtAk1thKzepUZ3yic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZt1rStPaYD2kgBQ/Gy/aIhi15PbV0NFaNuta4k5AM6c4hXdVT2da/cJNmpv9Ij6v +SN0Q1R6DascIIp3eLGuFHXoFaVplFssIH+326qzEc+au5wG1nAQwuhjcJWwA4Q6Bh WKcl4C+21AuV6JK8/jNyqqmA/x6GZaErvT2ha9SI= 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 4.19 022/113] memstick: Fix error cleanup path of memstick_init Date: Mon, 29 Jul 2019 21:21:49 +0200 Message-Id: <20190729190701.147254323@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 1246d69ba187..b1564cacd19e 100644 --- a/drivers/memstick/core/memstick.c +++ b/drivers/memstick/core/memstick.c @@ -629,13 +629,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