From nobody Mon Feb 9 15:19:41 2026 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=1666015894; cv=none; d=zohomail.com; s=zohoarc; b=IZW0SylW1tYZod0sT0nz6BONgkk86qZbjyO8b6gs6GB27T8pN0XvMVxuuDcq2NFiCs2nc8gQBeoB78Mg6JflbAzxmTmoFbe4rfnzf9+T4byr8pS7hYkPTBBu1vrerhq9mAvMEFTi4swrqy00zts1aP330+708ByC5h34K6zdofY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666015894; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=auAaR2rcwcC2TNmTB23p+VjxALKiBPmN6wV5io15T0I=; b=hiAyb7+3hdhJ6O75R9G7TP0brglHeHaYpIA6pccN8Tf/+YlBDSL2UmZ2RMimvPxyg8p5i5DWDRVPBQTEMCd6G2/RayfIfTF27RSEMfRYiq3PUbDr2mTi5rTlN7meraxrbMvE0AdbkZFjpeeULuG2dMfK/AZLqkSp2B63UcylMcw= 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 1666015894173731.0496983488428; Mon, 17 Oct 2022 07:11:34 -0700 (PDT) Received: from localhost ([::1]:47404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okQq3-0001sM-0a for importer@patchew.org; Mon, 17 Oct 2022 10:11:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okQI6-0003iv-2x for qemu-devel@nongnu.org; Mon, 17 Oct 2022 09:36:27 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:6094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okQI2-0004ok-HY for qemu-devel@nongnu.org; Mon, 17 Oct 2022 09:36:25 -0400 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MrdL74xgYzHtwF; Mon, 17 Oct 2022 21:35:59 +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; Mon, 17 Oct 2022 21:36:05 +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; Mon, 17 Oct 2022 21:36:04 +0800 To: CC: , , , Subject: [PATCH] firmware: qemu_fw_cfg: fix possible memory leak in fw_cfg_build_symlink() Date: Mon, 17 Oct 2022 21:35:26 +0800 Message-ID: <20221017133526.108812-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 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-Mailman-Approved-At: Mon, 17 Oct 2022 10:00:18 -0400 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: 1666015895096100001 Content-Type: text/plain; charset="utf-8" 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. 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