lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241031030228.46563-1-yaolu@kylinos.cn>
Date: Thu, 31 Oct 2024 11:02:28 +0800
From: Lu Yao <yaolu@...inos.cn>
To: alexander.deucher@....com,
	christian.koenig@....com,
	Xinhui.Pan@....com
Cc: amd-gfx@...ts.freedesktop.org,
	dri-devel@...ts.freedesktop.org,
	linux-kernel@...r.kernel.org,
	Lu Yao <yaolu@...inos.cn>
Subject: [PATCH] drm/radeon/ni: Fix memory leak and missing error handling in ni_init_microcode()

'smc_fw' is not released when its size is not as expected, causing memory
leak. And when other firmware sizes do not meet expectations, 'err' is
assigned but does not jump to 'out'.

Signed-off-by: Lu Yao <yaolu@...inos.cn>
---
 drivers/gpu/drm/radeon/ni.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 3890911fe693..11f7a05a5261 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -765,6 +765,7 @@ int ni_init_microcode(struct radeon_device *rdev)
 		pr_err("ni_cp: Bogus length %zu in firmware \"%s\"\n",
 		       rdev->me_fw->size, fw_name);
 		err = -EINVAL;
+		goto out;
 	}
 
 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
@@ -775,6 +776,7 @@ int ni_init_microcode(struct radeon_device *rdev)
 		pr_err("ni_rlc: Bogus length %zu in firmware \"%s\"\n",
 		       rdev->rlc_fw->size, fw_name);
 		err = -EINVAL;
+		goto out;
 	}
 
 	/* no MC ucode on TN */
@@ -787,6 +789,7 @@ int ni_init_microcode(struct radeon_device *rdev)
 			pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n",
 			       rdev->mc_fw->size, fw_name);
 			err = -EINVAL;
+			goto out;
 		}
 	}
 
@@ -795,9 +798,7 @@ int ni_init_microcode(struct radeon_device *rdev)
 		err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
 		if (err) {
 			pr_err("smc: error loading firmware \"%s\"\n", fw_name);
-			release_firmware(rdev->smc_fw);
-			rdev->smc_fw = NULL;
-			err = 0;
+			err = -EINVAL;
 		} else if (rdev->smc_fw->size != smc_req_size) {
 			pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n",
 			       rdev->smc_fw->size, fw_name);
@@ -818,6 +819,8 @@ int ni_init_microcode(struct radeon_device *rdev)
 		rdev->rlc_fw = NULL;
 		release_firmware(rdev->mc_fw);
 		rdev->mc_fw = NULL;
+		release_firmware(rdev->smc_fw);
+		rdev->smc_fw = NULL;
 	}
 	return err;
 }
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ