summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorZach Koopmans <zkoopmans@google.com>2021-08-30 15:32:22 -0700
committergVisor bot <gvisor-bot@google.com>2021-08-30 15:35:02 -0700
commitdfbcb8903ae8bd0d1ff984889f1b5cf1e041865e (patch)
treef38c3de45bb102e17971f428fed0099ac69b6a2c /pkg
parenta247e227b1f629392d0a9132dc490a6ef9ee2519 (diff)
[syserr] Fix SIGBUS on syserr.FromError
Fix syzcaller panic SIGBUS on error handling. Done by adding an interface, errors.GuestError, which errors can implement in order to be compared against each other. PiperOrigin-RevId: 393867554
Diffstat (limited to 'pkg')
-rw-r--r--pkg/syserr/BUILD1
-rw-r--r--pkg/syserr/syserr.go16
2 files changed, 11 insertions, 6 deletions
diff --git a/pkg/syserr/BUILD b/pkg/syserr/BUILD
index 1cd5d641d..d8c4c9613 100644
--- a/pkg/syserr/BUILD
+++ b/pkg/syserr/BUILD
@@ -14,6 +14,7 @@ go_library(
"//pkg/abi/linux/errno",
"//pkg/errors",
"//pkg/errors/linuxerr",
+ "//pkg/safecopy",
"//pkg/tcpip",
"@org_golang_x_sys//unix:go_default_library",
],
diff --git a/pkg/syserr/syserr.go b/pkg/syserr/syserr.go
index a5e386e38..b679f3046 100644
--- a/pkg/syserr/syserr.go
+++ b/pkg/syserr/syserr.go
@@ -24,6 +24,7 @@ import (
"gvisor.dev/gvisor/pkg/abi/linux/errno"
"gvisor.dev/gvisor/pkg/errors"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
+ "gvisor.dev/gvisor/pkg/safecopy"
)
// Error represents an internal error.
@@ -278,15 +279,18 @@ func FromError(err error) *Error {
if err == nil {
return nil
}
- if errno, ok := err.(unix.Errno); ok {
- return FromHost(errno)
- }
- if linuxErr, ok := err.(*errors.Error); ok {
- return FromHost(unix.Errno(linuxErr.Errno()))
+ switch e := err.(type) {
+ case unix.Errno:
+ return FromHost(e)
+ case *errors.Error:
+ return FromHost(unix.Errno(e.Errno()))
+ case safecopy.SegvError, safecopy.BusError, safecopy.AlignmentError:
+ return FromHost(unix.EFAULT)
}
- panic("unknown error: " + err.Error())
+ msg := fmt.Sprintf("err: %s type: %T", err.Error(), err)
+ panic(msg)
}
// ConvertIntr converts the provided error code (err) to another one (intr) if