From 07cba70d5794747044ce5f2f3b34de139193e2a5 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Mon, 16 Nov 2020 21:28:26 -0500 Subject: cmd/compile, runtime: use __msan_memmove for moving data, split msanread to fields Currently, for data moving, we generate an msanread of the source, followed by an msanwrite of the destination. msanread checks the source is initialized. This has a problem: if the source is an aggregate type containing alignment paddings, the padding bytes may not be thought as initialized by MSAN. If we copy the aggregate type by value, if it counts as a read, MSAN reports using uninitialized data. This CL changes it to use __msan_memmove for data copying, which tells MSAN to propagate initialized-ness but not check for it. Caveat: technically __msan_memmove is not a public API of MSAN, although the C compiler does generate direct calls to it. Also, when instrumenting a load of a struct, split the instrumentation to fields, instead of generating an msanread for the whole struct. This skips padding bytes, which may not be considered initialized in MSAN. Fixes #42820. Change-Id: Id861c8bbfd94cfcccefcc58eaf9e4eb43b4d85c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/270859 Trust: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Austin Clements --- src/runtime/msan.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/runtime/msan.go') diff --git a/src/runtime/msan.go b/src/runtime/msan.go index c0f3957e28..6a5960b0a8 100644 --- a/src/runtime/msan.go +++ b/src/runtime/msan.go @@ -50,8 +50,12 @@ func msanmalloc(addr unsafe.Pointer, sz uintptr) //go:noescape func msanfree(addr unsafe.Pointer, sz uintptr) -// These are called from msan_amd64.s +//go:noescape +func msanmove(dst, src unsafe.Pointer, sz uintptr) + +// These are called from msan_GOARCH.s //go:cgo_import_static __msan_read_go //go:cgo_import_static __msan_write_go //go:cgo_import_static __msan_malloc_go //go:cgo_import_static __msan_free_go +//go:cgo_import_static __msan_memmove -- cgit v1.3