All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nouveau/gsp: Avoid addressing beyond end of rpc->entries
@ 2024-03-30 14:12 Kees Cook
  2024-04-05 16:37 ` Danilo Krummrich
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2024-03-30 14:12 UTC (permalink / raw)
  To: Karol Herbst
  Cc: Kees Cook, Lyude Paul, Danilo Krummrich, David Airlie,
	Daniel Vetter, Dave Airlie, Ben Skeggs, Timur Tabi, dri-devel,
	nouveau, Gustavo A. R. Silva, Dan Carpenter, linux-kernel,
	linux-hardening

Using the end of rpc->entries[] for addressing runs into both compile-time
and run-time detection of accessing beyond the end of the array. Use the
base pointer instead, since was allocated with the additional bytes for
storing the strings. Avoids the following warning in future GCC releases
with support for __counted_by:

In function 'fortify_memcpy_chk',
    inlined from 'r535_gsp_rpc_set_registry' at ../drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1123:3:
../include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
  553 |                         __write_overflow_field(p_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

for this code:

	strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES];
	...
                memcpy(strings, r535_registry_entries[i].name, name_len);

Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@redhat.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Timur Tabi <ttabi@nvidia.com>
Cc: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
index 9994cbd6f1c4..9858c1438aa7 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
@@ -1112,7 +1112,7 @@ r535_gsp_rpc_set_registry(struct nvkm_gsp *gsp)
 	rpc->numEntries = NV_GSP_REG_NUM_ENTRIES;
 
 	str_offset = offsetof(typeof(*rpc), entries[NV_GSP_REG_NUM_ENTRIES]);
-	strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES];
+	strings = (char *)rpc + str_offset;
 	for (i = 0; i < NV_GSP_REG_NUM_ENTRIES; i++) {
 		int name_len = strlen(r535_registry_entries[i].name) + 1;
 
-- 
2.34.1


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

* Re: [PATCH] nouveau/gsp: Avoid addressing beyond end of rpc->entries
  2024-03-30 14:12 [PATCH] nouveau/gsp: Avoid addressing beyond end of rpc->entries Kees Cook
@ 2024-04-05 16:37 ` Danilo Krummrich
  0 siblings, 0 replies; 2+ messages in thread
From: Danilo Krummrich @ 2024-04-05 16:37 UTC (permalink / raw)
  To: Kees Cook
  Cc: Lyude Paul, David Airlie, Daniel Vetter, Dave Airlie, Ben Skeggs,
	Timur Tabi, dri-devel, nouveau, Gustavo A. R. Silva,
	Dan Carpenter, linux-kernel, linux-hardening, Karol Herbst

On 3/30/24 15:12, Kees Cook wrote:
> Using the end of rpc->entries[] for addressing runs into both compile-time
> and run-time detection of accessing beyond the end of the array. Use the
> base pointer instead, since was allocated with the additional bytes for
> storing the strings. Avoids the following warning in future GCC releases
> with support for __counted_by:
> 
> In function 'fortify_memcpy_chk',
>      inlined from 'r535_gsp_rpc_set_registry' at ../drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1123:3:
> ../include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
>    553 |                         __write_overflow_field(p_size_field, size);
>        |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> for this code:
> 
> 	strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES];
> 	...
>                  memcpy(strings, r535_registry_entries[i].name, name_len);
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Applied to drm-misc-fixes, thanks!

> ---
> Cc: Karol Herbst <kherbst@redhat.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Danilo Krummrich <dakr@redhat.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: Timur Tabi <ttabi@nvidia.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> ---
>   drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> index 9994cbd6f1c4..9858c1438aa7 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c
> @@ -1112,7 +1112,7 @@ r535_gsp_rpc_set_registry(struct nvkm_gsp *gsp)
>   	rpc->numEntries = NV_GSP_REG_NUM_ENTRIES;
>   
>   	str_offset = offsetof(typeof(*rpc), entries[NV_GSP_REG_NUM_ENTRIES]);
> -	strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES];
> +	strings = (char *)rpc + str_offset;
>   	for (i = 0; i < NV_GSP_REG_NUM_ENTRIES; i++) {
>   		int name_len = strlen(r535_registry_entries[i].name) + 1;
>   


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

end of thread, other threads:[~2024-04-05 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-30 14:12 [PATCH] nouveau/gsp: Avoid addressing beyond end of rpc->entries Kees Cook
2024-04-05 16:37 ` Danilo Krummrich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.