58 Commits
Author SHA1 Message Date
Xin ZhongandgVisor bot 488d530e97 seccheck: Trace sibling pipe processes in a client lib
PiperOrigin-RevId: 964771164
2026-08-14 10:39:17 -07:00
Xin ZhongandgVisor bot 1f06584417 seccheck: add binary_in_memfd to ExecveInfo
PiperOrigin-RevId: 953601428
2026-07-24 16:22:41 -07:00
Xin ZhongandgVisor bot 58866a1823 Add binary size and nlink to exec security check points.
PiperOrigin-RevId: 952306838
2026-07-22 13:45:36 -07:00
Xin ZhongandgVisor bot 8547939d22 seccheck: Add an LRU cache for execve binary SHA-256 and SHA-1 hashes.
This change introduces an LRU cache (ExecveHashCache) and multi-algorithm
calculation engine (file_hash.go) to store and resolve SHA-256 and SHA-1
digests of executables during execve syscalls.

PiperOrigin-RevId: 952257971
2026-07-22 12:11:46 -07:00
Xin ZhongandgVisor bot 1efbdb842d seccheck: Add execfn to ExecveInfo seccheck point
This change adds the execfn field to the ExecveInfo seccheck point.
This field preserves the original, unresolved pathname passed to
execve(2) (used for AT_EXECFN), distinguishing it from BinaryPath,
which contains the fully resolved filesystem path after symlink and
interpreter resolution.

Tests have been updated to verify the distinction between
BinaryPath, Execfn, and Argv[0].

PiperOrigin-RevId: 952211288
2026-07-22 10:50:32 -07:00
Xin ZhongandgVisor bot 937d896c97 Add seccheck field to indicate if a file is on an overlayfs lower layer.
This change introduces a new field `binary_overlayfs_lower` in the
`ExecveBinaryInfo` seccheck point. This field is set to true if the executed
binary is found on one of the lower layers of an overlay filesystem. A helper
function `overlay.IsOnLower` is added to determine this. The existing
`binary_overlayfs_upper` field is also clarified to represent any file on
the upper layer.

PiperOrigin-RevId: 949711533
2026-07-17 12:50:20 -07:00
Xin ZhongandgVisor bot 1366eb443a Add seccheck support for collecting stdin/stdout/stderr info on execve.
This change introduces a new seccheck field, FieldSentryExecveFdInfo, for the
Execve trace point. When enabled, this field collects information about file
descriptors 0, 1, and 2 (stdin, stdout, stderr) and populates the new stdin,
stdout, and stderr fields in the ExecveInfo proto. The collected FdInfo
includes the file path, mode, inode, whether it's on an overlayfs upper
layer, and socket details (local/remote addresses) if the FD is a socket.

PiperOrigin-RevId: 948482163
2026-07-15 12:33:22 -07:00
Xin ZhongandgVisor bot a8bd23b455 Add executable ctime to ExecveInfo and MmapInfo.
This change includes the creation time (ctime) of the executable binary in the
seccheck ExecveInfo and MmapInfo.

The Timespec proto message is moved to common.proto for reuse.

PiperOrigin-RevId: 948385290
2026-07-15 09:42:22 -07:00
Xin ZhongandgVisor bot dd438bd876 Add executable inode number to seccheck ExecveBinaryInfo.
PiperOrigin-RevId: 945774987
2026-07-10 10:23:38 -07:00
Xin ZhongandgVisor bot 5b0c4003be Add seccheck field to indicate if executed binary is on overlayfs upper layer.
This change introduces a new field `binary_overlayfs_upper` to the
`ExecveBinaryInfo` seccheck point. This field is set to true if the executable
being run is located on the upper layer of an overlay filesystem. A new helper
function `overlay.IsCopiedUp` is added to check this condition.

PiperOrigin-RevId: 944568906
2026-07-08 10:23:45 -07:00
Shailend ChandandgVisor bot 329cdabbf5 Implement pidfds
This patch introduces pidfd support roughly up to Linux 6.8. Linux selftests
at this version pass, and are now run as an //image_test target. Some features,
like PIDFD_THREAD, that occur later than 6.8 in Linux, are included.

It includes:
- These new syscalls:
  - pidfd_open()
  - pidfd_getfd()
  - pidfd_send_signal()
- New aspects to these existing syscalls:
  - waitid() in its support of P_PIDFD
  - clone()/clone3() in their support of CLONE_PIDFD
  - poll()/epoll()/select() in their support for pidfds
  - setns() in its support for pidfds
  - pid introspection via /proc/[pid]/fdinfo/[pidfd]

It excludes:
- pidfdfs: pidfds are backed by the anon inode right now
- ioctls to retrieve namespace fds using a pidfd
- process_madvise()

Updates #5839.

PiperOrigin-RevId: 908341658
2026-04-30 13:22:58 -07:00
Jamie LiuandgVisor bot d7996a5d9b Remove "AddressSpace activation".
PiperOrigin-RevId: 869302553
2026-02-12 14:55:06 -08:00
Shailend ChandandgVisor bot 1b546ce933 Fix race between unshare(2) and execve(2).
There are two issues being fixed: 1) checkAndPreventSharingOutsideTG() was
accessing t.fsContext without grabbing t.mu and thus causing a data race with
a concurrent unshare and 2) the concurrent unshare might present an incomplete
view of the shared fscontext and cause execve to incorrectly conclude that it
was shared outside the thread group.

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 800327461
2025-08-27 23:52:21 -07: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
Andrei VaginandgVisor bot 3b48b4a29a kernel: handle MemoryManager().Activate() errors
Report panic just like Task.Active. Otherwise, it can report misleading errors
like: "panic: trying to use inactive address space?"
PiperOrigin-RevId: 791013732
2025-08-04 20:42:19 -07:00
Jamie LiuandgVisor bot c38bbe4dee sentry/kernel: don't use Task.mu to protect Task.creds
Task.creds is documented as being "owned by the task goroutine", i.e. it can
only be mutated by the task goroutine, precluding the need for writer
synchronization. (AFAIK, no current Linux feature permits one task to change
another's credentials; capset(2) did before the introduction of VFS
capabilities, but gVisor doesn't support this. Libcs implement functions like
setresuid() by signaling every thread to execute the setresuid() syscall to
change their own credentials.) Prior to cl/185803179 and cl/205315612, the
mutex was needed to avoid data races on auth.Credentials fields; then prior to
cl/254989492, the mutex was needed to avoid data races on the auth.Credentials
pointer; now the mutex is not needed at all.

PiperOrigin-RevId: 777692758
2025-06-30 13:21:50 -07:00
Fabricio VoznikaandgVisor bot d3cc90d077 Add missing binary_sha256 field
Fixes #11466

PiperOrigin-RevId: 734209881
2025-03-06 11:01:58 -08:00
Jimmy TranandgVisor bot 392f4360b5 Return EACCES when calling setpgid() after execve()
From setpgid manpage,

EACCES - An attempt was made to change the process group ID of one
of the children of the calling process and the child had
already performed an execve(2) (setpgid(), setpgrp()).

This CL makes gVisor implement this rule and updates the exec test
suite accordingly.

TESTED: http://sponge2/7f364e8a-4f82-463e-ba62-79234c4d054d
PiperOrigin-RevId: 727095560
2025-02-14 16:14:14 -08:00
Jamie LiuandgVisor bot 76a011743d kernel: add ThreadGroup.signalLock()
This allows "remote" locking of ThreadGroup.signalHandlers.mu without needing
to lock TaskSet.mu, analogously to Linux's lock_task_sighand().

This reveals a bug: kernel.Task.sendSignal[Timer]Locked() unintentionally
requires TaskSet.mu to be locked since it reads Task.exitState. To fix this,
use atomic memory operations on Task.exitState when required.

PiperOrigin-RevId: 681128063
2024-10-01 12:48:10 -07:00
Etienne PerotandgVisor bot 3495c7e7d5 Use clear on map types wherever possible.
This is similar as pull request #9749 but for maps rather than slices.

PiperOrigin-RevId: 586504320
2023-11-29 18:00:07 -08:00
Jamie LiuandgVisor bot fe546357e4 Pass context to kernel.TaskImage.release().
PiperOrigin-RevId: 543541608
2023-06-26 14:28:58 -07:00
Andrei Vagin 2c35bc8656 kernel: release kernel.taskSetRWMutex before calling TaskImage.Release
Reported-by: [email protected]
2023-03-16 10:25:46 -07:00
Ayush RanjanandgVisor bot 64e8ac9ea1 Delete fsbridge.
Updates #1624

PiperOrigin-RevId: 492286535
2022-12-01 13:36:10 -08:00
Ayush RanjanandgVisor bot 1003ae8e93 Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Zach KoopmansandgVisor bot 9cf42afc65 [sst] Cleanup TODOs for SecurityMessages
PiperOrigin-RevId: 464589591
2022-08-01 12:04:31 -07:00
Fabricio VoznikaandgVisor bot 59f1b78fd5 Rename seccheck.checkers to seccheck.sinks
Makes the naming consistent with the public configuration. There is no
behavior change.

Updates #4805

PiperOrigin-RevId: 462448505
2022-07-21 12:47:06 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Fabricio VoznikaandgVisor bot 974fc32a4d Add Points to some syscalls
Added a raw syscall points to all syscalls. Added schematized syscall
points to the following syscalls:

  - read
  - close
  - socket
  - connect
  - execve
  - creat
  - openat
  - execveat

Updates #4805

PiperOrigin-RevId: 446008358
2022-05-02 13:03:04 -07:00
Fabricio VoznikaandgVisor bot 81eaf62655 Refactor code to use seccheck.SendToCheckers
Updates #4805

PiperOrigin-RevId: 445017536
2022-04-27 18:04:14 -07:00
Fabricio VoznikaandgVisor bot 93023f5e60 Use proto structs for seccheck points
Given that in most cases points are serialized to another process,
point data is now created diretly into protos.

As part of this change, infrastructure to track optional and context
fields was created to facilitate addition of lots of Points which is
needed for upcomming of changes.

Updates #4805

Currently the SST code is converting seccheck protos into SST protos
in the sentry before sending it to the API. After this change, SST
checker will be changed to send seccheck protos to the API and the
API then converts these into SST on the way to pubsub.

PiperOrigin-RevId: 442688320
2022-04-18 19:03:15 -07:00
Konstantin BogomolovandgVisor bot 03113543e2 Implement close_range.
Fixes #5500

PiperOrigin-RevId: 431454836
2022-02-28 09:37:03 -08: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 f26a93e634 [syserror] Convert remaining syserror definitions to linuxerr.
Convert remaining public errors (e.g. EINTR) from syserror to linuxerr.

PiperOrigin-RevId: 390471763
2021-08-12 15:19:12 -07:00
Ayush RanjanandgVisor bot 13128df6e1 [op] Move SignalStack to abi/linux package.
Updates #214

PiperOrigin-RevId: 378594929
2021-06-10 01:00:24 -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
Michael PrattandgVisor bot 1ca04daf73 Consistent precondition formatting
Our "Preconditions:" blocks are very useful to determine the input invariants,
but they are bit inconsistent throughout the codebase, which makes them harder
to read (particularly cases with 5+ conditions in a single paragraph).

I've reformatted all of the cases to fit in simple rules:

1. Cases with a single condition are placed on a single line.
2. Cases with multiple conditions are placed in a bulleted list.

This format has been added to the style guide.

I've also mentioned "Postconditions:", though those are much less frequently
used, and all uses already match this style.

PiperOrigin-RevId: 327687465
2020-08-20 13:32:24 -07:00
Andrei VaginandgVisor bot 82a70c9144 Add context.FullStateChanged()
It indicates that the Sentry has changed the state of the thread and
next calls of PullFullState() has to do nothing.

PiperOrigin-RevId: 325567415
2020-08-07 22:49:55 -07:00
Nayana BidariandgVisor bot 4a8d0d3f20 Plumbing context.Context to DecRef() and Release().
context is passed to DecRef() and Release() which is
needed for SO_LINGER implementation.

PiperOrigin-RevId: 324672584
2020-08-03 13:36:05 -07:00
Nicolas LacasseandgVisor bot 86dc46113e Implement get/set_robust_list.
PiperOrigin-RevId: 322904430
2020-07-23 17:42:50 -07:00
Andrei VaginandgVisor bot d10004dd2d Unshare files on exec
The current task can share its fdtable with a few other tasks,
but after exec, this should be a completely separate process.

PiperOrigin-RevId: 314999565
2020-06-05 14:45:32 -07:00
Fabricio VoznikaandgVisor bot 849c8e1258 Add option to skip stuck tasks waiting for address space
PiperOrigin-RevId: 297192390
2020-02-25 13:44:18 -08:00
Fabricio VoznikaandgVisor bot 561e23dec4 Add vfs.FileDescription to FD table
FD table now holds both VFS1 and VFS2 types and uses the correct
one based on what's set.

Parts of this CL are just initial changes (e.g. sys_read.go,
runsc/main.go) to serve as a template for the remaining changes.

Updates #1487
Updates #1623

PiperOrigin-RevId: 292023223
2020-01-28 15:31:03 -08:00
Michael PrattandgVisor bot fa67a4368a Implement rseq(2)
PiperOrigin-RevId: 288342928
2020-01-06 11:42:44 -08:00
Adin ScannellandgVisor bot 25b09ce49b Add runtime tracing.
This adds meaningful annotations to the trace generated by the runtime/trace
package.

PiperOrigin-RevId: 284290115
2019-12-06 17:00:07 -08:00
Adin ScannellandgVisor bot 753da9604e Remove map from fd_map, change to fd_table.
This renames FDMap to FDTable and drops the kernel.FD type, which had an entire
package to itself and didn't serve much use (it was freely cast between types,
and served as more of an annoyance than providing any protection.)

Based on BenchmarkFDLookupAndDecRef-12, we can expect 5-10 ns per lookup
operation, and 10-15 ns per concurrent lookup operation of savings.

This also fixes two tangential usage issues with the FDMap. Namely, non-atomic
use of NewFDFrom and associated calls to Remove (that are both racy and fail to
drop the reference on the underlying file.)

PiperOrigin-RevId: 256285890
2019-07-02 19:28:59 -07:00
Adin ScannellandShentubot add40fd6ad Update canonical repository.
This can be merged after:
https://github.com/google/gvisor-website/pull/77
  or
https://github.com/google/gvisor-website/pull/78

PiperOrigin-RevId: 253132620
2019-06-13 16:50:15 -07:00
Michael PrattandShentubot d3ed9baac0 Implement dumpability tracking and checks
We don't actually support core dumps, but some applications want to
get/set dumpability, which still has an effect in procfs.

Lack of support for set-uid binaries or fs creds simplifies things a
bit.

As-is, processes started via CreateProcess (i.e., init and sentryctl
exec) have normal dumpability. I'm a bit torn on whether sentryctl exec
tasks should be dumpable, but at least since they have no parent normal
UID/GID checks should protect them.

PiperOrigin-RevId: 251712714
2019-06-05 14:00:13 -07:00
Michael PrattandShentubot 4d52a55201 Change copyright notice to "The gVisor Authors"
Based on the guidelines at
https://opensource.google.com/docs/releasing/authors/.

1. $ rg -l "Google LLC" | xargs sed -i 's/Google LLC.*/The gVisor Authors./'
2. Manual fixup of "Google Inc" references.
3. Add AUTHORS file. Authors may request to be added to this file.
4. Point netstack AUTHORS to gVisor AUTHORS. Drop CONTRIBUTORS.

Fixes #209

PiperOrigin-RevId: 245823212
Change-Id: I64530b24ad021a7d683137459cafc510f5ee1de9
2019-04-29 14:26:23 -07:00
Nicolas LacasseandShentubot f4ce43e1f4 Allow and document bug ids in gVisor codebase.
PiperOrigin-RevId: 245818639
Change-Id: I03703ef0fb9b6675955637b9fe2776204c545789
2019-04-29 14:04:14 -07:00