Skip to content

Commit 7b4f1de

Browse files
Dan Carpentercandicelicy
authored andcommitted
drm/amdgpu: Fix a buffer overflow handling the serial number
The comments say that the serial number is a 16-digit HEX string so the buffer needs to be at least 17 characters to hold the NUL terminator. The other issue is that "size" returned from sprintf() is the number of characters before the NUL terminator so the memcpy() wasn't copying the terminator. The serial number needs to be NUL terminated so that it doesn't lead to a read overflow in amdgpu_device_get_serial_number(). Also it's just cleaner and faster to sprintf() directly to adev->serial[] instead of using a temporary buffer. Fixes: 81a1624 ("drm/amdgpu: Add unique_id and serial_number for Arcturus v3") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Evan Quan <evan.quan@amd.com>
1 parent d8f0cd0 commit 7b4f1de

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ struct amdgpu_device {
10351035
/* Chip product information */
10361036
char product_number[16];
10371037
char product_name[32];
1038-
char serial[16];
1038+
char serial[20];
10391039

10401040
struct amdgpu_autodump autodump;
10411041

drivers/gpu/drm/amd/powerplay/arcturus_ppt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,8 +2265,7 @@ static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control)
22652265
static void arcturus_get_unique_id(struct smu_context *smu)
22662266
{
22672267
struct amdgpu_device *adev = smu->adev;
2268-
uint32_t top32, bottom32, smu_version, size;
2269-
char sn[16];
2268+
uint32_t top32, bottom32, smu_version;
22702269
uint64_t id;
22712270

22722271
if (smu_get_smc_version(smu, NULL, &smu_version)) {
@@ -2289,8 +2288,7 @@ static void arcturus_get_unique_id(struct smu_context *smu)
22892288
/* For Arcturus-and-later, unique_id == serial_number, so convert it to a
22902289
* 16-digit HEX string for convenience and backwards-compatibility
22912290
*/
2292-
size = sprintf(sn, "%llx", id);
2293-
memcpy(adev->serial, &sn, size);
2291+
sprintf(adev->serial, "%llx", id);
22942292
}
22952293

22962294
static bool arcturus_is_baco_supported(struct smu_context *smu)

0 commit comments

Comments
 (0)