66 Commits
Author SHA1 Message Date
Ryan El Kochta b7ed3549ef getsockopt(2): only copy out data up to optLen bytes
This frees implementations of getsockopt to no longer return EINVAL when
userspace specifies a buffer smaller than the output.

Some callers, such as resolved, pass a null buffer to probe the output
size before passing a real buffer to getsockopt. This allows those
callers to succeed.

This commit also removes EINVAL returns from netlink route sockets related to
the userspace-provided size to allow this pattern.
2026-06-17 16:40:21 -07:00
Amir Alavi 9c89c4a7f0 fix(setsockopt): increase maxOptLen from 8KB to 32KB
The hard-coded maxOptLen of 8192 bytes silently rejected
setsockopt(IPT_SO_SET_REPLACE) payloads with EINVAL when the
iptables ruleset exceeded 8KB. This broke real-world workloads such
as Istio 1.28+ service mesh, whose istio-init container generates
nat table rulesets of ~13KB.

This raises the limit to 32KB, which provides ~2.5x headroom over
the largest known real-world payload. Linux itself limits this to
INT_MAX (net/socket.c: do_sock_setsockopt); other container runtimes
(runc, Kata Containers) inherit that limit by delegating to the host
kernel. We use a conservative 32KB here to balance compatibility with
resource protection in the sentry.

Fixes #12685

Signed-off-by: Amir Alavi <[email protected]>
2026-03-07 20:22:26 -05:00
Jamie LiuandgVisor bot d7996a5d9b Remove "AddressSpace activation".
PiperOrigin-RevId: 869302553
2026-02-12 14:55:06 -08:00
Jamie LiuandgVisor bot 19f12e64c8 Move //pkg/sentry/kernel/time to //pkg/sentry/ktime.
This avoids needing to rename it everywhere it's imported.

PiperOrigin-RevId: 693930089
2024-11-06 18:13:51 -08:00
Etienne PerotandgVisor bot da6948a692 gVisor: Refactor SyscallFn to take in the syscall number as argument.
This will be used to plumb the syscall number through to a counter metric that
exports the number of times an unimplemented syscall has been called.

Plenty of syscall implementations call `EmitUnimplementedEvent` for flags and
settings that are not implemented. With `sysno` available, they will be able
to plumb that bit of information through.

PiperOrigin-RevId: 518635831
2023-03-22 12:06:26 -07: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
Ayush RanjanandgVisor bot d90d0743d3 Delete VFS1 syscall handlers.
Directly use VFS2 syscall handlers. No need to override VFS2 handlers.
Updates #1624

PiperOrigin-RevId: 488448348
2022-11-14 13:11:22 -08:00
Zach KoopmansandgVisor bot 17d151514d [syserr] Move ConvertIntr function to linuxerr package
Move ConverIntr out of syserr package and delete an unused function.

PiperOrigin-RevId: 407676258
2021-11-04 14:55:52 -07:00
Zach KoopmansandgVisor bot 83bf514e27 [syserror] Remove pkg syserror.
Removes package syserror and moves still relevant code to either linuxerr
or to syserr (to be later removed).

Internal errors are converted from random types to *errors.Error types used
in linuxerr. Internal errors are in linuxerr/internal.go.

PiperOrigin-RevId: 390724202
2021-08-13 17:16:52 -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
Zach KoopmansandgVisor bot 5e6d494c2f [syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent:
EEXIST
EFAULT
ENOTDIR
ENOTTY
EOPNOTSUPP
ERANGE
ESRCH

PiperOrigin-RevId: 384329869
2021-07-12 15:26:20 -07:00
Zach KoopmansandgVisor bot f033577349 [syserror] Update several syserror errors to linuxerr equivalents.
Update/remove most syserror errors to linuxerr equivalents. For list
of removed errors, see //pkg/syserror/syserror.go.

PiperOrigin-RevId: 382574582
2021-07-01 12:05:19 -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
Zach KoopmansandgVisor bot 45b64220cb [syserror] Add conversions to linuxerr with temporary Equals method.
Add Equals method to compare syserror and unix.Errno errors to linuxerr errors.
This will facilitate removal of syserror definitions in a followup, and
finding needed conversions from unix.Errno to linuxerr.

PiperOrigin-RevId: 380909667
2021-06-22 15:53:32 -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
Bhasker HariharanandgVisor bot 045f060030 Fix AF_UNIX listen() w/ zero backlog.
In https://github.com/google/gvisor/commit/f075522849fa a check to increase zero
to a minimum backlog length was removed from sys_socket.go to bring it in parity
with linux and then in tcp/endpoint.go we bump backlog by 1. But this broke
calling listen on a AF_UNIX socket w/ a zero backlog as in linux it does allow 1
connection even with a zero backlog.

This was caught by a php runtime test socket_abstract_path.phpt.

PiperOrigin-RevId: 369974744
2021-04-22 16:34:00 -07:00
Mithun IyerandgVisor bot a7edb1fdea Move maxListenBacklog check to sentry
Move maxListenBacklog check to the caller of endpoint Listen so that it
is applicable to Unix domain sockets as well.
This was changed in cl/366935921.

Reported-by: [email protected]
PiperOrigin-RevId: 367728052
2021-04-09 16:53:33 -07:00
Mithun IyerandgVisor bot a85065cdb7 Fix listen backlog handling to be in parity with Linux
- Change the accept queue full condition for a listening endpoint
  to only honor completed (and delivered) connections.
- Use syncookies if the number of incomplete connections is beyond
  listen backlog. This also cleans up the SynThreshold option code
  as that is no longer used with this change.
- Added a new stack option to unconditionally generate syncookies.
  Similar to sysctl -w net.ipv4.tcp_syncookies=2 on Linux.
- Enable keeping of incomplete connections beyond listen backlog.
- Drop incoming SYNs only if the accept queue is filled up.
- Drop incoming ACKs that complete handshakes when accept queue is full
- Enable the stack to accept one more connection than programmed by
  listen backlog.
- Handle backlog argument being zero, negative for listen, as Linux.
- Add syscall and packetimpact tests to reflect the changes above.
- Remove TCPConnectBacklog test which is polling for completed
  connections on the client side which is not reflective of whether
  the accept queue is filled up by the test. The modified syscall test
  in this CL addresses testing of connecting sockets.

Fixes #3153

PiperOrigin-RevId: 366935921
2021-04-05 21:53:41 -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
Andrei VaginandgVisor bot 0d828f36a6 unix: sendmmsg and recvmsg have to cap a number of message to UIO_MAXIOV
Reported-by: [email protected]
PiperOrigin-RevId: 358866218
2021-02-22 11:51:30 -08:00
Ayush RanjanandgVisor bot a2d387b416 [go-marshal] Remove binary package reference from syscalls package.
Fixes a bug in our getsockopt(2) implementation which was incorrectly using
binary.Size() instead of Marshallable.SizeBytes().

PiperOrigin-RevId: 356396551
2021-02-08 18:02:35 -08: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 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
Dean DengandgVisor bot 094917b657 Fix SCM Rights reference leaks.
Control messages should be released on Read (which ignores the control message)
or zero-byte Send. Otherwise, open fds sent through the control messages will
be leaked.

PiperOrigin-RevId: 337110774
2020-10-14 09:54:05 -07:00
Rahat MahmoodandgVisor bot c25d44649f Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Rahat MahmoodandgVisor bot 172800eed9 Move the 'marshal' and 'primitive' packages to the 'pkg' directory.
PiperOrigin-RevId: 331256608
2020-09-11 17:42:49 -07:00
Nayana BidariandgVisor bot f4d7d0e8b3 Fix panic when calling dup2().
PiperOrigin-RevId: 329572337
2020-09-01 13:41:01 -07:00
Dean DengandgVisor bot af68364c51 Move ERESTART* error definitions to syserror package.
This is needed to avoid circular dependencies between the vfs and kernel
packages.

PiperOrigin-RevId: 327355524
2020-08-18 19:28:53 -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
823cc9c8ee Marshallable socket opitons.
Socket option values are now required to implement marshal.Marshallable.

Co-authored-by: Rahat Mahmood <[email protected]>
PiperOrigin-RevId: 322831612
2020-07-23 11:45:10 -07:00
Jamie LiuandgVisor bot 567f020fad Fix cleanup around socketpair() failure to copy out FDs.
- Use the fs.File, rather than the vfs.FileDescription, in the VFS1 version.

- Check for a nil fs.File/vfs.FileDescription before calling DecRef, which is
  possible if a racing dup2() or dup3() replaces the file descriptor between
  when it is installed and when it is returned. (This is not possible in Linux
  because Linux separates allocation of a file descriptor from binding an
  allocated file descriptor to a struct file, and dup2/dup3 return EBUSY if
  asked to replace an allocated but unbound file descriptor.)

PiperOrigin-RevId: 306517101
2020-04-14 14:41:06 -07:00
Dean DengandgVisor bot 33ecf251a5 Port socket-related syscalls to VFS2.
Note that most kinds of sockets are not yet supported in VFS2
(only Unix sockets are partially supported at the moment), so
these syscalls will still generally fail. Enabling them allows
us to begin running socket tests for VFS2 as more features are
ported over.

Updates #1476, #1478, #1484, #1485.

PiperOrigin-RevId: 306292294
2020-04-13 13:02:34 -07: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
Kevin Krakauer 087828b669 Minor fixes to comments and logging 2020-01-08 11:15:46 -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 1587ae8509 Let socket.ControlMessages Release() the underlying transport.ControlMessages.
PiperOrigin-RevId: 284804370
2019-12-10 11:36:08 -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
Ting-Yu WangandgVisor bot 617c84d313 Fix return codes for {get,set}sockopt for some nullptr cases.
Updates #1092

PiperOrigin-RevId: 280547239
2019-11-14 17:04:34 -08:00
gVisor bot 95dbe034f7 Implement SO_BINDTODEVICE sockopt
PiperOrigin-RevId: 271644926
2019-09-27 14:14:04 -07:00
Kevin KrakauerandgVisor bot a2d970d38a Plumbing for iptables sockopts.
PiperOrigin-RevId: 261413396
2019-08-02 16:26:48 -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 d11027f127 Cleanup straggling syscall dependencies.
PiperOrigin-RevId: 257293198
2019-07-09 16:18:02 -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
Rahat MahmoodandShentubot 05ff1ffaad Implement getsockopt() SO_DOMAIN, SO_PROTOCOL and SO_TYPE.
SO_TYPE was already implemented for everything but netlink sockets.

PiperOrigin-RevId: 253138157
2019-06-13 17:24:51 -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
Rahat MahmoodandShentubot 315cf9a523 Use common definition of SockType.
SockType isn't specific to unix domain sockets, and the current
definition basically mirrors the linux ABI's definition.

PiperOrigin-RevId: 251956740
2019-06-06 17:00:27 -07:00