From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C0CC4332F for ; Fri, 21 Oct 2022 02:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbiJUCXK (ORCPT ); Thu, 20 Oct 2022 22:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiJUCWz (ORCPT ); Thu, 20 Oct 2022 22:22:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A72A232E54 for ; Thu, 20 Oct 2022 19:22:51 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCN0WmtzHvCB; Fri, 21 Oct 2022 10:22:40 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:40 +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; Fri, 21 Oct 2022 10:22:36 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 01/11] kset: fix documentation for kset_register() Date: Fri, 21 Oct 2022 10:20:52 +0800 Message-ID: <20221021022102.2231464-2-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kset_register() is currently used in some places without calling kset_put() in error path, because the callers think it should be kset internal thing to do, but the driver core can not know what caller doing with that memory at times. The memory could be freed both in kset_put() and error path of caller, if it is called in kset_register(). So make the function documentation more explicit about calling kset_put() in the error path of caller. Signed-off-by: Yang Yingliang --- lib/kobject.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/kobject.c b/lib/kobject.c index a0b2dbfcfa23..6da04353d974 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -834,6 +834,9 @@ EXPORT_SYMBOL_GPL(kobj_sysfs_ops); /** * kset_register() - Initialize and add a kset. * @k: kset. + * + * If this function returns an error, kset_put() must be called to + * properly clean up the memory associated with the object. */ int kset_register(struct kset *k) { --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1313C4332F for ; Fri, 21 Oct 2022 02:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbiJUCWq (ORCPT ); Thu, 20 Oct 2022 22:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiJUCWl (ORCPT ); Thu, 20 Oct 2022 22:22:41 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86D5B1F810F for ; Thu, 20 Oct 2022 19:22:40 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtp7V36sMzpVfQ; Fri, 21 Oct 2022 10:19:18 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:38 +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; Fri, 21 Oct 2022 10:22:37 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 02/11] kset: add null pointer check in kset_put() Date: Fri, 21 Oct 2022 10:20:53 +0800 Message-ID: <20221021022102.2231464-3-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kset_put() can be called from drivers, add null pointer check to make it more robust. Signed-off-by: Yang Yingliang --- include/linux/kobject.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 57fb972fea05..e81de8ba41a2 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -195,7 +195,8 @@ static inline struct kset *kset_get(struct kset *k) =20 static inline void kset_put(struct kset *k) { - kobject_put(&k->kobj); + if (k) + kobject_put(&k->kobj); } =20 static inline const struct kobj_type *get_ktype(struct kobject *kobj) --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26C93C433FE for ; Fri, 21 Oct 2022 02:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiJUCWs (ORCPT ); Thu, 20 Oct 2022 22:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiJUCWm (ORCPT ); Thu, 20 Oct 2022 22:22:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DCE1F813D for ; Thu, 20 Oct 2022 19:22:41 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtp5s2PGmzmVHX; Fri, 21 Oct 2022 10:17:53 +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; Fri, 21 Oct 2022 10:22:39 +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; Fri, 21 Oct 2022 10:22:38 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 03/11] bus: fix possible memory leak in bus_register() Date: Fri, 21 Oct 2022 10:20:54 +0800 Message-ID: <20221021022102.2231464-4-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading module (e.g. edac_core.ko), kset_register() may fail in bus_register(), if it fails, but the refcount of kobject is not decreased to 0, the name allocated in kobject_set_name() is leaked. To fix this by calling kset_put(), so that name can be freed in callback function kobject_cleanup(). unreferenced object 0xffff888103bddb68 (size 8): comm "systemd-udevd", pid 341, jiffies 4294903262 (age 42.212s) hex dump (first 8 bytes): 65 64 61 63 00 00 00 00 edac.... backtrace: [<000000009e31d566>] __kmalloc_track_caller+0x1ae/0x320 [<00000000e4cfd8de>] kstrdup+0x3a/0x70 [<000000003d0ec369>] kstrdup_const+0x68/0x80 [<000000008e5c3b20>] kvasprintf_const+0x10b/0x190 [<00000000b9a945aa>] kobject_set_name_vargs+0x56/0x150 [<000000000df9278c>] kobject_set_name+0xab/0xe0 [<00000000f51dc49f>] bus_register+0x132/0x350 [<000000007d91c2e5>] subsys_register+0x23/0x220 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Yang Yingliang --- drivers/base/bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7ca47e5b3c1f..301b5330f9d8 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -804,8 +804,10 @@ int bus_register(struct bus_type *bus) priv->drivers_autoprobe =3D 1; =20 retval =3D kset_register(&priv->subsys); - if (retval) + if (retval) { + kset_put(&priv->subsys); goto out; + } =20 retval =3D bus_create_file(bus, &bus_attr_uevent); if (retval) --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 490A7C433FE for ; Fri, 21 Oct 2022 02:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbiJUCXR (ORCPT ); Thu, 20 Oct 2022 22:23:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiJUCWy (ORCPT ); Thu, 20 Oct 2022 22:22:54 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D66230AAD for ; Thu, 20 Oct 2022 19:22:50 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCM5YgKzHv3Y; Fri, 21 Oct 2022 10:22:39 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:40 +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; Fri, 21 Oct 2022 10:22:39 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 04/11] kobject: fix possible memory leak in kset_create_and_add() Date: Fri, 21 Oct 2022 10:20:55 +0800 Message-ID: <20221021022102.2231464-5-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading module (e.g. qemu_fw_cfg.ko), kset_register() may fail in kset_create_and_add(), if it fails, but the refcount of kobject is not decreased to 0, the name allocated in kset_create() is leaked. To fix this by calling kset_put(), so that name can be freed in callback function kobject_cleanup() and kset can be freed in kset_release(). unreferenced object 0xffff888103cc8c08 (size 8): comm "modprobe", pid 508, jiffies 4294915182 (age 120.020s) hex dump (first 8 bytes): 62 79 5f 6e 61 6d 65 00 by_name. backtrace: [<00000000572f97f9>] __kmalloc_track_caller+0x1ae/0x320 [<00000000a167a5cc>] kstrdup+0x3a/0x70 [<000000001cd0d05e>] kstrdup_const+0x68/0x80 [<00000000b9101e6d>] kvasprintf_const+0x10b/0x190 [<0000000088f2b8df>] kobject_set_name_vargs+0x56/0x150 [<000000003f8aca68>] kobject_set_name+0xab/0xe0 [<00000000249f7816>] kset_create_and_add+0x72/0x200 Fixes: b727c702896f ("kset: add kset_create_and_add function") Signed-off-by: Yang Yingliang --- lib/kobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kobject.c b/lib/kobject.c index 6da04353d974..e77f37200876 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -985,7 +985,7 @@ struct kset *kset_create_and_add(const char *name, return NULL; error =3D kset_register(kset); if (error) { - kfree(kset); + kset_put(kset); return NULL; } return kset; --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20F12C433FE for ; Fri, 21 Oct 2022 02:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230130AbiJUCYD (ORCPT ); Thu, 20 Oct 2022 22:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbiJUCXk (ORCPT ); Thu, 20 Oct 2022 22:23:40 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDE5204ACB for ; Thu, 20 Oct 2022 19:23:19 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mtp6h5RF0zVhyp; Fri, 21 Oct 2022 10:18:36 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:41 +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; Fri, 21 Oct 2022 10:22:40 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 05/11] class: fix possible memory leak in __class_register() Date: Fri, 21 Oct 2022 10:20:56 +0800 Message-ID: <20221021022102.2231464-6-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading module (e.g. pktcdvd.ko), kset_register() may fail in __class_register(), if it fails, but the refcount of kobject is not decreased to 0, the name allocated in kobject_set_name() is leaked. To fix this by calling kfree_const(). unreferenced object 0xffff888102fa8190 (size 8): comm "modprobe", pid 502, jiffies 4294906074 (age 49.296s) hex dump (first 8 bytes): 70 6b 74 63 64 76 64 00 pktcdvd. backtrace: [<00000000e7c7703d>] __kmalloc_track_caller+0x1ae/0x320 [<000000005e4d70bc>] kstrdup+0x3a/0x70 [<00000000c2e5e85a>] kstrdup_const+0x68/0x80 [<000000000049a8c7>] kvasprintf_const+0x10b/0x190 [<0000000029123163>] kobject_set_name_vargs+0x56/0x150 [<00000000747219c9>] kobject_set_name+0xab/0xe0 [<0000000005f1ea4e>] __class_register+0x15c/0x49a If class_add_groups() fails, it need delete kobject and free its name, besides, subsys_private also need be freed. unreferenced object 0xffff888037274000 (size 1024): comm "modprobe", pid 502, jiffies 4294906074 (age 49.296s) hex dump (first 32 bytes): 00 40 27 37 80 88 ff ff 00 40 27 37 80 88 ff ff .@'7.....@'7.... 00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N.......... backtrace: [<00000000151f9600>] kmem_cache_alloc_trace+0x17c/0x2f0 [<00000000ecf3dd95>] __class_register+0x86/0x49a It can not call kset_put() or kset_unregister() in error path, because the 'cls' will be freed in callback function class_release() and it also freed in error path, it will cause double free. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Yang Yingliang --- drivers/base/class.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/class.c b/drivers/base/class.c index 64f7b9a0970f..87de0a04ee9b 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -187,11 +187,17 @@ int __class_register(struct class *cls, struct lock_c= lass_key *key) =20 error =3D kset_register(&cp->subsys); if (error) { + kfree_const(cp->subsys.kobj.name); kfree(cp); return error; } error =3D class_add_groups(class_get(cls), cls->class_groups); class_put(cls); + if (error) { + kobject_del(&cp->subsys.kobj); + kfree_const(cp->subsys.kobj.name); + kfree(cp); + } return error; } EXPORT_SYMBOL_GPL(__class_register); --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89F80C43219 for ; Fri, 21 Oct 2022 02:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiJUCWw (ORCPT ); Thu, 20 Oct 2022 22:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiJUCWo (ORCPT ); Thu, 20 Oct 2022 22:22:44 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09657226580 for ; Thu, 20 Oct 2022 19:22:44 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Mtp5w3XNvz1P7D4; Fri, 21 Oct 2022 10:17:56 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:42 +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; Fri, 21 Oct 2022 10:22:41 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 06/11] firmware: qemu_fw_cfg: fix possible memory leak in fw_cfg_build_symlink() Date: Fri, 21 Oct 2022 10:20:57 +0800 Message-ID: <20221021022102.2231464-7-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading 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. To fix this by calling kset_put(), so that name can be freed in callback function kobject_cleanup() and 'subdir' is freed in kset_release(). unreferenced object 0xffff88810ad69050 (size 8): comm "swapper/0", pid 1, jiffies 4294677178 (age 38.812s) hex dump (first 8 bytes): 65 74 63 00 81 88 ff ff etc..... backtrace: [<00000000a80c7bf1>] __kmalloc_node_track_caller+0x44/0x1b0 [<000000003f0167c7>] kstrdup+0x3a/0x70 [<0000000049336709>] kstrdup_const+0x41/0x60 [<00000000175616e4>] kvasprintf_const+0xf5/0x180 [<000000004bcc30f7>] kobject_set_name_vargs+0x56/0x150 [<000000004b0251bd>] kobject_set_name+0xab/0xe0 [<00000000700151fb>] fw_cfg_sysfs_probe+0xa5b/0x1320 Fixes: 246c46ebaeae ("firmware: create directory hierarchy for sysfs fw_cfg= entries") Signed-off-by: Yang Yingliang --- drivers/firmware/qemu_fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index a69399a6b7c0..d036e69cabbb 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -544,7 +544,7 @@ static int fw_cfg_build_symlink(struct kset *dir, } ret =3D kset_register(subdir); if (ret) { - kfree(subdir); + kset_put(subdir); break; } =20 --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00538C433FE for ; Fri, 21 Oct 2022 02:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbiJUCW5 (ORCPT ); Thu, 20 Oct 2022 22:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbiJUCWr (ORCPT ); Thu, 20 Oct 2022 22:22:47 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0656522BAEA for ; Thu, 20 Oct 2022 19:22:45 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtp7b16HRzpVdt; Fri, 21 Oct 2022 10:19:23 +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; Fri, 21 Oct 2022 10:22:43 +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; Fri, 21 Oct 2022 10:22:42 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 07/11] f2fs: fix possible memory leak in f2fs_init_sysfs() Date: Fri, 21 Oct 2022 10:20:58 +0800 Message-ID: <20221021022102.2231464-8-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading 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 0xffff888101b7cc80 (size 8): comm "modprobe", pid 252, jiffies 4294691378 (age 31.760s) hex dump (first 8 bytes): 66 32 66 73 00 88 ff ff f2fs.... backtrace: [<000000001db5b408>] __kmalloc_node_track_caller+0x44/0x1b0 [<000000002783a073>] kstrdup+0x3a/0x70 [<00000000ead2b281>] kstrdup_const+0x63/0x80 [<000000003e5cf8f7>] kvasprintf_const+0x149/0x180 [<00000000c4d949ff>] kobject_set_name_vargs+0x56/0x150 [<0000000044611660>] kobject_set_name+0xab/0xe0 Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry") Signed-off-by: Yang Yingliang Reviewed-by: Chao Yu --- fs/f2fs/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index df27afd71ef4..2ef7a48967be 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1250,8 +1250,10 @@ int __init f2fs_init_sysfs(void) kobject_set_name(&f2fs_kset.kobj, "f2fs"); f2fs_kset.kobj.parent =3D fs_kobj; ret =3D kset_register(&f2fs_kset); - if (ret) + if (ret) { + kset_put(&f2fs_kset); return ret; + } =20 ret =3D kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, NULL, "features"); --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BD23C4332F for ; Fri, 21 Oct 2022 02:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbiJUCXY (ORCPT ); Thu, 20 Oct 2022 22:23:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiJUCWz (ORCPT ); Thu, 20 Oct 2022 22:22:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE54232E4F for ; Thu, 20 Oct 2022 19:22:50 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCN18FmzHvCF; Fri, 21 Oct 2022 10:22:40 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:44 +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; Fri, 21 Oct 2022 10:22:43 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 08/11] erofs: fix possible memory leak in erofs_init_sysfs() Date: Fri, 21 Oct 2022 10:20:59 +0800 Message-ID: <20221021022102.2231464-9-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inject fault while loading 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 =3D fs_kobj; ret =3D kset_register(&erofs_root); - if (ret) + if (ret) { + kset_put(&erofs_root); goto root_err; + } =20 ret =3D kobject_init_and_add(&erofs_feat, &erofs_feat_ktype, NULL, "features"); --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1666319046; cv=none; d=zohomail.com; s=zohoarc; b=HvZOL4ItX44vi1C90L7zD38rFiC9PCo1NecrAAmvHWyofMRHckeh9kLbTYmfBj80X/HknGg4V0MfjADRhbsPB054JZphoyJQ1bp+FiAf9WFTcx7c9eR58D/kYaJBye5MoxVTqZ3kQAbffu/Y6GjdRt2WQ9Fw0I9JgoQx4+7DJJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666319046; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xzMFxLeFKUbQzHCjgeZFy2Z3JsN/mOjM/Yn4m8OkMjM=; b=FUahfrhaYuvWNdDXQ88M79Z1LADjjTDT+npMQ6QMMS9Bh3h3TM+zLl/WiZFHX0DpydsEzsRd8v7+bwa2ZbgcgLY6hGrGCtuffpEC+e+XN+EMAvXEh+rH1Wpv12olmlalCbdDOuswQJA/qkgyq3Qo5y0XGK9Zn2oxHLcvm5oVAWo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666319046799294.2295847387609; Thu, 20 Oct 2022 19:24:06 -0700 (PDT) Received: from localhost ([::1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olhhd-0004cZ-Al for importer@patchew.org; Thu, 20 Oct 2022 22:24:05 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olhh5-0004WG-6O for importer@patchew.org; Thu, 20 Oct 2022 22:23:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olhgz-0004VJ-7q for qemu-devel@nongnu.org; Thu, 20 Oct 2022 22:23:25 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olhgv-0003WW-5L for qemu-devel@nongnu.org; Thu, 20 Oct 2022 22:23:23 -0400 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mtp6h64dWzVj27; Fri, 21 Oct 2022 10:18:36 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:45 +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; Fri, 21 Oct 2022 10:22:44 +0800 To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 09/11] ocfs2: possible memory leak in mlog_sys_init() Date: Fri, 21 Oct 2022 10:21:00 +0800 Message-ID: <20221021022102.2231464-10-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=yangyingliang@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Yang Yingliang From: Yang Yingliang via X-ZM-MESSAGEID: 1666319047994100001 Content-Type: text/plain; charset="utf-8" Inject fault while loading 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 0xffff888100da9348 (size 8): comm "modprobe", pid 257, jiffies 4294701096 (age 33.334s) hex dump (first 8 bytes): 6c 6f 67 6d 61 73 6b 00 logmask. backtrace: [<00000000306e441c>] __kmalloc_node_track_caller+0x44/0x1b0 [<000000007c491a9e>] kstrdup+0x3a/0x70 [<0000000015719a3b>] kstrdup_const+0x63/0x80 [<0000000084e458ea>] kvasprintf_const+0x149/0x180 [<0000000091302b42>] kobject_set_name_vargs+0x56/0x150 [<000000005f48eeac>] kobject_set_name+0xab/0xe0 Fixes: 34980ca8faeb ("Drivers: clean up direct setting of the name of a kse= t") Signed-off-by: Yang Yingliang --- fs/ocfs2/cluster/masklog.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index 563881ddbf00..7f9ba816d955 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c @@ -156,6 +156,7 @@ static struct kset mlog_kset =3D { int mlog_sys_init(struct kset *o2cb_kset) { int i =3D 0; + int ret; =20 while (mlog_attrs[i].attr.mode) { mlog_default_attrs[i] =3D &mlog_attrs[i].attr; @@ -165,7 +166,11 @@ int mlog_sys_init(struct kset *o2cb_kset) =20 kobject_set_name(&mlog_kset.kobj, "logmask"); mlog_kset.kobj.kset =3D o2cb_kset; - return kset_register(&mlog_kset); + ret =3D kset_register(&mlog_kset); + if (ret) + kset_put(&mlog_kset); + + return ret; } =20 void mlog_sys_shutdown(void) --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62939C43219 for ; Fri, 21 Oct 2022 02:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiJUCXF (ORCPT ); Thu, 20 Oct 2022 22:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiJUCWu (ORCPT ); Thu, 20 Oct 2022 22:22:50 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA5512248E8 for ; Thu, 20 Oct 2022 19:22:48 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCK4pJ1zHvCk; Fri, 21 Oct 2022 10:22:37 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:46 +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; Fri, 21 Oct 2022 10:22:45 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 10/11] drm/amdgpu/discovery: fix possible memory leak Date: Fri, 21 Oct 2022 10:21:01 +0800 Message-ID: <20221021022102.2231464-11-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If kset_register() fails, the refcount of kobject is not 0, the name allocated in kobject_set_name(&kset.kobj, ...) is leaked. Fix this by calling kset_put(), so that it will be freed in callback function kobject_cleanup(). Cc: stable@vger.kernel.org Fixes: a6c40b178092 ("drm/amdgpu: Show IP discovery in sysfs") Signed-off-by: Yang Yingliang Reviewed-by: Luben Tuikov --- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/dr= m/amd/amdgpu/amdgpu_discovery.c index 3993e6134914..638edcf70227 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c @@ -863,7 +863,7 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_dev= ice *adev, res =3D kset_register(&ip_hw_id->hw_id_kset); if (res) { DRM_ERROR("Couldn't register ip_hw_id kset"); - kfree(ip_hw_id); + kset_put(&ip_hw_id->hw_id_kset); return res; } if (hw_id_names[ii]) { @@ -954,7 +954,7 @@ static int amdgpu_discovery_sysfs_recurse(struct amdgpu= _device *adev) res =3D kset_register(&ip_die_entry->ip_kset); if (res) { DRM_ERROR("Couldn't register ip_die_entry kset"); - kfree(ip_die_entry); + kset_put(&ip_die_entry->ip_kset); return res; } =20 @@ -989,6 +989,7 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_de= vice *adev) res =3D kset_register(&adev->ip_top->die_kset); if (res) { DRM_ERROR("Couldn't register die_kset"); + kset_put(&adev->ip_top->die_kset); goto Err; } =20 --=20 2.25.1 From nobody Sat May 18 05:53:15 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E05C0C3A589 for ; Fri, 21 Oct 2022 02:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbiJUCXC (ORCPT ); Thu, 20 Oct 2022 22:23:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbiJUCWu (ORCPT ); Thu, 20 Oct 2022 22:22:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD90229E64 for ; Thu, 20 Oct 2022 19:22:48 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtp605R63zmVCd; Fri, 21 Oct 2022 10:18:00 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:46 +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; Fri, 21 Oct 2022 10:22:46 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 11/11] ubifs: Fix memory leak in ubifs_sysfs_init() Date: Fri, 21 Oct 2022 10:21:02 +0800 Message-ID: <20221021022102.2231464-12-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Liu Shixin When insmod ubifs.ko, a kmemleak reported as below: unreferenced object 0xffff88817fb1a780 (size 8): comm "insmod", pid 25265, jiffies 4295239702 (age 100.130s) hex dump (first 8 bytes): 75 62 69 66 73 00 ff ff ubifs... backtrace: [] slab_post_alloc_hook+0x9c/0x3c0 [] __kmalloc_track_caller+0x183/0x410 [] kstrdup+0x3a/0x80 [] kstrdup_const+0x66/0x80 [] kvasprintf_const+0x155/0x190 [] kobject_set_name_vargs+0x5b/0x150 [] kobject_set_name+0xbb/0xf0 [] do_one_initcall+0x14c/0x5a0 [] do_init_module+0x1f0/0x660 [] load_module+0x6d7e/0x7590 [] __do_sys_finit_module+0x19f/0x230 [] __x64_sys_finit_module+0x73/0xb0 [] do_syscall_64+0x35/0x80 [] entry_SYSCALL_64_after_hwframe+0x63/0xcd When kset_register() failed, we should call kset_put to cleanup it. Fixes: 2e3cbf425804 ("ubifs: Export filesystem error counters") Signed-off-by: Liu Shixin Signed-off-by: Yang Yingliang --- fs/ubifs/sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ubifs/sysfs.c b/fs/ubifs/sysfs.c index 06ad8fa1fcfb..54270ad36321 100644 --- a/fs/ubifs/sysfs.c +++ b/fs/ubifs/sysfs.c @@ -144,6 +144,8 @@ int __init ubifs_sysfs_init(void) kobject_set_name(&ubifs_kset.kobj, "ubifs"); ubifs_kset.kobj.parent =3D fs_kobj; ret =3D kset_register(&ubifs_kset); + if (ret) + kset_put(&ubifs_kset); =20 return ret; } --=20 2.25.1