Skip to content

Commit

Permalink
drm/amdgpu: Fix a buffer overflow handling the serial number
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
Reviewed-by: Evan Quan <[email protected]>
  • Loading branch information
Dan Carpenter authored and candicelicy committed Jun 21, 2020
1 parent d8f0cd0 commit 7b4f1de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/amd/amdgpu/amdgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ struct amdgpu_device {
/* Chip product information */
char product_number[16];
char product_name[32];
char serial[16];
char serial[20];

struct amdgpu_autodump autodump;

Expand Down
6 changes: 2 additions & 4 deletions drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2265,8 +2265,7 @@ static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control)
static void arcturus_get_unique_id(struct smu_context *smu)
{
struct amdgpu_device *adev = smu->adev;
uint32_t top32, bottom32, smu_version, size;
char sn[16];
uint32_t top32, bottom32, smu_version;
uint64_t id;

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

static bool arcturus_is_baco_supported(struct smu_context *smu)
Expand Down

0 comments on commit 7b4f1de

Please sign in to comment.