Skip to contentSkip to conversation

drm/amd/pm: Replace all non-returning strlcpy with strscpy

PATCH Applied Azeem Shaikh 3 participants 4 messages May 22, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: Replace all non-returning strlcpy with strscpy

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +1 -1
index d3fe149d8476..81fb4e5dd804 100644
@@ -794,7 +794,7 @@ void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
 				struct i2c_board_info info = { };
 				const char *name = pp_lib_thermal_controller_names[controller->ucType];
 				info.addr = controller->ucI2cAddress >> 1;
-				strlcpy(info.type, name, sizeof(info.type));
+				strscpy(info.type, name, sizeof(info.type));
 				i2c_new_client_device(&adev->pm.i2c_bus->adapter, &info);
 			}
 		} else {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

Quoted 4 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signature · 1 line
Kees Cook
maintainer Acked-by
#2 lore raw

[Public]

Quoted 22 lines

-----Original Message-----
From: Kees Cook <[email protected]>
Sent: Monday, May 22, 2023 4:16 PM
To: Azeem Shaikh <[email protected]>
Cc: Quan, Evan <[email protected]>; [email protected]; [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; dri- [email protected]
Subject: Re: [PATCH] drm/amd/pm: Replace all non-returning strlcpy with strscpy

Quoted 8 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

Quoted 9 lines
Quoted 2 lines

[1]

https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy

Quoted 3 lines

[2] https://github.com/KSPP/linux/issues/89

Ack to take this through whatever tree makes sense if you are trying to batch all of these up. Otherwise, I can pick them up.

Alex

Applied
#3 lore raw
In reply to Azeem Shaikh
Quoted 9 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[...]

Applied to for-next/hardening, thanks!

[1/1] drm/amd/pm: Replace all non-returning strlcpy with strscpy

      https://git.kernel.org/kees/c/0f53b61b1ca0
Signature · 1 line
Kees Cook