]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/rv: Ensure monitor name and desc are NUL-terminated
authorGabriele Monaco <gmonaco@redhat.com>
Thu, 4 Jun 2026 12:09:45 +0000 (14:09 +0200)
committerGabriele Monaco <gmonaco@redhat.com>
Thu, 4 Jun 2026 14:43:43 +0000 (16:43 +0200)
ikm_fill_monitor_definition() copies monitor name and description with
strncpy(), but does not guarantee NUL termination when source strings are
equal to or longer than the destination buffers.

Clamp copies to sizeof(dst) - 1 and explicitly append '\0' for both fields
to keep them safe for later string operations.

Suggested-by: unknownbbqrx <dev@unknownbbqr.xyz>
Fixes: 6d60f89691fc9 ("tools/rv: Add in-kernel monitor interface")
Link: https://lore.kernel.org/r/20260604120946.90302-2-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
tools/verification/rv/src/in_kernel.c

index 4bb746ea6e17355328cd4860cf6a3654d0df3dda..d324538249d3ab6257b64225f3a7fa3499642061 100644 (file)
@@ -215,10 +215,11 @@ static int ikm_fill_monitor_definition(char *name, struct monitor *ikm, char *co
                return -1;
        }
 
-       strncpy(ikm->name, nested_name, MAX_DA_NAME_LEN);
+       strncpy(ikm->name, nested_name, sizeof(ikm->name) - 1);
+       ikm->name[sizeof(ikm->name) - 1] = '\0';
        ikm->enabled = enabled;
-       strncpy(ikm->desc, desc, MAX_DESCRIPTION);
-
+       strncpy(ikm->desc, desc, sizeof(ikm->desc) - 1);
+       ikm->desc[sizeof(ikm->desc) - 1] = '\0';
        free(desc);
 
        return 0;