[DTrace-devel] [PATCH 1/3] Clear agg keys

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Aug 8 21:24:23 UTC 2023


From: Eugene Loh <eugene.loh at oracle.com>

Aggregations use a "map of maps" to access per-CPU BPF maps whose
keys are of size dt_maxtuplesize to accommodate keys of various
sizes.  Care was exercised on the cg side to ensure that a key
would be zeroed out before filling so that garbage bytes would not
pollute the key.

Exercise similar caution on the consumer side.

THIS PATCH NEEDS TESTS.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_aggregate.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libdtrace/dt_aggregate.c b/libdtrace/dt_aggregate.c
index 24faf1c1..1b8167d6 100644
--- a/libdtrace/dt_aggregate.c
+++ b/libdtrace/dt_aggregate.c
@@ -570,11 +570,16 @@ hashnext:
 
 	/* Copy the key. */
 	size = agg->dtagd_ksize;
-	ptr = dt_alloc(dtp, size);
+	ptr = dt_alloc(dtp, dtp->dt_maxtuplesize);
 	if (ptr == NULL)
 		return dt_set_errno(dtp, EDT_NOMEM);
 
-	memcpy(ptr, key, size);
+	memset(ptr, 0, dtp->dt_maxtuplesize);
+	for (i = 0; i < agg->dtagd_nkrecs; i++) {
+		rec = &agg->dtagd_krecs[i];
+		off = rec->dtrd_offset;
+		memcpy(&ptr[off], &key[off], rec->dtrd_size);
+	}
 	agd->dtada_key = ptr;
 
 	/* Copy the data. */
-- 
2.31.1




More information about the DTrace-devel mailing list