Commit Graph
600 Commits
Author SHA1 Message Date
Nicolas LacasseandgVisor bot fd8f39c53b Emit SentryTcpListenEvent when the application listens on a tcp port.
PiperOrigin-RevId: 562957239
2023-09-05 19:15:45 -07:00
Mustafa Uzun a307331ec2 fix: rename dumpErrorMesage and dumpAckMessage functions 2023-08-18 10:46:02 +03:00
Jing ChenandgVisor bot 9a79dec6f1 Implement SO_SNDTIMEO and SO_RCVTIMEO for netlink's setsockopt and getsockopt.
PiperOrigin-RevId: 557933811
2023-08-17 14:18:15 -07:00
Andrei VaginandgVisor bot c5493106c6 Implement the setns syscall
This change introduces the nsfs file system. Each new namespace allocates
a new nsfs inode.

Here are reasons why we need these inodes:
* each namespace has to have an unique id.
* proc/pid/ns/ contains one entry for each namespace. Bind mounting one of
  the files in this directory to somewhere else in the filesystem keeps the
  corresponding namespace alive even if all processes currently in
  the namespace terminate.
* setns() allows the calling process to join an existing namespace specified
  by a file descriptor.

PiperOrigin-RevId: 550694515
2023-07-24 15:45:08 -07:00
gVisor bot a125f28c82 Merge pull request #9007 from andrew-d:andrew/tcp-forwarder-on-ignored
PiperOrigin-RevId: 549727271
2023-07-20 13:44:41 -07:00
Andrew Dunham 5496367f50 pkg/tcpip/transport/tcp: add statistics for dropped connections
When the TCP forwarder ignores a connection due to having too many
in-flight connections, it's not easy to log a message or update a metric
for later debugging. Add a metric that will be incremented in this case
so that the user of the Forwarder can observe this.

Signed-off-by: Andrew Dunham <[email protected]>
2023-07-17 15:07:55 -04:00
Jamie LiuandgVisor bot d627289f13 Remove //pkg/sentry/device.
This package was used for VFS1 device number assignment.

PiperOrigin-RevId: 538918926
2023-06-08 16:21:04 -07:00
Kevin KrakauerandgVisor bot 8a2b1df3f6 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -07:00
Ghanan GowripalanandgVisor bot 4b8f7d281b Don't hold link address in tcpip.Address
All tcpip.Endpoints use a tcpip.FullAddress to hold addresses associated
with an outgoing or incoming packet, but the struct only had a field for
a tcpip.Address. This field was overloaded to also hold a link address
(which is normally held in a tcpip.LinkAddress). This worked relatively
fine until the change to make addresses opaque types.

commit ef88b30bff required the use of a
workaround to continue passing around link addresses through the
tcpip.Address field. This workaround requires assumptions about the
size of the hardware address and unncessary jumping-through-hoops.

This change just introduces a new field to tcpip.FullAddress with type
tcpip.LinkAddress that can hold link addresses and this new field will
be used by packet endpoints.

The change referenced above is cl/532284732.

PiperOrigin-RevId: 536561363
2023-05-30 18:14:32 -07:00
Kevin KrakauerandgVisor bot 5cdebeb73d netstack: make tcpip.Address hold a []byte
tcp_benchmark throughput increase 2-3%, but allocations go down (25% in the
download benchmark, only 2% in the upload path).

PiperOrigin-RevId: 532523146
2023-05-16 11:40:49 -07:00
Kevin KrakauerandgVisor bot ef88b30bff netstack: make tcpip.Address an opaque type
The important change here is in tcpip/tcpip.go, where tcpip.Address is defined.
The rest is updating uses of tcpip.Address.

This is preparation for netip.Addr or []byte based addresses, which should save
us a bunch of allocations. Currently, we allocate every time we want to, say,
get a tcpip.Address from a header. This is because the header is a byte slice,
but Address is a string. Strings are immutable, so Go allocates and copies.

PiperOrigin-RevId: 532284732
2023-05-15 18:07:03 -07:00
Nicolas LacasseandgVisor bot 393ac5cf0a Don't hold baseEndpoint.mu when calling receiver.Recv.
We only need baseEndpoint.mu to read e.receiver, which we copy
before calling Recv() on in.

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 530970638
2023-05-10 12:07:18 -07:00
Nicolas LacasseandgVisor bot 93d64b5c07 Don't hold streamQueueReceiver.mu while calling RightsControlMessage.Release().
This leads to lock order violations.

Reported-by: [email protected]
PiperOrigin-RevId: 530726950
2023-05-09 15:21:21 -07:00
Nicolas LacasseandgVisor bot e75ff4f68c Enable socket_inet_loopback test on hostinet.
A few minor fixes. The biggest change is that the blocking implementation needs
to wait on POLLHUP and POLLERR events, in addition to readable/writable events.
We also need to track shutdown state in the socket.

PiperOrigin-RevId: 529816115
2023-05-05 14:35:57 -07:00
Ghanan GowripalanandgVisor bot 3173a75072 Use tcpip.NICID when get/set-ing GRO timeout
PiperOrigin-RevId: 529535113
2023-05-04 15:47:28 -07:00
Nicolas LacasseandgVisor bot 5116e64228 hostinet: Disallow writes to AF_PACKET sockets.
PiperOrigin-RevId: 528831169
2023-05-02 10:58:18 -07:00
Etienne PerotandgVisor bot ba61bf6e93 gVisor metric library: Change interface for passing in field values.
This introduces a `metric.FieldValue` struct type that wraps a string.
All metric interfaces that deal with field values have been updated to use
pointers to this type instead of strings.

The intent of this change is to make it more obvious that field values must
be passed using references. Prior to this change, this was done using string
pointer comparisons. Now this must be done by using a pointer to the same
`metric.FieldValue` struct.

The struct type still externally exposes its string so that it can be referred
to in value function callbacks by "custom" metrics. (Though there are no
current uses of callback metrics with fields.)

PiperOrigin-RevId: 527030738
2023-04-25 11:49:02 -07:00
Kevin KrakauerandgVisor bot 60a2432dff stop using tcpip.FullAddress with unix sockets
It's unnecessarily overloading the type, which makes it hard to change the type
in netstack.

PiperOrigin-RevId: 526168235
2023-04-21 16:48:37 -07:00
Nicolas LacasseandgVisor bot df930b374f Enable socket_stress_test with hostinet.
The min/max port ranges were broken.

PiperOrigin-RevId: 526137330
2023-04-21 14:35:51 -07:00
Nicolas LacasseandgVisor bot 8ee4c3bae7 Automated rollback of changelist 525849045
PiperOrigin-RevId: 526120544
2023-04-21 13:26:08 -07:00
Nicolas LacasseandgVisor bot 66fe1d19e0 Enable socket_inet_loopback test on hostinet.
The blocking implementation needs to wait on POLLHUP and POLLERR events, in
addition to readable/writable events. That fixed at least one test.

There's still two unresolved issues in the tests, but we can enable the rest
of the suite while we figure out those two.

PiperOrigin-RevId: 525849045
2023-04-20 14:25:27 -07:00
Nicolas LacasseandgVisor bot e51a59ccbf Enable hostinet for netdevice tests.
This was just a matter of passing a few more IOCTL commands to the host.

PiperOrigin-RevId: 523540572
2023-04-11 16:46:35 -07:00
Nicolas LacasseandgVisor bot c07dc2673f Implement hostinet.Stack methods that manipulate interfaces and addresses.
And enable all of the netlink tests that depend on this functionality.

Specifially, this CL implements hostinet.stack:
* .RemoveInterface()
* .AddInterfaceAddr()
* .RemoveInterfaceAddr()

Applications use netlink messages to call into these methods. For hostinet, we
use netlink messages to the host to implement these methods.

Note that the netlink messages are not simple passed from the application to
the host -- they are parsed first and only carefully crafted messages are sent
to the host.

This CL required a lot of refactoring to the existing netlink code in the
hostinet package, as well as a bunch of new functionality. All of that code has
been collected in hostinet/netlink.go

I also changed how we handle CAP_NET_ADMIN and CAP_NET_RAW in tests, since we
must drop those capabilities inside the sandbox if we don't have them on the
host. The new solution is cleaner and does not rely on google-specific env
variables.

PiperOrigin-RevId: 522685544
2023-04-07 14:33:21 -07:00
Nicolas LacasseandgVisor bot e4f4a8bc8a Make hostinet get the interfaces/addr/routes dynamicallys.
Previously we were initializing these at startup and they could never change.
Now they are read dynamically every time they are requested. This is a
pre-requisite for implementing methods that mutate the interfaces
(stack.AddInterface()).

PiperOrigin-RevId: 522109098
2023-04-05 11:35:39 -07:00
Nicolas LacasseandgVisor bot 92d0427c98 Clean up netlink code in hostinet.
No functional changes. Refactored some methods into smaller chunks for easy
reuse. Got rid of some needlessly exported methods.

PiperOrigin-RevId: 520748526
2023-03-30 14:51:24 -07:00
Etienne PerotandgVisor bot c6d19db4e4 Update unimpl.EmitUnimplementedEvent interface to add the syscall number.
This catches up the interface to the `EmitUnimplementedEvent` method signature
on `kernel.Kernel`.

Also add build-time test to verify that `kernel.Kernel` implements this
interface, in order to catch such breakages at build time in the future.

PiperOrigin-RevId: 519000411
2023-03-23 17:01:37 -07:00
Ayush RanjanandgVisor bot 930a246030 Make HostBountEndpoint.SetBoundSocketFD take ownership of bound socket FD.
Earlier SetBoundSocketFD() was taking ownership of bound socket FD only on
success. Having it take ownership unconditionally is cleaner.

PiperOrigin-RevId: 516903597
2023-03-15 12:53:27 -07:00
Nicolas LacasseandgVisor bot b68d7769e6 hostinet: Allow MSG_OOB in send/recvmsg.
This is needed for the python runtime tests (not yet enabled for hostinet).

PiperOrigin-RevId: 514593833
2023-03-06 19:36:36 -08:00
Nicolas LacasseandgVisor bot 94a97f1941 hostinet: Implement packet sockets.
Two of the tests are still disabled for now. There is an existing issue with
poll in hostinet that I need to look into.

PiperOrigin-RevId: 513936838
2023-03-04 00:48:57 -08:00
Nicolas LacasseandgVisor bot 704b8d9ee8 hostinet: Support ping and raw sockets.
PiperOrigin-RevId: 513902015
2023-03-04 00:40:01 -08:00
Nicolas LacasseandAyush Ranjan 93f846e915 hostinet: Allow more socket options to have variable-length buffers.
Most of these buffers can be truncated in the Sentry before returning to the
application.

IP_TOS is a bit funny, since it is interpreted as a 8, 16, or 32-bit int
depending on the buffer size, so simple truncation does not work. We allow all
sizes to be passed to the host.

PiperOrigin-RevId: 513880257
2023-03-04 00:24:17 -08:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Nicolas LacasseandgVisor bot 7c478ef129 hostinet: Generate socket validation and filters from list of supported sockets
This cuts down on the amount of duplication between socket() syscall handling
and the filters.

No new functionality.

PiperOrigin-RevId: 511862459
2023-02-23 12:57:01 -08:00
Nicolas LacasseandgVisor bot 5832110718 Move netstack's isTCP/UDP/ICMPSocket methods into socket package.
They are useful across other socket implementations.

PiperOrigin-RevId: 510699847
2023-02-18 13:27:45 -08:00
Nicolas LacasseandgVisor bot 1dd99dcb1c Enable more hostinet socket tests.
Fixes:
* Support for SO_MULTICAST_IF socket option.
* Support IPPROTO_ICMP protocol.

The tests that require raw sockets are disabled on hostinet, since those are
not yet supported.

PiperOrigin-RevId: 509563771
2023-02-14 10:07:54 -08:00
Nicolas LacasseandgVisor bot d2044eff24 Enable socket_ip_{udp,tcp}_loopback_test_runsc_ptrace_hostnet tests.
Fixes:
* Pass through some more recvmmsg flags.
* Pass through some more get/setsockopt flags.
* Allow IP_MULTICAST_LOOP/TTL to have variable size, since it can be 8 or 32
  bits.
* Convert IPPROTO_IP to IPPROTO_TCP/UDP so it can be returned properly by
  getsockopt(SO_PROTO).
* Disable one test that requires CAP_SYS_ADMIN on the host. Will have to come
  back to these.
PiperOrigin-RevId: 508938466
2023-02-11 16:17:52 -08:00
Nicolas LacasseandgVisor bot cceb6f7715 Fix socket_ip_tcp_generic_loopback_test_runsc_ptrace_hostnet
This was mostly a matter of allowing more get/setsockopts. Also had to support
getsockopt with a null option, because apparantly Linux allows that.

PiperOrigin-RevId: 508460614
2023-02-09 13:32:17 -08:00
Nicolas LacasseandgVisor bot 73347044b2 Refactor hostinet get/setsockopt handlers and filters.
There is a lot of duplication between the get/setsockopt handlers for hostinet
and the filters. This CL introduces an intermediate type hostinet.SockOpt which
is used to generate both handlers and filters.

There is no functional change.

PiperOrigin-RevId: 508430221
2023-02-09 11:34:01 -08:00
Nicolas LacasseandgVisor bot 256cb0cd62 Fix (most of) tcp_socket_test on hostinet.
A few fixes in here:

* Linux does not transition the state of a non-blocking socket to SS_CONNECTED
  when the connect happens asynchronously. Instead, it leaves the state as
  SS_CONNECTING (seems like a Linux bug, but OK). This can introduce weird
  behavior for subsequent connect() calls. gVisor now forces the state to
  update to SS_CONNECTED by calling connect() twice.

* Socket shutdown events are slightly different between gVisor and linux. We
  already assert different behavior between the two environments, and now we
  also have to check for gVisor+hostinet instead of just gvisor.

* Handle send/recv timeouts, which fixes blocking for read()/write() syscalls.

* Handle cases like MSG_PEEK where the senderAddress is not returned.

* Pass through some more socketopts, and allow them in the syscall filters.

Something is still wrong with shutdown() and poll() calls, so those tests are
temporarily disabled. I'm looking at those next.

This also fixes a number of other syscall test suites, so those are enabled as
well.

PiperOrigin-RevId: 508397317
2023-02-09 09:39:26 -08:00
gVisor bot 3175ff4ce8 Inherit SO_PASSCRED from listening socket on server socket
PiperOrigin-RevId: 508137166
2023-02-08 11:35:35 -08:00
Andrei VaginandgVisor bot d92524febd inet: each socket has to hold a reference to its network namespace
Otherwise a network namespace can be destroyed before sockets.

Reported-by: [email protected]
PiperOrigin-RevId: 503552997
2023-01-20 17:10:58 -08:00
Andrei VaginandgVisor bot 7d66029df0 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Ayush RanjanandgVisor bot 7c1d3983e3 Remove remaining references to vfs2.
PiperOrigin-RevId: 493998299
2022-12-08 14:37:43 -08:00
Ghanan GowripalanandgVisor bot 3ebe155d12 Don't prevent removing loopback in core netstack
Implement this check in netstack integration (in sentry) so that the
core netstack does not prevent an integrator from removing loopback.

PiperOrigin-RevId: 493992707
2022-12-08 14:23:45 -08:00
Kevin KrakauerandgVisor bot c45a4738dc netstack: fallback to IPv4 when checking hostinet interface features
This enables hostinet to start on both IPv4-only and IPv6-only hosts.

Note that hostinet doesn't have a way to prevent applications inside gVisor
from trying to send, for example, IPv6 packets on an IPv4-only host. The result
of trying to do so is environment-dependent, but will likely fail during calls
to connect(), send(), and the like.

Fixes #8253.

PiperOrigin-RevId: 492579750
2022-12-02 15:58:01 -08:00
Ayush RanjanandgVisor bot d937df6218 Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Etienne PerotandgVisor bot 3b258e1308 connectioned: Change nested lock name to only have a single nested lock.
Now there's the unnamed one, and "higherID" which is the lock for the
endpoint that has a higher ID.

The lock dependency should consistently be "lower ID" -> "higher ID".

PiperOrigin-RevId: 491716600
2022-11-29 13:06:57 -08:00
Etienne PerotandgVisor bot 5f9231cd71 Lockdep: Print more info in the "unbalanced unlock" case.
This CL does the following:

- Add the ability for nested locks to have names.
- Give names to all current uses of nested locks in the codebase.
- Truncate `lockdep` debug stack traces to avoid the clutter from the
  `lockdep` code itself
- Simplify `lockdep` to not longer require `classMap`.

PiperOrigin-RevId: 491486620
2022-11-28 17:53:09 -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
Ayush RanjanandgVisor bot ee523cfbc7 Delete VFS1 filesystem implementations.
Updates #1624

PiperOrigin-RevId: 488986080
2022-11-16 11:05:10 -08:00