513 Commits
Author SHA1 Message Date
Jimmy TranandgVisor bot 8d5f3c982a Handle sighandling.KillItself() return error.
Call dumpAndPanicSyscallError for the rare case where we fail to kill the the
Sentry upon detecting an unexpected stub exit. This will provide enough
information determine if a panic occur due to failed SIGKILL attempt or an
unexpected event.

PiperOrigin-RevId: 737751257
2025-03-17 14:29:52 -07:00
Jamie LiuandgVisor bot 768c0364e4 kvm: unlock OS thread during machine.available.Wait()
PiperOrigin-RevId: 737750303
2025-03-17 14:25:23 -07:00
Jamie LiuandgVisor bot fbca0560dd kvm: honor memmap.File.MemoryType()
Updates #11436

PiperOrigin-RevId: 737689743
2025-03-17 11:34:50 -07:00
Andrei VaginandgVisor bot d844c7bbb7 Allow Sentry to kill itself even when it is the init process
PiperOrigin-RevId: 733399678
2025-03-04 11:25:32 -08:00
Jamie LiuandgVisor bot 2247aceb99 kvm: enable CPUID faulting on all VCPUs
This feature is controlled by an MSR; MSRs are per-CPU.

The Intel SDM doesn't document CPUID faulting, at least as of the Dec 2024
revision; despite the deleted comment in ring0/kernel_amd64.go, there is no
Vol. 3 Table 2-43, and every table in Vol. 4 ("Model-Specific Registers") lists
bit 31 in MSR_PLATFORM_INFO as "reserved". The only documentation seems to be
that cited by Linux's e9ea1e7f53b85 ("x86/arch_prctl: Add
ARCH_[GET|SET]_CPUID"): "Intel Virtualization Technology FlexMigration
Application Note" 323850-004, 2012. This document positions CPUID faulting as
an alternative way to support cross-CPU migration for VMs that don't use VMX;
consequently it does not clarify if CPUID faulting is effective in guest ("VMX
non-root") mode, or if the CPUID VM exit takes precedence. If the former is the
case then CPUID faulting is probably faster than setting app CPUID with
KVM_SET_CPUID2, and vice versa. But regardless, this is much simpler.

PiperOrigin-RevId: 733113944
2025-03-03 17:15:39 -08:00
Andrei VaginandgVisor bot 6c88fd7b6f Internal change
PiperOrigin-RevId: 727079732
2025-02-14 15:17:51 -08:00
Andrei VaginandgVisor bot bd0dbf9b11 kvm/arm64: send SIGKILL if ring0.El0SyncInv has been triggered
Linux does the same thing.

PiperOrigin-RevId: 722789748
2025-02-03 14:07:09 -08:00
Andrei Vagin f010ae01ac Fix a few typos 2025-01-29 21:16:51 -08:00
Andrei VaginandgVisor bot 1864d9d091 Untag user addresses before handling them in the Sentry
Top-Byte-Ignore (TBI) is a feature on all ARMv8.0 CPUs that causes the top byte
of virtual addresses to be ignored on loads and stores. Instead, bit 55 is
extended over bits 56-63 before address translation. This feature allows use of
the (ignored) top byte as a tag or for other in-band metadata.

In Linux, brk()/mmap()/mremap() syscalls don't untag addresses. More details
are in dcde237319e6 ("mm: Avoid creating virtual address aliases in
brk()/mmap()/mremap()")

PiperOrigin-RevId: 715885990
2025-01-15 11:52:40 -08:00
Konstantin BogomolovandgVisor bot 17962e58c1 Replace unsafeSlice with unsafe.Slice.
reflect.SliceHeader has been deprecated.

PiperOrigin-RevId: 714222929
2025-01-10 15:11:53 -08:00
Konstantin BogomolovandgVisor bot f7875f90fd systrap: Unset fpstate_changed if ctx did not change.
For some reason we only cleared this flag in the sighandler, where it doesn't
make a difference.

PiperOrigin-RevId: 707690365
2024-12-18 15:45:14 -08:00
Andrei VaginandgVisor bot 03a28d158e platform/systrap: return memory access type based on a page fault error code
Now we don't need to trigger a second fault to figure out whether it was write
or read access.

Fixes #11008

Co-developed-by: Jamie Liu <jamieliu@google.com>
PiperOrigin-RevId: 697677262
2024-11-18 10:33:59 -08:00
Jamie LiuandgVisor bot cf5841ba66 mm: implement prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME)
PiperOrigin-RevId: 696727156
2024-11-14 19:06:07 -08:00
Andrei VaginandgVisor bot bd7d1a7388 platform/systrap: revise /proc/self/maps to find regions for the stub code
ASAN can create huge mappings and it can take too long to skip them just
incrementing offset.

PiperOrigin-RevId: 691812156
2024-10-31 08:32:16 -07:00
Andrei VaginandgVisor bot babeb34ee8 platform/kvm: don't map the entire sentry address space to VM
On x86_64, we prefer not to map the entire sentry address space into
the VM due to memory overhead. It is about 3MB for a 40-bit address
space and about 250MB for 46-bit address spaces (modern CPUs).

If the entire address space isn't mapped into the VM, we need to
trap mmap system calls and map sentry memory regions on demand. This
introduces some overhead for mmap system calls, but considering that
mmap isn't called frequently, it seems better than the memory and
startup time overhead introduced by mapping the entire address
space.

* native mmap:
  BenchmarkHostMMap-12          266972          4297 ns/op
* mmpa with the seccomp trap:
  BenchmarkHostMMap-12          174373          6855 ns/op

PiperOrigin-RevId: 687418707
2024-10-18 14:09:29 -07:00
Etienne PerotandgVisor bot b7334af658 Internal change.
PiperOrigin-RevId: 686612361
2024-10-16 13:07:09 -07:00
Jing Chen a093ad0450 Simplify and format gVisor codebase.
The changes are just output of `gofmt -s -w .`.
2024-10-13 00:50:32 -07:00
Andrei VaginandgVisor bot 8890371e35 platform/kvm: use per-thread signal stack to run bluepill handler
The user-space bluepill introduced the issue. With that change, we use a
per-vcpu stack to run bluepillHandler. BluepillHanlder releases a vcpu before
calling sigreturn, so it is still running on the vcpu stack. The race looks
like this: one thread releases a vcpu, another thread takes it and  starts
using its stack, the first thread calls sigreturn with a corrupted signal
frame.



PiperOrigin-RevId: 684992950
2024-10-11 16:40:39 -07:00
Andrei VaginandgVisor bot f9c7e51064 systrap/arm64: add the end header after FPSIMD state in signal frame
gVisor doesn't support other than FPSIMD extension, so we have to be sure that
only FPSIMD states are restored from signal frames. Stub processes are forked
from the sentry and so they can have other extensions such as SVE which shares
FPSR and FPCR registers with FPSIMD.

Fixes #10900

PiperOrigin-RevId: 684878144
2024-10-11 10:22:33 -07:00
Koichi Shiraishi 0cf77c02f8 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2024-10-10 20:36:24 +09:00
Konstantin BogomolovandgVisor bot a94f5e598f systrap: Replace all instances of unix.RawSyscall with pkg/hostsyscall variants.
PiperOrigin-RevId: 681941600
2024-10-03 10:48:09 -07:00
Konstantin BogomolovandgVisor bot d3ce23c224 Fix improper use of RawSyscall in KVM
futex wait needs to be called surrounded by syscall.Entersyscall() and
syscall.Exitsyscall(), which RawSyscall does not do. It was a mistake
to substitute it.

PiperOrigin-RevId: 681629844
2024-10-02 16:18:06 -07:00
Andrei VaginandgVisor bot ca8d05a657 platform/kvm: refactor handleBluepillFault to reduce stack usage
PiperOrigin-RevId: 681217279
2024-10-01 17:09:18 -07:00
Konstantin BogomolovandgVisor bot 51fa369cf1 kvm: Replace all instances of unix.RawSyscall with pkg/hostsyscall variants.
These are not as important as the instances that have already been replaced,
because everything builds without these replacements. However, for consistency
and for the sake of a couple of less jumps, let's replace these too.

PiperOrigin-RevId: 681135990
2024-10-01 13:12:57 -07:00
Konstantin BogomolovandgVisor bot 4a0bf841d9 Don't return r2 from RawSyscalls.
In practice we don't seem to ever use it.

PiperOrigin-RevId: 681073641
2024-10-01 10:29:10 -07:00