Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/radeon: Prefer strscpy over strlcpy in 'radeon_combios_get_power_modes'

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. The safe
replacement is strscpy() [1].

cleanup to remove the strlcpy() function entirely from the kernel [2].

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

Fixes the following:

WARNING: Prefer strscpy over strlcpy
+ strlcpy(info.type, name, sizeof(info.type));

WARNING: Prefer strscpy over strlcpy
+ strlcpy(info.type, name, sizeof(info.type));

Cc: Guchun Chen <guchun.chen@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Srinivasan Shanmugam and committed by
Alex Deucher
9eec1fc1 6cf20211

+2 -2
+2 -2
drivers/gpu/drm/radeon/radeon_combios.c
··· 2702 2702 struct i2c_board_info info = { }; 2703 2703 const char *name = thermal_controller_names[thermal_controller]; 2704 2704 info.addr = i2c_addr >> 1; 2705 - strlcpy(info.type, name, sizeof(info.type)); 2705 + strscpy(info.type, name, sizeof(info.type)); 2706 2706 i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info); 2707 2707 } 2708 2708 } ··· 2719 2719 struct i2c_board_info info = { }; 2720 2720 const char *name = "f75375"; 2721 2721 info.addr = 0x28; 2722 - strlcpy(info.type, name, sizeof(info.type)); 2722 + strscpy(info.type, name, sizeof(info.type)); 2723 2723 i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info); 2724 2724 DRM_INFO("Possible %s thermal controller at 0x%02x\n", 2725 2725 name, info.addr);