Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3134337ybi; Thu, 18 Jul 2019 21:42:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3qZgJ1CcSfUCUe8tJPQsox8ypyS8Ab1hU6aBGXZdTIQDjqs/3QqEWtWdNG5jpPZ5xPgAl X-Received: by 2002:a17:902:2be8:: with SMTP id l95mr50051225plb.231.1563511329217; Thu, 18 Jul 2019 21:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511329; cv=none; d=google.com; s=arc-20160816; b=Jp/BPliCsiHDKJn9cAUDoG993fWu9vHjmMTjGMqQO/IAHlbRxnidw8zfGr4ITZ0k+v CMkEGs4IWX71c/PnYPXiVOwWs2L419fRFTQ4f9W6InWKZbgaCwgy/p2qcuYAQnemxRxA rNauCmqYMHZKhjDk7JG0VzbYxFhk6l7dkYdoflHqYp7gyD7TX7RssestWeOf78Ray1Zx WARgBmeTmCl0Sq82hUfb0UByAg6PXdc5guYpFK5AKquUmsf7PJRtPz/Y/7MOjCMB8t9w yK0WfnUYv91mQXKJiQ11UO4HzypuNKGJSGE21V5ccYu51XyFMzEy+d/rBS3nERIn2gL7 OgWw== 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=AWRCJVHY0pPcIzhK1VSvlDULQqFVPs924PggCrQk7Gk=; b=RsUymqQ6ZWsVHl6elze0CblIZD05HI6fRd07/sH5YL0iU8WUOsyv6Gjy7xoXf0YLdt /OLu0YYGOLWxa8+eY5bBA4XO6d/MaFR96/UFKXh9xOqZMTGeuHmaUXy5vsgveGmBkLzJ m1VG7TLbp/xq5z4UKnh284GyzdCPIbql2XpuT9KRtG9xi9IOOIBUl/3twac49DFtzIT6 D9LsPi/o9EwCooEGxtBiQFGfDHgFcVGEtaEdbOdyGO1mzuhw/gpEDGKLztl2cyBmpXOg p+5Zm+U2Dq2W4qWfgVHp4S59SR7iNxGnTgLUYiPxsdxYCKAaTTqGZABkTHVKuax2DCaE iFWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oXwsVmm+; 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 j185si262381pfb.107.2019.07.18.21.41.53; Thu, 18 Jul 2019 21:42:09 -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=oXwsVmm+; 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 S1730723AbfGSEjk (ORCPT + 99 others); Fri, 19 Jul 2019 00:39:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:57936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728124AbfGSD6b (ORCPT ); Thu, 18 Jul 2019 23:58:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 87051218B8; Fri, 19 Jul 2019 03:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508711; bh=igEeNZ+76z4NIULmxopOFwPu8PrRx0t2WKt4pJurkWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXwsVmm+4Yyq4MYhjtRKwVVxYI7vl+Ee79f8Y0yYIIkPFzamuOgNjgTP/1uZLqAOE 9XhizH6yRxIHOjf7B4qhL1soaQw/Z4Niefejwl6n5lQFOz1Ax2J4plvKd/We3VZrT7 YpgNBF8Uc0RD334ggCbTT2/XZyxh4WU+ydnYLFAs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wang Hai , Hulk Robot , Ulf Hansson , Sasha Levin , linux-mmc@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 047/171] memstick: Fix error cleanup path of memstick_init Date: Thu, 18 Jul 2019 23:54:38 -0400 Message-Id: <20190719035643.14300-47-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-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: Wang Hai [ 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