aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorfanzha02 <fannie.zhang@arm.com>2021-01-05 17:52:43 +0800
committerIan Lance Taylor <iant@golang.org>2021-11-02 05:35:11 +0000
commit6f327f7b889b81549d551ce6963067267578bd70 (patch)
tree8a54f62ac50b787f86ad24892e32e854fd57f171 /src/syscall
parent6f1e9a9c21aec8531db40dbf61ad10fe77d7bee5 (diff)
downloadgo-6f327f7b889b81549d551ce6963067267578bd70.tar.gz
go-6f327f7b889b81549d551ce6963067267578bd70.zip
runtime, syscall: add calls to asan functions
Add explicit address sanitizer instrumentation to the runtime and syscall packages. The compiler does not instrument the runtime package. It does instrument the syscall package, but we need to add a couple of cases that it can't see. Refer to the implementation of the asan malloc runtime library, this patch also allocates extra memory as the redzone, around the returned memory region, and marks the redzone as unaddressable to detect the overflows or underflows. Updates #44853. Change-Id: I2753d1cc1296935a66bf521e31ce91e35fcdf798 Reviewed-on: https://go-review.googlesource.com/c/go/+/298614 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: fannie zhang <Fannie.Zhang@arm.com>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/asan.go23
-rw-r--r--src/syscall/asan0.go20
-rw-r--r--src/syscall/syscall_unix.go6
-rw-r--r--src/syscall/syscall_windows.go6
4 files changed, 55 insertions, 0 deletions
diff --git a/src/syscall/asan.go b/src/syscall/asan.go
new file mode 100644
index 0000000000..3199130211
--- /dev/null
+++ b/src/syscall/asan.go
@@ -0,0 +1,23 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build asan
+// +build asan
+
+package syscall
+
+import (
+ "runtime"
+ "unsafe"
+)
+
+const asanenabled = true
+
+func asanRead(addr unsafe.Pointer, len int) {
+ runtime.ASanRead(addr, len)
+}
+
+func asanWrite(addr unsafe.Pointer, len int) {
+ runtime.ASanWrite(addr, len)
+}
diff --git a/src/syscall/asan0.go b/src/syscall/asan0.go
new file mode 100644
index 0000000000..7b69f4a64b
--- /dev/null
+++ b/src/syscall/asan0.go
@@ -0,0 +1,20 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build !asan
+// +build !asan
+
+package syscall
+
+import (
+ "unsafe"
+)
+
+const asanenabled = false
+
+func asanRead(addr unsafe.Pointer, len int) {
+}
+
+func asanWrite(addr unsafe.Pointer, len int) {
+}
diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go
index 9413db3832..5a91a023e1 100644
--- a/src/syscall/syscall_unix.go
+++ b/src/syscall/syscall_unix.go
@@ -197,6 +197,9 @@ func Read(fd int, p []byte) (n int, err error) {
if msanenabled && n > 0 {
msanWrite(unsafe.Pointer(&p[0]), n)
}
+ if asanenabled && n > 0 {
+ asanWrite(unsafe.Pointer(&p[0]), n)
+ }
return
}
@@ -218,6 +221,9 @@ func Write(fd int, p []byte) (n int, err error) {
if msanenabled && n > 0 {
msanRead(unsafe.Pointer(&p[0]), n)
}
+ if asanenabled && n > 0 {
+ asanRead(unsafe.Pointer(&p[0]), n)
+ }
return
}
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index a8a78b9ef8..0456074d47 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -394,6 +394,9 @@ func Read(fd Handle, p []byte) (n int, err error) {
if msanenabled && done > 0 {
msanWrite(unsafe.Pointer(&p[0]), int(done))
}
+ if asanenabled && done > 0 {
+ asanWrite(unsafe.Pointer(&p[0]), int(done))
+ }
return int(done), nil
}
@@ -412,6 +415,9 @@ func Write(fd Handle, p []byte) (n int, err error) {
if msanenabled && done > 0 {
msanRead(unsafe.Pointer(&p[0]), int(done))
}
+ if asanenabled && done > 0 {
+ asanRead(unsafe.Pointer(&p[0]), int(done))
+ }
return int(done), nil
}