diff options
author | Adin Scannell <ascannell@google.com> | 2018-07-16 22:02:03 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-07-16 22:02:58 -0700 |
commit | 29e00c943a61dfcfd4ac8d3f6f526eab641c44a6 (patch) | |
tree | f7cdb0c59c8363b3a4e5737e17b1b4e423bfc05a /pkg/sentry/platform/ring0/kernel_amd64.go | |
parent | 14d06064d26b1cd9e2ccad08ebe997e704092eb8 (diff) |
Add CPUID faulting for ptrace and KVM.
PiperOrigin-RevId: 204858314
Change-Id: I8252bf8de3232a7a27af51076139b585e73276d4
Diffstat (limited to 'pkg/sentry/platform/ring0/kernel_amd64.go')
-rw-r--r-- | pkg/sentry/platform/ring0/kernel_amd64.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/pkg/sentry/platform/ring0/kernel_amd64.go b/pkg/sentry/platform/ring0/kernel_amd64.go index 117e86104..0d2b0f7dc 100644 --- a/pkg/sentry/platform/ring0/kernel_amd64.go +++ b/pkg/sentry/platform/ring0/kernel_amd64.go @@ -163,7 +163,6 @@ func IsCanonical(addr uint64) bool { // the case for amd64, but may not be the case for other architectures. // // Precondition: the Rip, Rsp, Fs and Gs registers must be canonical. - // //go:nosplit func (c *CPU) SwitchToUser(switchOpts SwitchOpts) (vector Vector) { @@ -237,6 +236,27 @@ func start(c *CPU) { wrmsr(_MSR_CSTAR, kernelFunc(sysenter)) } +// SetCPUIDFaulting sets CPUID faulting per the boolean value. +// +// True is returned if faulting could be set. +// +//go:nosplit +func SetCPUIDFaulting(on bool) bool { + // Per the SDM (Vol 3, Table 2-43), PLATFORM_INFO bit 31 denotes support + // for CPUID faulting, and we enable and disable via the MISC_FEATURES MSR. + if rdmsr(_MSR_PLATFORM_INFO)&_PLATFORM_INFO_CPUID_FAULT != 0 { + features := rdmsr(_MSR_MISC_FEATURES) + if on { + features |= _MISC_FEATURE_CPUID_TRAP + } else { + features &^= _MISC_FEATURE_CPUID_TRAP + } + wrmsr(_MSR_MISC_FEATURES, features) + return true // Setting successful. + } + return false +} + // ReadCR2 reads the current CR2 value. // //go:nosplit |