From 5f4b5f1a196774e45bc50de0729973119eb7bf07 Mon Sep 17 00:00:00 2001 From: "khr@golang.org" Date: Sat, 8 Nov 2025 11:11:10 -0800 Subject: [PATCH] runtime/msan: use different msan routine for copying __msan_memmove records the fact that we're copying memory, and actually does the copy. Use instead __msan_copy_shadow, which records the fact that we're copying memory, but doesn't actually do the copy itself. We're doing the copy ourselves, so we don't need msan to do it also. More importantly, msan doing the copy clobbers the target before we issue the write barrier, which causes pointers to get lost. Fixes #76138 Change-Id: I17aea739f9444de21fac2bbfd81e48534a39481d Reviewed-on: https://go-review.googlesource.com/c/go/+/719020 Reviewed-by: Cherry Mui Reviewed-by: t hepudds LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Auto-Submit: Keith Randall Reviewed-by: Radu Berinde Reviewed-by: Ian Lance Taylor --- src/runtime/msan/msan.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime/msan/msan.go b/src/runtime/msan/msan.go index 8d4471b816..7a30581de7 100644 --- a/src/runtime/msan/msan.go +++ b/src/runtime/msan/msan.go @@ -13,8 +13,6 @@ package msan #include #include -extern void __msan_memmove(void*, const void*, uintptr_t); - void __msan_read_go(void *addr, uintptr_t sz) { __msan_check_mem_is_initialized(addr, sz); } @@ -32,7 +30,11 @@ void __msan_free_go(void *addr, uintptr_t sz) { } void __msan_memmove_go(void *to, const void *from, uintptr_t sz) { - __msan_memmove(to, from, sz); + // Note: don't use msan_memmove, as it actually does + // the move. We do the move ourselves, so it isn't necessary. + // Also, it clobbers the target before we issue the write + // barrier, which causes pointers to get lost. See issue 76138. + __msan_copy_shadow(to, from, sz); } */ import "C" -- 2.52.0