58 Commits
Author SHA1 Message Date
Ryan El Kochta f9d533b8ce SO_PEERCRED: fix race against thread-group reap
NewSCMCredentials previously resolved the specified PID into a thread group with separate calls to ThreadGroupWithID() and PIDNamespacedIDs().
Both of these functions separately take and release the TaskSet lock.

This causes a race condition where between the two function calls, the thread group might get reaped, leading to the panic() being reached.

This commit addresses this issue by moving the thread group resolution/PID namespace map creation into a single critical section.
A regression syscall test is also included.

Reported-by: [email protected]
2026-07-31 09:31:46 -07:00
Etienne Perot f36bad2517 UDS: Transfer SCM_RIGHTS into enqueued messages. 2026-07-29 16:36:25 -07:00
Ryan El Kochta ad1f2ef91a SCM_CREDENTIALS: use PID from ucred rather than caller's PID
Previously, the caller-provided PID was used for the CAP_SYS_ADMIN check, but wasn't actually passed along.
2026-06-30 10:18:20 -07:00
Ryan El Kochta 40e377ce90 SO_PEERCRED: snapshot peer pid instead of looking up upon getsockopt()
Previously, scmCredentials stored a *kernel.Task, from which the peer
pid could be looked up when getsockopt() was called with SO_PEERCRED.
However, if the peer had since died, the lookup would fail and the
returned pid would be 0.

Instead, we should store a snapshot of the *pid*, not the Task pointer.
The lookup should happen at open time, not at getsockopt() time.

This does mean that the returned pid may be stale, but this happens on
Linux too, so userspace should know to avoid racy behavior with the
returned PID.

Other things changed:
- Since the cred is a PID, not a TID, use the task group ID instead of
  task ID
- Add a test for SO_PEERCRED across a different PID namespace
2026-06-15 11:48:14 -07:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -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
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
Ayush RanjanandgVisor bot 7cac4e2732 Start cleaning up VFS1.
PiperOrigin-RevId: 486586072
2022-11-07 00:39:54 -08:00
Arthur SfezandgVisor bot 4dbf587b07 Support sending TTL and HopLimit
PiperOrigin-RevId: 430554985
2022-02-23 15:40:37 -08:00
Arthur SfezandgVisor bot 1d2822917b Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Arthur SfezandgVisor bot 7ea73a6830 Support receiving PKTINFO on icmp endpoints
PiperOrigin-RevId: 428599075
2022-02-14 13:51:49 -08:00
Ayush RanjanandgVisor bot a941d15831 Move HostConnectedEndpoint and SCMConnectedEndpoint to transport package.
This is needed so that connectioned endpoint in the transport package can use
this endpoint to implement host FD based binded endpoints.

I had to simplify some other dependencies to make this possible.
- Removed uniqueid's dependency on transport package completely.
- Removed SCMConnectedEndpoint and HostConnectedEndpoint's dependency on
  control package so they could be moved to transport. control already depends
  on transport.
- scmRights struct from fsimpl/host/control.go had to be moved into transport
  so that  HostConnectedEndpoint could be implemented. But scmRights.Fill()
  could not be moved because it inherently depends on making
  vfs.FileDescriptions which depends on vfs which in turn depends on transport.
  So now that scmRights -> vfs.FD conversion happens in the syscall package.

PiperOrigin-RevId: 413839350
2021-12-02 21:16:58 -08:00
Andrei VaginandgVisor bot 59305c72b9 Validate ControlMessageHeader.Length
Reported-by: [email protected]
PiperOrigin-RevId: 408776291
2021-11-09 20:58:59 -08:00
Ayush RanjanandgVisor bot c7f074fc3b Make {Un}Marshal{Bytes/Unsafe} return remaining buffer.
Change marshal.Marshallable method signatures to return the remaining buffer.
This makes it easier to implement these method manually. Without this, we would
have to manually do buffer shifting which is error prone.

tools/go_marshal/test:benchmark test does not show change in performance.
Additionally fixed some marshalling bugs in fsimpl/fuse.

Updated multiple callpoints to get rid of redundant slice indexing work and
simplified code using this new signature.

Updates #6450

PiperOrigin-RevId: 407857019
2021-11-05 10:43:49 -07:00
Tamir DubersteinandgVisor bot 6808bf0c45 Store timestamps as time.Time
Rather than boiling down to an integer eagerly, do it as late as possible.

PiperOrigin-RevId: 401599308
2021-10-07 14:04:55 -07:00
Ghanan GowripalanandgVisor bot 44f496d24f Support IPV6_RECVPKTINFO on UDP sockets
PiperOrigin-RevId: 397631833
2021-09-19 13:15:28 -07:00
Zach KoopmansandgVisor bot 895c2eaa09 [syserror] Update syserror to linuxerr for EACCES, EBADF, and EPERM.
Update all instances of the above errors to the faster linuxerr implementation.
With the temporary linuxerr.Equals(), no logical changes are made.

PiperOrigin-RevId: 382306655
2021-06-30 08:18:59 -07:00
Zach KoopmansandgVisor bot cd84634cc0 [syserror] Change syserror to linuxerr for E2BIG, EADDRINUSE, and EINVAL
Remove three syserror entries duplicated in linuxerr. Because of the
linuxerr.Equals method, this is a mere change of return values from
syserror to linuxerr definitions.

Done with only these three errnos as CLs removing all grow to a significantly
large size.

PiperOrigin-RevId: 382173835
2021-06-29 15:08:46 -07:00
Rahat MahmoodandgVisor bot 3246444f6f Remove uses of the binary package from networking code.
Co-Author: ayushranjan
PiperOrigin-RevId: 370785009
2021-04-27 16:20:01 -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
Kevin KrakauerandgVisor bot 7b37fe39e2 Fix panic when parsing SO_TIMESTAMP cmsg
PiperOrigin-RevId: 350223482
2021-01-05 14:45:47 -08:00
Ayush RanjanandgVisor bot 130220dd6c [netstack] Implement MSG_ERRQUEUE flag for recvmsg(2).
Introduces the per-socket error queue and the necessary cmsg mechanisms.

PiperOrigin-RevId: 348028508
2020-12-17 08:47:24 -08:00
Ayush RanjanandgVisor bot 17d539fe08 [netstack] Update raw socket and hostinet control message parsing.
There are surprisingly few syscall tests that run with hostinet. For example
running the following command only returns two results:
`bazel query test/syscalls:all | grep hostnet`

I think as a result, as our control messages evolved, hostinet was left
behind. Update it to support all control messages netstack supports.

This change also updates sentry's control message parsing logic to make it up to
date with all the control messages we support.

PiperOrigin-RevId: 347508892
2020-12-14 18:00:55 -08:00
Ayush RanjanandgVisor bot 8f6c40d2c6 [netstack] Decouple tcpip.ControlMessages from the IP control messges.
tcpip.ControlMessages can not contain Linux specific structures which makes it
painful to convert back and forth from Linux to tcpip back to Linux when passing
around control messages in hostinet and raw sockets.

Now we convert to the Linux version of the control message as soon as we are
out of tcpip.

PiperOrigin-RevId: 347027065
2020-12-11 10:33:58 -08:00
Bhasker HariharanandShentubot 59b6de71b6 Add support for IP_RECVORIGDSTADDR IP option.
Fixes #5004

PiperOrigin-RevId: 346643745
2020-12-09 15:58:53 -08:00
Ting-Yu WangandgVisor bot d99406cbd8 Fix nogo tests in //pkg/sentry/socket/...
PiperOrigin-RevId: 338784921
2020-10-23 19:24:09 -07:00
Jamie LiuandgVisor bot 114d68adb8 Support VFS2 save/restore.
Inode number consistency checks are now skipped in save/restore tests for
reasons described in greatest detail in StatTest.StateDoesntChangeAfterRename.
They pass in VFS1 due to the bug described in new test case
SimpleStatTest.DifferentFilesHaveDifferentDeviceInodeNumberPairs.

Fixes #1663

PiperOrigin-RevId: 338776148
2020-10-23 17:48:33 -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
Dean DengandgVisor bot f4376a8c08 Port SCM Rights to VFS2.
Fixes #1477.

PiperOrigin-RevId: 308317511
2020-04-24 13:46:58 -07:00
gVisor bot bdc6e0e03f Enable IPV6_RECVTCLASS socket option for datagram sockets
Added the ability to get/set the IP_RECVTCLASS socket option on UDP endpoints.
If enabled, traffic class from the incoming Network Header passed as ancillary
data in the ControlMessages.

Adding Get/SetSockOptBool to decrease the overhead of getting/setting simple
options. (This was absorbed in a CL that will be landing before this one).

Test:
* Added unit test to udp_test.go that tests getting/setting as well as
verifying that we receive expected TOS from incoming packet.
* Added a syscall test for verifying getting/setting
* Removed test skip for existing syscall test to enable end to end test.
PiperOrigin-RevId: 295840218
2020-02-18 15:45:36 -08:00
gVisor bot 33f622bb7e Internal change.
PiperOrigin-RevId: 294952610
2020-02-13 10:59:52 -08:00
gVisor bot ba419a78a0 Move Align{Up,Down} into binary package.
PiperOrigin-RevId: 294477647
2020-02-11 11:09:31 -08:00
Adin ScannellandgVisor bot 4368058004 Update package locations.
Because the abi will depend on the core types for marshalling (usermem,
context, safemem, safecopy), these need to be flattened from the sentry
directory. These packages contain no sentry-specific details.

PiperOrigin-RevId: 291811289
2020-01-27 15:31:32 -08:00
Adin ScannellandgVisor bot 5cd5c2536a Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Tamir DubersteinandgVisor bot 76dfa05358 Implement {g,s}etsockopt(IP_RECVTOS) for UDP sockets
PiperOrigin-RevId: 289718534
2020-01-14 13:33:23 -08:00
Ting-Yu WangandgVisor bot ff943d5ed4 Fix slice bounds out of range panic in parsing socket control message.
Panic found by syzakller.

PiperOrigin-RevId: 288799046
2020-01-08 16:32:34 -08:00
gVisor bot fd665256c3 Automated rollback of changelist 287029703
PiperOrigin-RevId: 287217899
2019-12-26 13:05:52 -08:00
Ryan HeacockandgVisor bot 2ce69e673d Enable IP_RECVTOS socket option for datagram sockets
Added the ability to get/set the IP_RECVTOS socket option on UDP endpoints. If
enabled, TOS from the incoming Network Header passed as ancillary data in the
ControlMessages.

Test:
* Added unit test to udp_test.go that tests getting/setting as well as
verifying that we receive expected TOS from incoming packet.
* Added a syscall test
PiperOrigin-RevId: 287029703
2019-12-24 08:49:39 -08:00
Dean DengandgVisor bot f92ca64b27 Deduplicate and simplify control message processing for recvmsg and sendmsg.
Also, improve performance by calculating how much space is needed before making
an allocation for sendmsg in hostinet.

PiperOrigin-RevId: 284898581
2019-12-10 19:27:42 -08:00
Dean DengandgVisor bot 96fb4a9f2f Make comments clearer for control message handling.
PiperOrigin-RevId: 284791600
2019-12-10 10:01:06 -08:00
Dean DengandgVisor bot e33ae07b86 Support sending IP_TOS and IPV6_TCLASS control messages with hostinet sockets.
There are two potential ways of sending a TOS byte with outgoing packets:
including a control message in sendmsg, or setting the IP_TOS/IPV6_TCLASS
socket options (for IPV4 and IPV6 respectively). This change lets hostinet
support the former.

PiperOrigin-RevId: 283346737
2019-12-02 08:40:16 -08:00
Dean DengandgVisor bot 9770189cb7 Add support for receiving TOS and TCLASS control messages in hostinet.
This involves allowing getsockopt/setsockopt for the corresponding socket
options, as well as allowing hostinet to process control messages received from
the actual recvmsg syscall.

PiperOrigin-RevId: 282851425
2019-11-27 16:21:05 -08:00
Kevin KrakauerandgVisor bot 4da30beb39 Reorder BUILD license and load functions in gvisor.
PiperOrigin-RevId: 275139066
2019-10-16 16:40:30 -07:00
Andrei VaginandgVisor bot d6184e0c3d net/tcp/setockopt: impelment setsockopt(fd, SOL_TCP, TCP_INQ)
PiperOrigin-RevId: 258859507
2019-07-18 15:41:04 -07: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
Andrei VaginandShentubot 90a116890f gvisor/sock/unix: pass creds when a message is sent between unconnected sockets
and don't report a sender address if it doesn't have one

PiperOrigin-RevId: 251371284
2019-06-03 21:48:19 -07:00
Ian GudgerandShentubot 81ecd8b6ea Implement the MSG_CTRUNC msghdr flag for Unix sockets.
Updates google/gvisor#206

PiperOrigin-RevId: 245880573
Change-Id: Ifa715e98d47f64b8a32b04ae9378d6cd6bd4025e
2019-04-29 21:21:08 -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
Michael PrattandShentubot 2a0c69b19f Remove license comments
Nothing reads them and they can simply get stale.

Generated with:
$ sed -i "s/licenses(\(.*\)).*/licenses(\1)/" **/BUILD

PiperOrigin-RevId: 231818945
Change-Id: Ibc3f9838546b7e94f13f217060d31f4ada9d4bf0
2019-01-31 11:12:53 -08:00