drm/amd/powerplay: Fix buffer overflow in arcturus_get_unique_id()
Subsystems (3)
PATCH 1/1 drm/amd/powerplay: Fix buffer overflow in arcturus_get_unique_id()
The comments say that the "sn" buffer is used to hold a 16-digit HEX string so the buffer needs to be at least 17 characters to hold the NUL terminator.
--- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
@@ -2266,7 +2266,7 @@ 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 ]; +char sn[20 ];uint64_t id;if (smu_get_smc_version (smu,NULL , &smu_version)) {
Signature · 1 line
2.26.2
[AMD Official Use Only - Internal Distribution Only]
adev->serial which is used to hold the final serial number may need to be enlarged also. Since it comes with 16 bytes also.
BR,
Evan
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Monday, June 8, 2020 10:18 PM
To: Quan, Evan <[email protected]>; Russell, Kent <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] drm/amd/powerplay: Fix buffer overflow in arcturus_get_unique_id()
The comments say that the "sn" buffer is used to hold a 16-digit HEX string so the buffer needs to be at least 17 characters to hold the NUL terminator.
--- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -2
@@ -2266,7 +2266,7 @@ 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 ]; +char sn[20 ];uint64_t id;if (smu_get_smc_version (smu,NULL , &smu_version)) { --
2.26.2
PATCH v2 1/1 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.
---
v2: Change adev->serial. The original patch would have just moved the overflow until amdgpu_device_get_serial_number() is called.
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -986,7 +986,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;
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +2 -4
@@ -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)) {
@@ -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)
Signature · 1 line
2.26.2
RE: [PATCH v2] drm/amdgpu: Fix a buffer overflow handling the serial number
[AMD Official Use Only - Internal Distribution Only]
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, June 10, 2020 4:57 PM
To: Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Quan, Evan <[email protected]>; Zhang, Hawking <[email protected]>; Kuehling, Felix <[email protected]>; Zhou1, Tao <[email protected]>; Ma, Le <[email protected]>; Xiao, Jack <[email protected]>; Kim, Jonathan <[email protected]>; Greathouse, Joseph <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v2] 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.
---
v2: Change adev->serial. The original patch would have just moved the overflow until amdgpu_device_get_serial_number() is called.
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -986,7 +986,7 @@ struct amdgpu_device {/* Chip product information */ charproduct_number[16 ]; charproduct_name[32 ]; -charserial[16 ]; +charserial[20 ];struct amdgpu_autodumpautodump ;
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +2 -4
@@ -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)) {
@@ -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)
--
2.26.2
Alex Deucher
AppliedRe: [PATCH v2] drm/amdgpu: Fix a buffer overflow handling the serial number
Quoted 4 lines · Evan
[AMD Official Use Only - Internal Distribution Only]
Reviewed-by Evan Quan <[email protected]>
Applied. Thanks!
Alex
Quoted 75 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, June 10, 2020 4:57 PM
To: Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Quan, Evan <[email protected]>; Zhang, Hawking <[email protected]>; Kuehling, Felix <[email protected]>; Zhou1, Tao <[email protected]>; Ma, Le <[email protected]>; Xiao, Jack <[email protected]>; Kim, Jonathan <[email protected]>; Greathouse, Joseph <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v2] drm/amdgpu: Fix a buffer overflow handling the serial numberThe 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 thememcpy()wasn't copying the terminator. The serial number needs to be NUL terminated so that it doesn't lead to a read overflow inamdgpu_device_get_serial_number(). Also it's just cleaner and faster tosprintf()directly to adev->serial[] instead of using a temporary buffer.Fixes 81a16241114b ("drm/amdgpu: Add unique_id and serial_number for Arcturus v3")Signed-off-by Dan Carpenter <[email protected]>---
v2: Changeadev->serial. The original patch would have just moved the overflow untilamdgpu_device_get_serial_number()is called.drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-1@@ -986,7 +986,7 @@ struct amdgpu_device {/* Chip product information */ charproduct_number[16 ]; charproduct_name[32 ]; -charserial[16 ]; +charserial[20 ];struct amdgpu_autodumpautodump ;drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +2
-5@@ -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)) {@@ -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) --2.26.2
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx