Skip to contentSkip to conversation

trace: fix out of bounds write in __rte_trace_mem_get

PATCH Superseded Oleksandr Nahnybida 3 participants 6 messages Apr 2, 2025 – Jun 4, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace: fix out of bounds write in __rte_trace_mem_get

Offset should be aligned first before checking if there is free space for another write.

Bugzilla ID: 1665

Fixes ebaee6409702 ("trace: simplify trace point headers")
---
 lib/eal/include/rte_trace_point.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/eal/include/rte_trace_point.h +1 -3
index 8a317d31d2..343e0271b3 100644
@@ -328,7 +328,7 @@ __rte_trace_mem_get(uint64_t in)
 			return NULL;
 	}
 	/* Check the wrap around case */
-	uint32_t offset = trace->offset;
+	uint32_t offset = RTE_ALIGN_CEIL(trace->offset, __RTE_TRACE_EVENT_HEADER_SZ);
 	if (unlikely((offset + sz) >= trace->len)) {
 		/* Disable the trace event if it in DISCARD mode */
 		if (unlikely(in & __RTE_TRACE_FIELD_ENABLE_DISCARD))
@@ -336,8 +336,6 @@ __rte_trace_mem_get(uint64_t in)
 
 		offset = 0;
 	}
-	/* Align to event header size */
-	offset = RTE_ALIGN_CEIL(offset, __RTE_TRACE_EVENT_HEADER_SZ);
 	void *mem = RTE_PTR_ADD(&trace->mem[0], offset);
 	offset += sz;
 	trace->offset = offset;
Signature · 1 line
2.49.0
#2 lore raw
In reply to Oleksandr Nahnybida
Quoted 6 lines · Oleksandr Nahnybida

Offset should be aligned first before checking if there is free space for another write.

Bugzilla ID: 1665

Fixes ebaee6409702 ("trace: simplify trace point headers")

This commit ebaee6409702 ("trace: simplify trace point headers") just moved code around.

I think the bug was present since the first implementation, so:

Fixes 032a7e5499a0 ("trace: implement provider payload")
Signature · 1 line
David Marchand
#3 lore raw

PATCH v2 1/1 trace: fix out of bounds write in __rte_trace_mem_get

In reply to Oleksandr Nahnybida

Offset should be aligned first before checking if there is free space for another write.

Bugzilla ID: 1665

Fixes 032a7e5499a0 ("trace: implement provider payload")

---
Specified correct "Fixes" commit.

 lib/eal/include/rte_trace_point.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/eal/include/rte_trace_point.h +1 -3
index 8a317d31d2..343e0271b3 100644
@@ -328,7 +328,7 @@ __rte_trace_mem_get(uint64_t in)
 			return NULL;
 	}
 	/* Check the wrap around case */
-	uint32_t offset = trace->offset;
+	uint32_t offset = RTE_ALIGN_CEIL(trace->offset, __RTE_TRACE_EVENT_HEADER_SZ);
 	if (unlikely((offset + sz) >= trace->len)) {
 		/* Disable the trace event if it in DISCARD mode */
 		if (unlikely(in & __RTE_TRACE_FIELD_ENABLE_DISCARD))
@@ -336,8 +336,6 @@ __rte_trace_mem_get(uint64_t in)
 
 		offset = 0;
 	}
-	/* Align to event header size */
-	offset = RTE_ALIGN_CEIL(offset, __RTE_TRACE_EVENT_HEADER_SZ);
 	void *mem = RTE_PTR_ADD(&trace->mem[0], offset);
 	offset += sz;
 	trace->offset = offset;

--
2.49.0

Acked-by on v2 1/1
#4 lore raw
Quoted 38 lines

Offset should be aligned first before checking if there is free space for another write.

Bugzilla ID: 1665

Fixes 032a7e5499a0 ("trace: implement provider payload")

---
Specified correct "Fixes" commit.

 lib/eal/include/rte_trace_point.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/eal/include/rte_trace_point.h +2 -4
index 8a317d31d2..343e0271b3 100644
@@ -328,7 +328,7 @@ __rte_trace_mem_get(uint64_t in)
 			return NULL;
 	}
 	/* Check the wrap around case */
-	uint32_t offset = trace->offset;
+	uint32_t offset = RTE_ALIGN_CEIL(trace->offset,
+__RTE_TRACE_EVENT_HEADER_SZ);
 	if (unlikely((offset + sz) >= trace->len)) {
 		/* Disable the trace event if it in DISCARD mode */
 		if (unlikely(in & __RTE_TRACE_FIELD_ENABLE_DISCARD))
@@ -336,8 +336,6 @@ __rte_trace_mem_get(uint64_t in)
 
 		offset = 0;
 	}
-	/* Align to event header size */
-	offset = RTE_ALIGN_CEIL(offset, __RTE_TRACE_EVENT_HEADER_SZ);
 	void *mem = RTE_PTR_ADD(&trace->mem[0], offset);
 	offset += sz;
 	trace->offset = offset;
--
Quoted 1 line

2.49.0