drm/amd/pm: Replace all non-returning strlcpy with strscpy
Subsystems (3)
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
@@ -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 {
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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>
Signature · 1 line
Kees Cook
[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 strscpyQuoted 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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
Signed-off-by Azeem Shaikh <[email protected]>Reviewed-by Kees Cook <[email protected]>
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
Kees Cook
AppliedQuoted 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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