Skip to content

Commit 992b8fe

Browse files
azeemshaikh38kees
authored andcommitted
drm/radeon: 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] KSPP#89 Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230522155032.2336283-1-azeemshaikh38@gmail.com
1 parent c7dce4c commit 992b8fe

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/gpu/drm/amd/amdgpu/atom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
15091509
str = CSTR(idx);
15101510
if (*str != '\0') {
15111511
pr_info("ATOM BIOS: %s\n", str);
1512-
strlcpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));
1512+
strscpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));
15131513
}
15141514

15151515
atom_rom_header = (struct _ATOM_ROM_HEADER *)CSTR(base);

drivers/gpu/drm/radeon/radeon_atombios.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
21052105
const char *name = thermal_controller_names[power_info->info.
21062106
ucOverdriveThermalController];
21072107
info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
2108-
strlcpy(info.type, name, sizeof(info.type));
2108+
strscpy(info.type, name, sizeof(info.type));
21092109
i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
21102110
}
21112111
}
@@ -2355,7 +2355,7 @@ static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *r
23552355
struct i2c_board_info info = { };
23562356
const char *name = pp_lib_thermal_controller_names[controller->ucType];
23572357
info.addr = controller->ucI2cAddress >> 1;
2358-
strlcpy(info.type, name, sizeof(info.type));
2358+
strscpy(info.type, name, sizeof(info.type));
23592359
i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
23602360
}
23612361
} else {

drivers/gpu/drm/radeon/radeon_combios.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ void radeon_combios_get_power_modes(struct radeon_device *rdev)
27022702
struct i2c_board_info info = { };
27032703
const char *name = thermal_controller_names[thermal_controller];
27042704
info.addr = i2c_addr >> 1;
2705-
strlcpy(info.type, name, sizeof(info.type));
2705+
strscpy(info.type, name, sizeof(info.type));
27062706
i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
27072707
}
27082708
}
@@ -2719,7 +2719,7 @@ void radeon_combios_get_power_modes(struct radeon_device *rdev)
27192719
struct i2c_board_info info = { };
27202720
const char *name = "f75375";
27212721
info.addr = 0x28;
2722-
strlcpy(info.type, name, sizeof(info.type));
2722+
strscpy(info.type, name, sizeof(info.type));
27232723
i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
27242724
DRM_INFO("Possible %s thermal controller at 0x%02x\n",
27252725
name, info.addr);

0 commit comments

Comments
 (0)