[PATCH 2/3] tools/mm: use memmove() to drop the timestamp from a record
From: 2-D Godoy
Date: Wed Nov 04 2026 - 14:24:06 EST
remove_pattern() moves what follows the match over the match itself. The
source and the destination are inside the same buffer and overlap, which
is undefined behaviour for memcpy(). AddressSanitizer flags it on every
record that carries a timestamp:
ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges
[0x60f000000262,0x60f0000002be) and [0x60f000000265,0x60f0000002c1)
overlap
#0 __interceptor_memcpy
#1 remove_pattern tools/mm/page_owner_sort.c:252
Use memmove(), which is defined for overlapping ranges.
Signed-off-by: Henrique Godoy <henrique.godoy@xxxxxxxxxxxx>
---
tools/mm/page_owner_sort.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c
index 58d4a54..e56375f 100644
--- a/tools/mm/page_owner_sort.c
+++ b/tools/mm/page_owner_sort.c
@@ -249,7 +249,8 @@ static int remove_pattern(regex_t *pattern, char
*buf, int len)
if (err != 0 || pmatch[1].rm_so == -1)
return len;
- memcpy(buf + pmatch[1].rm_so,
+ /* source and destination overlap, so memmove() is required */
+ memmove(buf + pmatch[1].rm_so,
buf + pmatch[1].rm_eo, len - pmatch[1].rm_eo);
return len - (pmatch[1].rm_eo - pmatch[1].rm_so);
--
2.39.5