linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy
@ 2023-05-22 15:50 Azeem Shaikh
  2023-05-22 20:15 ` Kees Cook
  2023-05-22 20:54 ` Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Azeem Shaikh @ 2023-05-22 15:50 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan Xinhui
  Cc: linux-hardening, Azeem Shaikh, amd-gfx, linux-kernel,
	David Airlie, Daniel Vetter, dri-devel

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

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/atom.c        |    2 +-
 drivers/gpu/drm/radeon/radeon_atombios.c |    4 ++--
 drivers/gpu/drm/radeon/radeon_combios.c  |    4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
index 1c5d9388ad0b..5f610e9a5f0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/atom.c
+++ b/drivers/gpu/drm/amd/amdgpu/atom.c
@@ -1509,7 +1509,7 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
 	str = CSTR(idx);
 	if (*str != '\0') {
 		pr_info("ATOM BIOS: %s\n", str);
-		strlcpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));
+		strscpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));
 	}
 
 	atom_rom_header = (struct _ATOM_ROM_HEADER *)CSTR(base);
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 4ad5a328d920..bf3c411a55c5 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -2105,7 +2105,7 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
 			const char *name = thermal_controller_names[power_info->info.
 								    ucOverdriveThermalController];
 			info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
-			strlcpy(info.type, name, sizeof(info.type));
+			strscpy(info.type, name, sizeof(info.type));
 			i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
 		}
 	}
@@ -2355,7 +2355,7 @@ static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *r
 				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(&rdev->pm.i2c_bus->adapter, &info);
 			}
 		} else {
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 783a6b8802d5..795c3667f6d6 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -2702,7 +2702,7 @@ void radeon_combios_get_power_modes(struct radeon_device *rdev)
 				struct i2c_board_info info = { };
 				const char *name = thermal_controller_names[thermal_controller];
 				info.addr = i2c_addr >> 1;
-				strlcpy(info.type, name, sizeof(info.type));
+				strscpy(info.type, name, sizeof(info.type));
 				i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
 			}
 		}
@@ -2719,7 +2719,7 @@ void radeon_combios_get_power_modes(struct radeon_device *rdev)
 				struct i2c_board_info info = { };
 				const char *name = "f75375";
 				info.addr = 0x28;
-				strlcpy(info.type, name, sizeof(info.type));
+				strscpy(info.type, name, sizeof(info.type));
 				i2c_new_client_device(&rdev->pm.i2c_bus->adapter, &info);
 				DRM_INFO("Possible %s thermal controller at 0x%02x\n",
 					 name, info.addr);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy
  2023-05-22 15:50 [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-22 20:15 ` Kees Cook
  2023-05-22 20:34   ` Deucher, Alexander
  2023-05-22 20:54 ` Kees Cook
  1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2023-05-22 20:15 UTC (permalink / raw)
  To: Azeem Shaikh
  Cc: Alex Deucher, Christian König, Pan Xinhui, linux-hardening,
	amd-gfx, linux-kernel, David Airlie, Daniel Vetter, dri-devel

On Mon, May 22, 2023 at 03:50:32PM +0000, Azeem Shaikh wrote:
> 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
> 
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy
  2023-05-22 20:15 ` Kees Cook
@ 2023-05-22 20:34   ` Deucher, Alexander
  0 siblings, 0 replies; 4+ messages in thread
From: Deucher, Alexander @ 2023-05-22 20:34 UTC (permalink / raw)
  To: Kees Cook, Azeem Shaikh
  Cc: Koenig, Christian, Pan, Xinhui, linux-hardening, amd-gfx,
	linux-kernel, David Airlie, Daniel Vetter, dri-devel

[Public]

> -----Original Message-----
> From: Kees Cook <keescook@chromium.org>
> Sent: Monday, May 22, 2023 4:15 PM
> To: Azeem Shaikh <azeemshaikh38@gmail.com>
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian
> <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; linux-
> hardening@vger.kernel.org; amd-gfx@lists.freedesktop.org; linux-
> kernel@vger.kernel.org; David Airlie <airlied@gmail.com>; Daniel Vetter
> <daniel@ffwll.ch>; dri-devel@lists.freedesktop.org
> Subject: Re: [PATCH] drm/radeon: Replace all non-returning strlcpy with
> strscpy
> 
> On Mon, May 22, 2023 at 03:50:32PM +0000, Azeem Shaikh wrote:
> > 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
> >
> > Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> 

Acked-by: Alex Deucher <alexander.deucher@amd.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy
  2023-05-22 15:50 [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy Azeem Shaikh
  2023-05-22 20:15 ` Kees Cook
@ 2023-05-22 20:54 ` Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2023-05-22 20:54 UTC (permalink / raw)
  To: Xinhui.Pan, azeemshaikh38, christian.koenig, alexander.deucher
  Cc: Kees Cook, dri-devel, amd-gfx, airlied, linux-hardening, daniel,
	linux-kernel

On Mon, 22 May 2023 15:50:32 +0000, Azeem Shaikh wrote:
> 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/radeon: Replace all non-returning strlcpy with strscpy
      https://git.kernel.org/kees/c/76ea3f6ef93f

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-22 20:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-22 15:50 [PATCH] drm/radeon: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-22 20:15 ` Kees Cook
2023-05-22 20:34   ` Deucher, Alexander
2023-05-22 20:54 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).