82 Commits

Author SHA1 Message Date
Jamie Liu e23347e5b5 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
Nicolas Lacasse 4b35f1242d 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 Lacasse 77cf871eda hostinet: Disallow writes to AF_PACKET sockets.
PiperOrigin-RevId: 528831169
2023-05-02 10:58:18 -07:00
Nicolas Lacasse e9b8e1b74c Automated rollback of changelist 525849045
PiperOrigin-RevId: 526120544
2023-04-21 13:26:08 -07:00
Nicolas Lacasse 751906f40d 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
Etienne Perot f8b9824813 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 Lacasse bdb4a4c5ea 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 Lacasse e4ece21634 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 Lacasse f37b20c011 hostinet: Support ping and raw sockets.
PiperOrigin-RevId: 513902015
2023-03-04 00:40:01 -08:00
Nicolas Lacasse f905e456ed 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 Lacasse 5c30349f08 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 Lacasse fa8676b310 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 Lacasse ec1abcf521 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 Lacasse 753fb9ac5e 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
Ayush Ranjan 1fa3c06f1e 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 Liu 9f351c68ca Allow SO_BROADCAST through hostinet.
Fixes #8090

PiperOrigin-RevId: 488767693
2022-11-15 15:00:46 -08:00
Ayush Ranjan 020df37be7 Start cleaning up VFS1.
PiperOrigin-RevId: 486586072
2022-11-07 00:39:54 -08:00
Tan Yifeng c844c84a71 Truncate the output buffer to outLen size when getsockopt with TCP_INFO.
Signed-off-by: Tan Yifeng <yiftan@163.com>
2022-09-08 14:33:14 +08:00
Tan Yifeng 39e2e5b968 support set or get tcpsockopt TCP_MAXSEG, TCP_CONGESTION for hostnetwork.
Signed-off-by: Tan Yifeng <yiftan@163.com>
2022-09-07 11:02:06 +08:00
Kevin Krakauer 88b2fc0942 hostinet: allow getsockopt(SO_RCVTIMEO) and getsockopt(SO_SNDTIMEO)
Fixes #6603
2022-05-02 15:41:14 -07:00
Arthur Sfez 86ad7d5b58 Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Arthur Sfez 4a94302baf Support receiving PKTINFO on icmp endpoints
PiperOrigin-RevId: 428599075
2022-02-14 13:51:49 -08:00
Bhasker Hariharan fe88fe6768 Support custom socket options in hostinet.
PiperOrigin-RevId: 416625574
2021-12-15 12:51:54 -08:00
Fabricio Voznika 9768009a79 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 Scannell 91f58d2cc8 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