From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECC6E1CDFAC; Sun, 7 Sep 2025 20:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757275641; cv=none; b=hIrrLmUFNYu8657xOtCzlv7mwiUkvuiXQjPoQKqVGhvRP+gjAdAuVPKPqHfdOexO1+8f/obgxS39YRe+X2GalMby7S/I4QDRMtwXDHctMxf1VNE8DUJT88rsaTJDhlgRC06crgclhKKJv5i5mNdSmlsoUtatsuXAFGG7HxUYUGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757275641; c=relaxed/simple; bh=xI2D8o+uVFXBiMREgZHvdRtiXcjcOGPRuly7K0wBczo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UrOJMb6YIDgvsiMs+rSy1ztvKuLCKnQ5FMBDMaOa7ff8Gpw3+p1usXrm7emW41Sz1vx5I2hlEoaaKpxG5GU2XbTIJd4S02EoNK6zZC8wd+Yagj3uS96xBewJZDEFIVv+AZihhBZ3IV2dHOS2/mGKIHHmlr+A3/eHWeP3d1XfOkY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=y7KbHCMy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="y7KbHCMy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2157AC4CEF0; Sun, 7 Sep 2025 20:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757275639; bh=xI2D8o+uVFXBiMREgZHvdRtiXcjcOGPRuly7K0wBczo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y7KbHCMygaxevirlIrTQN2L7DyuydtIwUsSdRo7lHsZmnWp5ey0/4LZM18peWzKOe 756KJZhL9NLWHQ3Qc88Bo+jJLBlOzqoi5ejGgzm6trvoyreHfpejUFUA1e4tgSxVGr 7fAbGv4nK9SSB4NAPnU+wBF+WsMLlFO/GyUg0qLg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wang Liang , Simon Horman , Paolo Abeni , Sasha Levin Subject: [PATCH 5.10 18/52] net: atm: fix memory leak in atm_register_sysfs when device_register fail Date: Sun, 7 Sep 2025 21:57:38 +0200 Message-ID: <20250907195602.524521236@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250907195601.957051083@linuxfoundation.org> References: <20250907195601.957051083@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wang Liang [ Upstream commit 0a228624bcc00af41f281a2a84c928595a74c17d ] When device_register() return error in atm_register_sysfs(), which can be triggered by kzalloc fail in device_private_init() or other reasons, kmemleak reports the following memory leaks: unreferenced object 0xffff88810182fb80 (size 8): comm "insmod", pid 504, jiffies 4294852464 hex dump (first 8 bytes): 61 64 75 6d 6d 79 30 00 adummy0. backtrace (crc 14dfadaf): __kmalloc_node_track_caller_noprof+0x335/0x450 kvasprintf+0xb3/0x130 kobject_set_name_vargs+0x45/0x120 dev_set_name+0xa9/0xe0 atm_register_sysfs+0xf3/0x220 atm_dev_register+0x40b/0x780 0xffffffffa000b089 do_one_initcall+0x89/0x300 do_init_module+0x27b/0x7d0 load_module+0x54cd/0x5ff0 init_module_from_file+0xe4/0x150 idempotent_init_module+0x32c/0x610 __x64_sys_finit_module+0xbd/0x120 do_syscall_64+0xa8/0x270 entry_SYSCALL_64_after_hwframe+0x77/0x7f When device_create_file() return error in atm_register_sysfs(), the same issue also can be triggered. Function put_device() should be called to release kobj->name memory and other device resource, instead of kfree(). Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array") Signed-off-by: Wang Liang Reviewed-by: Simon Horman Link: https://patch.msgid.link/20250901063537.1472221-1-wangliang74@huawei.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/atm/resources.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/atm/resources.c b/net/atm/resources.c index fb8cf4cd6c1d7..932f7b383dba7 100644 --- a/net/atm/resources.c +++ b/net/atm/resources.c @@ -114,7 +114,9 @@ struct atm_dev *atm_dev_register(const char *type, struct device *parent, if (atm_proc_dev_register(dev) < 0) { pr_err("atm_proc_dev_register failed for dev %s\n", type); - goto out_fail; + mutex_unlock(&atm_dev_mutex); + kfree(dev); + return NULL; } if (atm_register_sysfs(dev, parent) < 0) { @@ -130,7 +132,7 @@ struct atm_dev *atm_dev_register(const char *type, struct device *parent, return dev; out_fail: - kfree(dev); + put_device(&dev->class_dev); dev = NULL; goto out; } -- 2.50.1