16 Commits
Author SHA1 Message Date
Etienne Perot 0cd10e4a36 runsc boot: Add startup timer instrumentation.
Example output:

```
I0807 10:27:23.158030       1 timing.go:866] ---- runsc boot timing information ----
[10:27:22.991938]                               ╭─ runsc boot
[10:27:22.995285]        +3 346µs ▋             ├─ Go code running: 3 346µs
[10:27:22.996191]          +906µs ▏             ├─ boot subcommand dispatched: 906µs
[10:27:22.996643]          +451µs               ├─ CPUID initialized: 451µs
[10:27:22.996645]            +2µs               ├─ ring0 initialized: 2µs
[10:27:22.997012]          +367µs               ├─ host info read: 367µs
[10:27:22.998024]        +1 011µs ▏             ├─ spec read: 1 011µs
[10:27:22.998555]          +530µs               ├─ chroot base mounted: 530µs
[10:27:22.998822]          +267µs               ├─ chroot proc mounted: 267µs
[10:27:23.000271]        +1 449µs ▎             ├─ chroot procfs set up: 1 449µs
[10:27:23.000369]           +97µs               ├─ chroot sealed read-only: 97µs
[10:27:23.002635]        +2 266µs ▍             ├─ chroot set up: 2 266µs
[10:27:23.003523]          +887µs ▏             ├─ sandbox capabilities computed: 887µs
[10:27:23.003693]          +170µs               ├─ current capabilities read: 170µs
[10:27:23.012905]        +9 211µs ▉▊            ├─ bounding set trimmed on all threads: 9 211µs
[10:27:23.013139]          +233µs               ├─ capset applied on all threads: 233µs
[10:27:23.013449]          +310µs               ├─ capabilities applied: 310µs
[10:27:23.024366]       +10 916µs ▉▉            ├─ resolved mounts read: 10 916µs
[10:27:23.029416]        +5 049µs ▉             ├─ seccheck initialized: 5 049µs
[10:27:23.029419]            +3µs               ├─ RNG initialized: 3µs
[10:27:23.029571]          +152µs               ├─ memory usage initialized: 152µs
[10:27:23.029619]           +47µs               ├─ GOMAXPROCS set: 47µs
[10:27:23.057560]       +27 941µs ▉▉▉▉▉▍        ├─ stdio FDs remapped: 27 941µs
[10:27:23.057563]            +2µs               ├─ donated FDs ingested: 2µs
[10:27:23.057889]          +326µs               ├─ systrap memory file created: 326µs
[10:27:23.058714]          +825µs ▏             ├─ systrap stub initialized: 825µs
[10:27:23.063232]        +4 517µs █             ├─ systrap source process created: 4 517µs
[10:27:23.063244]           +12µs               ├─ waiting for membarrier: 12µs
[10:27:23.063246]            +1µs               ├─ host membarrier probed: 1µs
[10:27:23.063251]            +4µs               ├─ platform created: 4µs
[10:27:23.063390]          +138µs               ├─ memory file created: 138µs
[10:27:23.063438]           +48µs               ├─ VDSO prepared: 48µs
[10:27:23.063473]           +34µs               ├─ timekeeper configured: 34µs
[10:27:23.063675]          +201µs               ├─ network stack created: 201µs
[10:27:23.063854]          +179µs               ├─ kernel initialized: 179µs
[10:27:23.063859]            +4µs               ├─ filesystems registered: 4µs
[10:27:23.063943]           +84µs               ├─ process args created: 84µs
[10:27:23.063947]            +3µs               ├─ compat logs initialized: 3µs
[10:27:23.063948]            +0µs               ├─ mount hints parsed: 0µs
[10:27:23.063949]            +1µs               ├─ host FS mount created: 1µs
[10:27:23.064142]          +192µs               ├─ control server started: 192µs
[10:27:23.064142]            +0µs               ├─ loader created: 0µs
[10:27:23.064152]            +9µs               ├─ metrics initialized: 9µs
[10:27:23.064152]            +0µs               ├─ notifying parent: 0µs
[10:27:23.126745]       +62 592µs ▉▉▉▉▉▉▉▉▉▉▉▉  ├─ network args received: 62 592µs
[10:27:23.126972]          +227µs               ├─ start RPC received: 227µs
[10:27:23.126982]           +10µs               ├─ start signal received: 10µs
[10:27:23.127852]          +869µs ▏             ├─ network configured: 869µs
[10:27:23.128646]          +794µs ▏             ├─ open FDs validated: 794µs
[10:27:23.131274]        +2 628µs ▌             ├─ pre-seccomp callback done: 2 628µs
[10:27:23.132513]        +1 238µs ▎             ├─ seccomp rules computed: 1 238µs
[10:27:23.146898]       +14 384µs ▉▉▊           ├─ seccomp program compiled: 14 384µs
[10:27:23.148596]        +1 698µs ▎             ├─ seccomp program installed: 1 698µs
[10:27:23.148655]           +58µs               ├─ seccomp filters installed: 58µs
[10:27:23.148655]            +0µs               ├─ forked: 0µs                          ╭─ root container
[10:27:23.148876]          +220µs               │ ... 220µs ...                         ├─ FD table created: 220µs
[10:27:23.149125]          +249µs               │ ... 469µs ...                         ├─ cgroups mounted: 249µs
[10:27:23.149798]          +673µs ▏             │ ... 1 143µs ...                       ├─ rootfs mounted: 673µs
[10:27:23.149804]            +5µs               │ ... 1 148µs ...                       ├─ submounts prepared: 5µs
[10:27:23.150009]          +205µs               │ ... 1 353µs ...                       ├─ mounted "/dev": 205µs
[10:27:23.150362]          +352µs               │ ... 1 706µs ...                       ├─ mounted "/sys": 352µs
[10:27:23.150822]          +459µs               │ ... 2 166µs ...                       ├─ mounted "/proc": 459µs
[10:27:23.150886]           +63µs               │ ... 2 230µs ...                       ├─ mounted "/dev/pts": 63µs
[10:27:23.150915]           +29µs               │ ... 2 259µs ...                       ├─ mounted "/dev/shm": 29µs
[10:27:23.151200]          +285µs               │ ... 2 544µs ...                       ├─ mounted "/etc/hosts": 285µs
[10:27:23.151212]           +12µs               │ ... 2 557µs ...                       ├─ mounted "/dev/mqueue": 12µs
[10:27:23.151539]          +326µs               │ ... 2 883µs ...                       ├─ mounted "/etc/hostname": 326µs
[10:27:23.151660]          +121µs               │ ... 3 004µs ...                       ├─ mounted "/sys/fs/cgroup": 121µs
[10:27:23.151846]          +186µs               │ ... 3 190µs ...                       ├─ mounted "/etc/resolv.conf": 186µs
[10:27:23.151974]          +128µs               │ ... 3 319µs ...                       ├─ submounts mounted: 128µs
[10:27:23.151981]            +6µs               │ ... 3 325µs ...                       ├─ device files created: 6µs
[10:27:23.151981]            +0µs               │ ... 3 326µs ...                       ├─ executable path resolved: 0µs
[10:27:23.152057]           +75µs               │ ... 3 401µs ...                       ├─ exec user home resolved: 75µs
[10:27:23.152085]           +28µs               │ ... 3 429µs ...                       ├─ FS context created: 28µs
[10:27:23.153742]        +1 656µs ▎             │ ... 5 086µs ...                       ├─ memory manager created: 1 656µs
[10:27:23.156409]        +2 667µs ▌             │ ... 7 753µs ...                       ├─ executable loaded: 2 667µs
[10:27:23.156419]           +10µs               │ ... 7 763µs ...                       ├─ VDSO mapped: 10µs
[10:27:23.156425]            +5µs               │ ... 7 769µs ...                       ├─ stack allocated: 5µs
[10:27:23.156491]           +65µs               │ ... 7 835µs ...                       ├─ stack contents loaded: 65µs
[10:27:23.156497]            +5µs               │ ... 7 841µs ...                       ├─ task image loaded: 5µs
[10:27:23.156543]           +46µs               │ ... 7 887µs ...                       ├─ init task created: 46µs
[10:27:23.156599]           +56µs               ├─ root container created: 7 943µs      │ ... 56µs ...
[10:27:23.157146]          +547µs               ├─ signal forwarding started: 547µs     │ ... 603µs ...
[10:27:23.157575]          +428µs               ├─ kernel started: 428µs                │ ... 1 031µs ...
[10:27:23.157575]            +0µs               │ ... 0µs ...                           ╰─ END 1 032µs, total 8 919µs
[10:27:23.157576]            +1µs               ╰─ END 1µs, total 165 638µs
---- End of runsc boot timing information ----
```
2026-08-07 10:26:34 -07:00
Lucas ManningandgVisor bot f6f17a6ed8 Fix mm error handling during task image loading.
NewMemoryManager can return a non-linux error in some cases. This causes
a panic in syserr.FromError. We can handle the error more gracefully
by not panicking.

PiperOrigin-RevId: 915494807
2026-05-14 10:26:06 -07:00
gVisor bot 7465eeb020 Merge pull request #12598 from tamird:nogo-more-checks
PiperOrigin-RevId: 873002517
2026-02-20 11:35:37 -08:00
Jamie LiuandgVisor bot d7996a5d9b Remove "AddressSpace activation".
PiperOrigin-RevId: 869302553
2026-02-12 14:55:06 -08:00
Tamir Duberstein 2be07b55b6 Fix S1039 violations and drop suppression 2026-02-10 11:56:16 -08:00
Shailend ChandandgVisor bot 2c6185b9d1 Support privileged executables inside the sandbox
There is already some support for privileged executables before this change:
file capabilities were taken into account when creating new processes inside
the sandbox from external instigation (but not during execve(2)). set-user-id
and set-group-id bits were never taken into account, and the Sentry behaved
as if NO_NEW_PRIVS is always true. After this change, execve(2) and the
external Exec entry point both take the set-user(group)-id bits and file
capabilities into account.

Because NO_NEW_PRIVS can no longer be assumed to be always set, a couple of
extra checks to prevent privilege elevation during execve(2) are needed:
the presence of a ptracer and the use of a shared fsContext. Moreover,
execve had to be serialized with seccomp(2) when it is syncing filters to
all threads in a group. Serializing execve with PTRACE_ATTACH and seccomp
required some Task runState gymnastics.

Task dumpability is reset when privilege elevation takes place and privilege
elevation is denied for binaries living on nosuid mounts. To fix an old bug
where some aux vectors were populated using data from the old pre-execve
creds, the computation of the (file-privilege-augmented) creds during execve
now takes place before the stack for the new program is set up.

gvisor users who thus far have exec'd into the sandbox with UID as (sandbox)
root will lose the caps an all-powerful namespace root'd have if: 1) the binary
is a suid/guid binary 2) the owner of the binary is host root and there is
no mapping for host root in the host user namespace of the sandbox. To avoid
this surprise, the suid/sgid bits are ignored by default. Users can opt-in
via the --allow-suid flag.

One result of this change is that sudo now works inside the sandbox.

PiperOrigin-RevId: 794414101
2025-08-12 23:07:38 -07:00
Ayush RanjanandgVisor bot f3a6c7491e Delete pgalloc.MemoryFileProvider.
The work done in a9af2d309b ("Plumb restore context to afterLoad()") makes
pgalloc.MemoryFileProvider redundant as structs can now easily restore
pgalloc.MemoryFile in stateify's afterLoad() method. This allows structs to
have a pgalloc.MemoryFile field and use that directly, instead of going through
the provided interface.

This cleans up a lot of code and also should be more performant (avoids an
interface method call on many hot paths).

PiperOrigin-RevId: 615258927
2024-03-12 20:06:58 -07:00
Jing ChenandgVisor bot 8936746121 Return a task image's file capability when the image is loaded to be executed.
PiperOrigin-RevId: 613732844
2024-03-07 16:06:34 -08:00
Jamie LiuandgVisor bot fe546357e4 Pass context to kernel.TaskImage.release().
PiperOrigin-RevId: 543541608
2023-06-26 14:28:58 -07:00
Kevin KrakauerandgVisor bot 3a76efe831 convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Etienne PerotandgVisor bot 15e3dd3c3d gVisor: Turn arch.Context interface references to struct pointers.
Since `arch.Context64` is the only concrete implementation of
`arch.Context`, this does not functionally change anything.
While `arch.Context64` *can* mean multiple things in the codebase, since
the `arch` module uses conditional compilation to create different builds
for AMD64 vs ARM64, the `Context64` type is still singular within each
possible version this can compile to.

This avoids the overhead involved in calling interface
functions in Go:
https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#dynamic-dispatch

This overhead is particularly painful for functions like `SyscallSaveOrig`
which is a no-op on AMD64.

On KVM, this reduces syscall latency by 4~5%:

```
name       old wall_ns/op  new wall_ns/op  delta
Getpid           602 ± 4%        579 ± 3%  -3.94%  (p=0.000 n=66+195)
GetpidOpt        604 ± 3%        573 ± 3%  -5.10%  (p=0.000 n=71+194)

name       old cpu_ns/op   new cpu_ns/op   delta
Getpid           604 ± 5%        581 ± 0%  -3.81%  (p=0.000 n=75+130)
GetpidOpt        604 ± 2%        574 ± 3%  -4.95%  (p=0.000 n=71+196)
```

PiperOrigin-RevId: 461742893
2022-07-18 16:32:28 -07:00
Jamie LiuandgVisor bot 09cb4152f4 Add caller for the Execve checkpoint.
Binary fields are VFS2-only.

PiperOrigin-RevId: 424176912
2022-01-25 14:16:07 -08:00
Nicolas LacasseandgVisor bot 35f1723116 Fix lock order violations: mm.mappingMu > Task.mu.
Document this ordering in mm/mm.go.

PiperOrigin-RevId: 393413203
2021-08-27 13:18:49 -07:00
Zach KoopmansandgVisor bot 3b0fa805bb [syserror] Refactor linuxerr and error package.
Move Error struct to pkg/errors package for use in multiple places.
Move linuxerr static definitions under pkg/errors/linuxerr.
Add a lookup list for quick lookup of *errors.Error by errno. This is useful
when converting syserror errors and unix.Errno/syscall.Errrno values to
*errors.Error.
Update benchmarks routines to include conversions.

The below benchmarks show *errors.Error usage to be comparable to using
unix.Errno.

BenchmarkAssignUnix
BenchmarkAssignUnix-32                 	787875022	         1.284 ns/op
BenchmarkAssignLinuxerr
BenchmarkAssignLinuxerr-32             	1000000000	         1.209 ns/op
BenchmarkAssignSyserror
BenchmarkAssignSyserror-32             	759269229	         1.429 ns/op
BenchmarkCompareUnix
BenchmarkCompareUnix-32                	1000000000	         1.310 ns/op
BenchmarkCompareLinuxerr
BenchmarkCompareLinuxerr-32            	1000000000	         1.241 ns/op
BenchmarkCompareSyserror
BenchmarkCompareSyserror-32            	147196165	         8.248 ns/op
BenchmarkSwitchUnix
BenchmarkSwitchUnix-32                 	373233556	         3.664 ns/op
BenchmarkSwitchLinuxerr
BenchmarkSwitchLinuxerr-32             	476323929	         3.294 ns/op
BenchmarkSwitchSyserror
BenchmarkSwitchSyserror-32             	39293408	        29.62 ns/op
BenchmarkReturnUnix
BenchmarkReturnUnix-32                 	1000000000	         0.5042 ns/op
BenchmarkReturnLinuxerr
BenchmarkReturnLinuxerr-32             	1000000000	         0.8152 ns/op
BenchmarkConvertUnixLinuxerr
BenchmarkConvertUnixLinuxerr-32        	739948875	         1.547 ns/op
BenchmarkConvertUnixLinuxerrZero
BenchmarkConvertUnixLinuxerrZero-32    	977733974	         1.489 ns/op

PiperOrigin-RevId: 379806801
2021-06-16 14:08:52 -07:00
Zach KoopmansandgVisor bot d8f34027b3 [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Jamie LiuandgVisor bot 0dede4687f Rename kernel.TaskContext to kernel.TaskImage.
This reduces confusion with context.Context (which is also relevant to
kernel.Tasks) and is consistent with existing function kernel.LoadTaskImage().

PiperOrigin-RevId: 342167298
2020-11-12 17:39:19 -08:00