Commit Graph
147 Commits
Author SHA1 Message Date
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 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 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
Nicolas LacasseandgVisor bot 5116e64228 hostinet: Disallow writes to AF_PACKET sockets.
PiperOrigin-RevId: 528831169
2023-05-02 10:58:18 -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
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 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
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 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
Jamie LiuandgVisor bot 3fe0a9c52b Allow SO_BROADCAST through hostinet.
Fixes #8090

PiperOrigin-RevId: 488767693
2022-11-15 15:00:46 -08:00
Kevin KrakauerandgVisor bot 60b0f76f7f netstack: add gro_flush_timeout
Makes a per-interface file available to configure the GRO timeout, e.g.
/sys/class/net/eth0/gro_flush_timeout

PiperOrigin-RevId: 487082821
2022-11-08 16:34:55 -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
Tan YifengandTan Yifeng 2056acc59c Truncate the output buffer to outLen size when getsockopt with TCP_INFO.
Signed-off-by: Tan Yifeng <[email protected]>
2022-09-08 14:33:14 +08:00
Tan YifengandTan Yifeng e36937ef55 support set or get tcpsockopt TCP_MAXSEG, TCP_CONGESTION for hostnetwork.
Signed-off-by: Tan Yifeng <[email protected]>
2022-09-07 11:02:06 +08:00
Andrei VaginandgVisor bot 89c8e320fc Don't leak network namespaces
PiperOrigin-RevId: 454707336
2022-06-13 15:05:21 -07:00
gVisor bot b4db7d95b9 Merge pull request #7326 from knisbet:kevin/master/97-add-SIOCGIFTXQLEN-to-hostnetwork
PiperOrigin-RevId: 449590833
2022-05-18 15:24:31 -07:00
Kevin Krakauer 64e5415bed hostinet: allow getsockopt(SO_RCVTIMEO) and getsockopt(SO_SNDTIMEO)
Fixes #6603
2022-05-02 15:41:14 -07:00
Bhasker HariharanandgVisor bot b3a5701e19 Remove TCP endpoint goroutines.
This change removes all endpoint goroutines and all TCP processing is now done
inline in the TCP processor loop. TCP timers directly invoke handlers as
required rather than assert a waker.

UnlockUser is also simplified to just queue the endpoint to the processor
instead of trying to process segments inline. This allows us to centralize logic
for TCP state handling in the processor. This potentially could involve an extra
wakeup but now that endpoint goroutines do not exist this is not such a big
concern as in case of busy servers the processor goroutines will already be
running anyway.

This change also allows us to clean up S/R as now restoring a TCP endpoint does
not require restarting a goroutine and moving it to the right logical point but
only requires that we restart any timers that may have been running when the
save was done and restore any port bindings as required.

Endpoint.Release is now removed in favor of Endpoint.Abort by using Abort in
places where we use Endpoint.Release.

Updates #231

PiperOrigin-RevId: 442673015
2022-04-18 17:35:36 -07:00
Kevin Nisbet f8d8cb7753 implement SIOCGIFTXQLEN when using host network
revise unit test based on PR feedback
2022-04-01 01:52:16 -04:00
Fabricio VoznikaandgVisor bot 9725ff1d9b Fix epoll_ctl(2) regular files and dirs
Linux behaves differently for regular files and dirs for poll(2)/select(2)
compared to epoll_ctl(2). The latter returns EPERM for file and dirs.
I've also changed host FDs to behave like the underlying FD in regards
to epoll to keep it compatible with docker.

Fixes #7134

PiperOrigin-RevId: 429412692
2022-02-17 15:12:36 -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
Dionna GlazeandgVisor bot 2a2e5247e6 Fix SIOCGIFCONF in hostinet
Add a syscall test with a bad nested pointer.
The implementation properly copies out a sentry buffer.

PiperOrigin-RevId: 421847766
2022-01-14 09:41:03 -08:00
Bhasker HariharanandgVisor bot 4664e71ebb Support custom socket options in hostinet.
PiperOrigin-RevId: 416625574
2021-12-15 12:51:54 -08:00
gVisor bot 27d5c95b99 Internal change.
PiperOrigin-RevId: 416113422
2021-12-13 13:00:36 -08:00
Fabricio VoznikaandgVisor bot cecd7315bc Don't eat error from epoll_ctl EPOLL_CTL_ADD
Docker maps stdin to `/dev/null` which doesn't support epoll. Host FD
was ignoring the error and suceeding the epoll_ctl call from the
container, giving false impressing that epoll would be notified.

This required plumbing failure to all waiter.Waitable.EventRegister
callers and implementers.

Closes #6795

PiperOrigin-RevId: 414797621
2021-12-07 12:36:00 -08:00
Adin ScannellandgVisor bot 4967b16af9 Update Waitable API.
Instead of passing the event mask at registratrion time, pass the mask as part
of the waiter. This makes the mask immutable and simplifies the architecture of
waiters. This is also necessary for a future fix that will allow the fdnotifier
to keep persistent entries, as opposed to requiring constant updates.

This change is intended to be a no-op in terms of function. The only exception
is signalfd, where this mask was abused. To handle this case, the operation of
signalfd changed to allow one layer of indirection.

PiperOrigin-RevId: 409702998
2021-11-13 12:54:39 -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
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
Zeling FengandgVisor bot ccf06b3451 Support RTM_DELLINK
This change will allow us to remove the default link in a packetimpact test so
we can reduce indeterministic behaviors as required in https://fxbug.dev/78430.
This will also help with testing #1388.

Updates #578, #1388.

PiperOrigin-RevId: 387896847
2021-07-30 15:41:36 -07:00
Lucas ManningandgVisor bot 0036a024db Add support for SIOCGIFCONF ioctl in hostinet.
PiperOrigin-RevId: 386511818
2021-07-23 12:52:44 -07:00
Jamie LiuandgVisor bot f53b8a38e5 Add go:build directives as required by Go 1.17's gofmt.
PiperOrigin-RevId: 385894869
2021-07-20 16:28:45 -07:00