Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23320C4332F for ; Tue, 18 Oct 2022 07:41:05 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ms5Q81mL8z3c2N for ; Tue, 18 Oct 2022 18:41:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ozlabs.org; s=201707; t=1666078864; bh=mRCWfaHgwGA1JNCyES2+dKHA4gqpMRRooEjQ6Jm9ZHU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ecuy/IFpwT2jbS48HrIEsWBvaxA8zPS5TVK8TcgIo9ABiJVBjt3Wm+7h181LeTaYt 3IphBYVUUVDFTAfnTVXgPaTNIIogqx33g1AyZ5Z5sVJFIypTUFbICV1/VwwWRR2QK4 yo2EmSRajRVhgAlbwgziw9N2ZGi+bXbZvW9Bk44yBKKuhG0T07C2KdJDGDc+Rd8QIU 6PkL3xYbdwFAUQZv4LiIFZy5sFxhY/fOhxZ9nF3+szy74XX+uAVaCaBvDET08wpTDv NN2EdIqhfoFv/wPDU3uAruxtuLW73KSRhuBNeLBemI3DCy/zApPdXV3ijbxU80SsuY O0Pd9i9fnqRnw== Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=45.249.212.189; helo=szxga03-in.huawei.com; envelope-from=yangyingliang@huawei.com; receiver=) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Ms5Py1R1Cz2xy6 for ; Tue, 18 Oct 2022 18:40:49 +1100 (AEDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Ms5Lj2XgRzJn36; Tue, 18 Oct 2022 15:38:05 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 18 Oct 2022 15:40:25 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 18 Oct 2022 15:40:25 +0800 To: Subject: [PATCH] erofs: fix possible memory leak in erofs_init_sysfs() Date: Tue, 18 Oct 2022 15:39:47 +0800 Message-ID: <20221018073947.693206-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Yang Yingliang via Linux-erofs Reply-To: Yang Yingliang Cc: yangyingliang@huawei.com, hsiangkao@linux.alibaba.com, huangjianan@oppo.com Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" Inject fault while probing module, kset_register() may fail, if it fails, but the refcount of kobject is not decreased to 0, the name allocated in kobject_set_name() is leaked. Fix this by calling kset_put(), so that name can be freed in callback function kobject_cleanup(). unreferenced object 0xffff888101d228c0 (size 8): comm "modprobe", pid 276, jiffies 4294722700 (age 13.151s) hex dump (first 8 bytes): 65 72 6f 66 73 00 ff ff erofs... backtrace: [<00000000e2a9a4a6>] __kmalloc_node_track_caller+0x44/0x1b0 [<00000000b8ce02de>] kstrdup+0x3a/0x70 [<000000004a0e01d2>] kstrdup_const+0x63/0x80 [<00000000051b6cda>] kvasprintf_const+0x149/0x180 [<000000004dc51dad>] kobject_set_name_vargs+0x56/0x150 [<00000000b30f0bad>] kobject_set_name+0xab/0xe0 Fixes: 168e9a76200c ("erofs: add sysfs interface") Signed-off-by: Yang Yingliang --- fs/erofs/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index 783bb7b21b51..653b35001bc5 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -254,8 +254,10 @@ int __init erofs_init_sysfs(void) kobject_set_name(&erofs_root.kobj, "erofs"); erofs_root.kobj.parent = fs_kobj; ret = kset_register(&erofs_root); - if (ret) + if (ret) { + kset_put(&erofs_root); goto root_err; + } ret = kobject_init_and_add(&erofs_feat, &erofs_feat_ktype, NULL, "features"); -- 2.25.1