Skip to contentSkip to conversation

tools/rv: Ensure monitor name and desc are NUL-terminated

PATCH New Gabriele Monaco 1 participant 1 message Jun 4

Subsystems (2)
lore
Share & tools
lore

Gabriele Monaco

author maintainer
#0 lore raw

PATCH 1/1 tools/rv: Ensure monitor name and desc are NUL-terminated

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.

Fixes 6d60f89691fc9 ("tools/rv: Add in-kernel monitor interface")

---

Patch was initially sent as [1], the original author's email address doesn't seem to exist any longer and the author didn't provide a valid name.

Reimplementing the fix and changing attribution.

[1] - https://lore.kernel.org/r/[email protected]

---
 tools/verification/rv/src/in_kernel.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/verification/rv/src/in_kernel.c +4 -3
index 4bb746ea6..d32453824 100644
@@ -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;

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

Signature · 1 line
2.54.0