Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3789230ybi; Mon, 29 Jul 2019 12:39:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrWoY7efLHZKev1S/DviK6syfXG0VcHTm1C4lLoYapZudzlLVxG1DNC4ZbozUjlFdVvNoh X-Received: by 2002:a17:902:2baa:: with SMTP id l39mr112805266plb.280.1564429155433; Mon, 29 Jul 2019 12:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429155; cv=none; d=google.com; s=arc-20160816; b=iozDxR7MukDPUoFo48Iqw6GOhmp1Dbglbw1T4eZ2ymrGyBi53ymYf9MEheX/3P/GxA x8qA0HnGsB9bnOWQY3++zfBk1sj8LpTZp/4C2Tof4o/MbFvsH0FbWHa6DQ5sGjI2M3Zl izVOh/XB/Ck+kbJXlxQ1IV8Vf2zuqbvVHuRFsRHxLd+18kDcTPg+dHcKvPI5yfjHYPAR z265fiNJKR6mzzKEZ67Kmf0A9yplF9xPpLZklKR+UA7VZEv6hRWrDZpZoMh3qHc+xEYa nZmT58pKXCszq7atjEz0aDmVXtvBPz4HKO/XFTB7ghEGBkyJrdsYeVlFFQTva1s5vaE0 tSCg== 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=ZRl7buX/32N//OZdPiIArjroFqf/tw/ITE6YEC30SoqFcEs7RannOiWS2upjq3EcF9 1cdcRr9McRuHWw2d71GCc2dp7v6dr/vOwJ0ygy13nWJPliqrxjuYobEqA/Pu9WV/QGD1 sSvkaJusNoUq4aYA4rthGJLPMJlJf6GD4vkcmlDkx7o/+ALdkSGcZrJm1qplmGnzQ2M5 8cQOUAloLbPX4n9WGC0odUJtPbBH2KIuN50POW2Z7hl2mmsb87QrA9m5OzisH8Vjm4Z0 XwwUguigl490mVc1WN1+59nWjb+DZeaTkTcwDjLMkAXMnUclI23pl4G95zaaCr2UiG70 AdnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="wgDeO/Nj"; 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 m5si24138971pls.358.2019.07.29.12.39.00; Mon, 29 Jul 2019 12:39:15 -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="wgDeO/Nj"; 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 S2388741AbfG2Thj (ORCPT + 99 others); Mon, 29 Jul 2019 15:37:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:52442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388731AbfG2Thg (ORCPT ); Mon, 29 Jul 2019 15:37:36 -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 C1A542171F; Mon, 29 Jul 2019 19:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429055; bh=vPSgSOm/TM2mYA7OWKX8t8dWZRhtAk1thKzepUZ3yic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wgDeO/Nj3RUsfAHW5lXOgQ6B1OBzRfrXbZyruUFvQ4Jv2wQ+fBji7THl8o79of8Or g7bqaqynZuAKmRA/HKrBJ2cTagT2aKePkzuLf8GyzGZrJEm9i68rMNX+qm7vTutMkA a9wnStJYkhkFUzMoNtwGUYtoRPTkdNL725Fc6ZGk= 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.14 232/293] memstick: Fix error cleanup path of memstick_init Date: Mon, 29 Jul 2019 21:22:03 +0200 Message-Id: <20190729190842.262074869@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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