]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nouveau/gsp: Avoid addressing beyond end of rpc->entries
authorKees Cook <keescook@chromium.org>
Sat, 30 Mar 2024 14:12:03 +0000 (07:12 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 May 2024 10:14:43 +0000 (12:14 +0200)
[ Upstream commit 838ae9f45c4e43b4633d8b0ad1fbedff9ecf177d ]

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>
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240330141159.work.063-kees@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c

index a73a5b58979045b07468c1443940f87e1b151f67..dcafbb2004ca2394d9b6993b5370575d44a8f212 100644 (file)
@@ -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;