Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1180861ybi; Fri, 2 Aug 2019 10:39:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ9czLWivX0CmA+e28P3ny0yNdZELqDGOymI3HQQlgnf391xpG3NoNmRX1AlFQlBoCOlji X-Received: by 2002:a17:902:2ae8:: with SMTP id j95mr121680049plb.276.1564767544365; Fri, 02 Aug 2019 10:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564767544; cv=none; d=google.com; s=arc-20160816; b=b2TNEpz7sxgy9E9OHvaOqmSYmrM06jXVoQqwWlg6EKKHJ/swHp130IvQn+Gkin82Uu K7RJ6aT9sbCY/B9QUnnB25I6iFOyDP1Yik/6ZUb3dcHybb43Cz0kicrvrTK8QgMohqzR 8T0org6iQukjmBIrgmWWmaT6G8Xv2xZyjz0NF5jGHS8Vuu+rxyWvMoTWyjaUEMItyz/u ELm8a4SEdhz6kCEJ78IVjJ5bsTNtADz3xidN0l4OLLWDeWf1zvPbOslImeRi3MEZ3t7a jVq8juPG3XKFLIm9tRvNsz8tSuz50y9N/+D11Sye/rwoF2/GDMquD9VO4MkZmAWHaJqr US+g== 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=ZczUlvDEVqnfVkDUK4BChOR6Ft2c9QOqKIVMSz45bsA=; b=pOZAPFXnLGCcJFdi9hHISpIKe2ijJ2sCDfcf+1nMF2uCpFTADTVfd1KvN7ZO6m8rC7 CW25llFdI63Ww1MvO6ByaWxQJhTXBBhKkLZZVVrEa6E9njNkVZdZZcCcZfnm3nqf2gN6 2Hv0HXAq5N+ZOfgmG4kQ1fBYB3SuuKkGmZnPdvf9QH0zJe4Fo+Jyu7APX/h1tDYQojRA +5eMwunjn6oT96L7ghPhO1u7ovEU1zauwSQEG2ys30mAjWS2KkjNwIqYcSpZRHehgDqn hOaawNmIF05eXiHCSaAcmWFFTwX8L2VeYCZXlAmsQxTxH1rjfTMCD8K5Nr4cIlK2ihQl CG1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PZ1Xl6fW; 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 y84si45197029pfc.33.2019.08.02.10.38.48; Fri, 02 Aug 2019 10:39:04 -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=PZ1Xl6fW; 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 S2405901AbfHBJsp (ORCPT + 99 others); Fri, 2 Aug 2019 05:48:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:54152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405878AbfHBJsl (ORCPT ); Fri, 2 Aug 2019 05:48:41 -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 307E72087E; Fri, 2 Aug 2019 09:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739320; bh=1l0EAHHLvUwKDNyHuZOGsTVAkJXPM1btSYpS8ZVJubE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PZ1Xl6fWGZ7GPqupVCR8orx5EI3N1hymX9G2DwU7o4/ig/R/ndZWeFXCySm/bszbf H9RncAI5sDggm+Hm1fitofpFsiEZnA3pXhdUo1X8aktiCOcHSTy9hwvlZOR2J9fCTx Ez7XwCA9hVSsbl31sYEVNyJAqwHCTqyT1YRuZ/8Q= 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.9 166/223] memstick: Fix error cleanup path of memstick_init Date: Fri, 2 Aug 2019 11:36:31 +0200 Message-Id: <20190802092248.818904494@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 4d673a626db4..1041eb7a6167 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