Skip to contentSkip to conversation

drm/amdgpu: Replace deprecated strcpy() in amdgpu_virt_write_vf2pf_data

PATCH Applied Yicong Hui 3 participants 4 messages Jan 9 – Mar 11

Subsystems (2)
lore
Share & tools
lore

Yicong Hui

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Replace deprecated strcpy() in amdgpu_virt_write_vf2pf_data

strcpy() is deprecated as it does not do any bounds checking (as specified in Documentation/process/deprecated.rst).

There is a risk of buffer overflow in the case that the value for THIS_MODULE->version exceeds the 64 characters. This is unlikely, but replacing the deprecated function will pre-emptively remove this risk entirely.

Replace both instances of strcpy() with the safer strscpy() function.

Changes have been compile tested.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -2
index 47a6ce4fdc74..1c4e74e35cf3 100644
@@ -604,10 +604,10 @@ static int amdgpu_virt_write_vf2pf_data(struct amdgpu_device *adev)
 
 #ifdef MODULE
 	if (THIS_MODULE->version != NULL)
-		strcpy(vf2pf_info->driver_version, THIS_MODULE->version);
+		strscpy(vf2pf_info->driver_version, THIS_MODULE->version);
 	else
 #endif
-		strcpy(vf2pf_info->driver_version, "N/A");
+		strscpy(vf2pf_info->driver_version, "N/A");
 
 	vf2pf_info->pf2vf_version_required = 0; // no requirement, guest understands all
 	vf2pf_info->driver_cert = 0;
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Yicong Hui

strcpy() is deprecated as it does not do any bounds checking (as specified in Documentation/process/deprecated.rst).

There is a risk of buffer overflow in the case that the value for THIS_MODULE->version exceeds the 64 characters. This is unlikely, but replacing the deprecated function will pre-emptively remove this risk entirely.

Replace both instances of strcpy() with the safer strscpy() function.

This looks correct to me -- dest and src are both fixed-size, so strscpy happily checks everything at compile time. :)

-Kees

Signature · 1 line
Kees Cook
author
#2 lore raw
Quoted 9 lines · Kees Cook
Quoted 8 lines · Yicong Hui

strcpy() is deprecated as it does not do any bounds checking (as specified in Documentation/process/deprecated.rst).

There is a risk of buffer overflow in the case that the value for THIS_MODULE->version exceeds the 64 characters. This is unlikely, but replacing the deprecated function will pre-emptively remove this risk entirely.

Quoted 9 lines
Quoted 1 line

Replace both instances of strcpy() with the safer strscpy() function.

This looks correct to me -- dest and src are both fixed-size, so strscpy happily checks everything at compile time. :)

-Kees

Hello!

Is there any further feedback or progress on this patch?

Thank you!
Yicong

Applied
#3 lore raw
Quoted 16 lines · Yicong Hui
Quoted 14 lines · Kees Cook
Quoted 9 lines · Yicong Hui

strcpy() is deprecated as it does not do any bounds checking (as specified in Documentation/process/deprecated.rst).

There is a risk of buffer overflow in the case that the value for THIS_MODULE->version exceeds the 64 characters. This is unlikely, but replacing the deprecated function will pre-emptively remove this risk entirely.

Replace both instances of strcpy() with the safer strscpy() function.

This looks correct to me -- dest and src are both fixed-size, so strscpy happily checks everything at compile time. :)

Quoted 8 lines
Quoted 4 lines

-Kees

Hello!

Is there any further feedback or progress on this patch?

Applied. Thanks. If any other patches slipped through the cracks, please feel free to resend or ping on them.

Alex

Quoted 3 lines

Thank you!
Yicong