From: Arina Kharlamova <[email protected]>

binary[] in struct registry_list_entry is annotated __counted_by(vlen),
but add_registry() copies the value into it before vlen is set, and the
entry comes from kmalloc(). With FORTIFY_SOURCE and a compiler that
supports counted_by, the memcpy() is checked against an uninitialized
length and can trigger a fortify panic for string entries given with
NVreg_RegistryDwords.

Set vlen right after the allocation.

Fixes: b58a0bc904ff ("nouveau: add command-line GSP-RM registry support")
Cc: [email protected]
Signed-off-by: Arina Kharlamova <[email protected]>
---
Found by checks derived from the spec2patch kernel API specifications,
with the help of an AI coding assistant (Claude); I reviewed the
analysis and the fix.
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c 
b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
index fe590a045d70..e10e41879639 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
@@ -426,6 +426,8 @@ static int add_registry(struct nvkm_gsp *gsp, const char 
*key,
        if (!reg)
                return -ENOMEM;
 
+       reg->vlen = length;
+
        switch (type) {
        case REGISTRY_TABLE_ENTRY_TYPE_DWORD:
                reg->dword = *(const u32 *)(data);
@@ -443,7 +445,6 @@ static int add_registry(struct nvkm_gsp *gsp, const char 
*key,
 
        memcpy(reg->key, key, nlen);
        reg->klen = nlen;
-       reg->vlen = length;
        reg->type = type;
 
        list_add_tail(&reg->head, &gsp->registry_list);

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-c18-0874cdd482b1

Best regards,
--  
Arina Kharlamova <[email protected]>


Reply via email to