Commit Graph
81 Commits
Author SHA1 Message Date
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 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
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 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 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
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
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
Kevin Krakauer 64e5415bed hostinet: allow getsockopt(SO_RCVTIMEO) and getsockopt(SO_SNDTIMEO)
Fixes #6603
2022-05-02 15:41:14 -07: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
Bhasker HariharanandgVisor bot 4664e71ebb Support custom socket options in hostinet.
PiperOrigin-RevId: 416625574
2021-12-15 12:51:54 -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
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
Ian LewisandgVisor bot 4492679179 Trigger poll/epoll events on zero-length hostinet sendmsg
Fixes #2726

PiperOrigin-RevId: 380753516
2021-06-22 01:10:24 -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
Andrei VaginandgVisor bot c75a0cf622 hostinet: parse the timeval structure from a SO_TIMESTAMP control message
PiperOrigin-RevId: 370181621
2021-04-23 16:45:03 -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
Bhasker HariharanandgVisor bot cd96d40cf1 Add POLLRDNORM/POLLWRNORM support.
On Linux these are meant to be equivalent to POLLIN/POLLOUT. Rather
than hack these on in sys_poll etc it felt cleaner to just cleanup
the call sites to notify for both events. This is what linux does
as well.

Fixes #5544

PiperOrigin-RevId: 364859977
2021-03-24 12:11:44 -07:00
Ayush RanjanandgVisor bot c3ff9f93bc [op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.

Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
  are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
  returns it and not unix.Stat_t.

Updates #214

PiperOrigin-RevId: 360701387
2021-03-03 10:25:58 -08:00
Nayana BidariandgVisor bot a11687ab95 Remove unimplemented message for SO_LINGER
- Removes the unimplemented message for SO_LINGER
- Fix the length for IP_PKTINFO option

PiperOrigin-RevId: 352917611
2021-01-20 18:16:51 -08:00
Ayush RanjanandgVisor bot 4bc318854f [netstack] Implement IP(V6)_RECVERR socket option.
PiperOrigin-RevId: 348055514
2020-12-17 11:10:41 -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 3be1f4bb2a [netstack] Make recvmsg(2) call to host in hostinet even if dst is empty.
We want to make the recvmsg syscall to the host regardless of if the dst is
empty or not so that:
- Host can populate the control messages if necessary.
- Host can return sender address.
- Host can return appropriate errors.

Earlier because we were using the IOSequence.CopyOutFrom() API, the usermem
package does not even call the Reader function if the destination is empty (as
an optimization).

PiperOrigin-RevId: 347684566
2020-12-15 13:48:33 -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
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 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
gVisor bot cda2e11240 Merge pull request #3142 from tanjianfeng:fix-3141
PiperOrigin-RevId: 322937495
2020-07-23 22:25:14 -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
Jianfeng Tan 737b748ae7 hostinet: fix not specifying family field
Creating sockets by hostinet with VFS2 fails due to triggerring a
seccomp violation. In essence, we fails to pass down the field of
family.

We fix this by passing down this field, family.

Fixes #3141

Signed-off-by: Jianfeng Tan <[email protected]>
2020-07-06 20:53:51 +08:00
Michael PrattandgVisor bot 458dbc511d Remove various uses of 'whitelist'
Updates #2972

PiperOrigin-RevId: 317113059
2020-06-18 09:03:39 -07:00
Dean DengandgVisor bot bbd59ed343 Fix flaky udp tests by polling before reading.
On native Linux, calling recv/read right after send/write sometimes returns
EWOULDBLOCK, if the data has not made it to the receiving socket (even though
the endpoints are on the same host). Poll before reading to avoid this.

Making this change also uncovered a hostinet bug (gvisor.dev/issue/2726),
which is noted in this CL.

PiperOrigin-RevId: 312320587
2020-05-19 11:41:52 -07:00
Dean DengandgVisor bot 1db5e93592 Port netstack, hostinet, and netlink sockets to VFS2.
All three follow the same pattern:
1. Refactor VFS1 sockets into socketOpsCommon, so that most of the methods can
   be shared with VFS2.
2. Create a FileDescriptionImpl with the corresponding socket operations,
   rewriting the few that cannot be shared with VFS1.
3. Set up a VFS2 socket provider that creates a socket by setting up a dentry
   in the global Kernel.socketMount and connecting it with a new
   FileDescription.

This mostly completes the work for porting sockets to VFS2, and many syscall
tests can be enabled as a result.
There are several networking-related syscall tests that are still not passing:
1. net gofer tests
2. socketpair gofer tests
2. sendfile tests (splice is not implemented in VFS2 yet)

Updates #1478, #1484, #1485

PiperOrigin-RevId: 309457331
2020-05-01 12:54:41 -07:00
gVisor bot 33f622bb7e Internal change.
PiperOrigin-RevId: 294952610
2020-02-13 10:59:52 -08:00