Commit Graph
734 Commits
Author SHA1 Message Date
Dean DengandgVisor bot 0672a272ab Add test for open(2) with O_WRONLY|O_RDWR.
PiperOrigin-RevId: 349607959
2020-12-30 15:22:35 -08:00
Jing ChenandgVisor bot 9762250ce1 Deflake semaphore_test_native
PiperOrigin-RevId: 349490873
2020-12-29 17:38:23 -08:00
Tamir DubersteinandgVisor bot 0e7027a598 Export socket_ipv6_udp_unbound_loopback.cc
PiperOrigin-RevId: 349458984
2020-12-29 12:56:59 -08:00
gVisor bot f361d85aa7 Merge pull request #5166 from kevinGC:bk-warnings
PiperOrigin-RevId: 349314945
2020-12-28 12:12:35 -08:00
Kevin Krakauer 828818ab27 Resolve compiler warnings
The buildkite syscall tests start with a lot of C++ warnings. This
cleans that up a little.
2020-12-23 16:49:01 -08:00
Andrei VaginandgVisor bot 52f5d74eaa vfs1: don't allow to open socket files
open() has to return ENXIO in this case.

O_PATH isn't supported by vfs1.

PiperOrigin-RevId: 348820478
2020-12-23 11:11:07 -08:00
gVisor bot ca264a7ed0 Internal change.
PiperOrigin-RevId: 348720223
2020-12-22 17:46:41 -08:00
Nicolas LacasseandgVisor bot dad54f748f Fix seek on /proc/pid/cmdline when task is zombie.
PiperOrigin-RevId: 348056159
2020-12-17 11:16:06 -08:00
Ayush RanjanandgVisor bot 4bc318854f [netstack] Implement IP(V6)_RECVERR socket option.
PiperOrigin-RevId: 348055514
2020-12-17 11:10:41 -08:00
Jing ChenandgVisor bot 070e277b6e Implement command SEM_INFO and SEM_STAT for semctl.
PiperOrigin-RevId: 347711998
2020-12-15 16:06:06 -08:00
Nayana BidariandgVisor bot 83448813a5 Fix error code for connect in raw sockets.
PiperOrigin-RevId: 347650354
2020-12-15 11:07:48 -08:00
Nayana BidariandgVisor bot abf1c4bc0d Move SO_ERROR and SO_OOBINLINE option to socketops.
SO_OOBINLINE option is set/get as boolean value, which is the same as linux.
As we currently do not support disabling this option, we always return it as
true.

PiperOrigin-RevId: 347413905
2020-12-14 10:22:32 -08:00
Nayana BidariandgVisor bot df60ee40d3 Fix panic when IPv4 address is used in sendmsg for IPv6 sockets
We do not rely on error for getsockopt options(which have boolean values)
anymore. This will cause issue in sendmsg where we used to return error
for IPV6_V6Only option. Fix the panic by returning error (for sockets other
than TCP and UDP) if the address does not match the type(AF_INET/AF_INET6) of
the socket.

PiperOrigin-RevId: 347063838
2020-12-11 13:31:28 -08:00
Jing ChenandgVisor bot a0854b0b3a Make semctl IPC_INFO cmd return the index of highest used entry.
PiperOrigin-RevId: 346973338
2020-12-11 04:22:04 -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
gVisor bot 404a9b9793 Merge pull request #4932 from lubinszARM:pr_test_exceptions
PiperOrigin-RevId: 345976554
2020-12-06 13:06:37 -08:00
Adin ScannellandgVisor bot 33d17b2d0c Remove invalid test case.
The next test case is perfectly valid, which creates a test directory
with appropriate permissions and ensures that you can't create a file.

This test case assumes that the root directory has certain permissions.
In this case, we may have EROFS instead of a permission error, but it's
perfectly plausible that no error occurs at all. The test is not valid.

PiperOrigin-RevId: 345764412
2020-12-04 15:11:55 -08:00
Adin ScannellandgVisor bot ad009d6e5a Initialize has_tid for correctness.
PiperOrigin-RevId: 345763209
2020-12-04 14:59:54 -08:00
Jing ChenandgVisor bot 9b1bf422a0 Implement command IPC_INFO for semctl.
PiperOrigin-RevId: 345589628
2020-12-03 19:57:51 -08:00
Etienne PerotandgVisor bot c4cee5ea31 Implement fcntl options F_GETSIG and F_SETSIG.
These options allow overriding the signal that gets sent to the process when
I/O operations are available on the file descriptor, rather than the default
`SIGIO` signal. Doing so also populates `siginfo` to contain extra information
about which file descriptor caused the event (`si_fd`) and what events happened
on it (`si_band`). The logic around which FD is populated within `si_fd`
matches Linux's, which means it has some weird edge cases where that value may
not actually refer to a file descriptor that is still valid.

This CL also ports extra S/R logic regarding async handler in VFS2.
Without this, async I/O handlers aren't properly re-registered after S/R.

PiperOrigin-RevId: 345436598
2020-12-03 06:20:29 -08:00
Adin ScannellandgVisor bot f328a9d2b1 Fix chown test.
PiperOrigin-RevId: 345265342
2020-12-02 10:53:52 -08:00
Adin ScannellandgVisor bot 80291dfae1 Skip CanKillAllPIDs when running natively.
This is quite disruptive to run in some environments.

PiperOrigin-RevId: 345247206
2020-12-02 09:28:14 -08:00
Jing ChenandgVisor bot b82778c4f6 Add /proc/sys/kernel/sem.
PiperOrigin-RevId: 345178956
2020-12-02 00:13:24 -08:00
Bhasker HariharanandgVisor bot 78a5dca134 Fix deadlock in UDP handleControlPacket path.
Fixing the sendto deadlock exposed yet another deadlock where a lock inversion
occurs on the handleControlPacket path where e.mu and demuxer.epsByNIC.mu are
acquired in reverse order from say when RegisterTransportEndpoint is called
in endpoint.Connect().

This fix sidesteps the issue by just making endpoint.state an atomic and gets rid
of the need to acquire e.mu in e.HandleControlPacket.

PiperOrigin-RevId: 344939895
2020-11-30 20:13:26 -08:00
Robin Luk 9225de6f1c arm64 test: add exceptions related test cases
For now, I only added a halt test case for Arm64.

Signed-off-by: Robin Luk <[email protected]>
2020-11-25 13:43:11 +08:00
Adin ScannellandgVisor bot b5a49af8ea Omit sandbox from chown test.
This test fails because it must include additional UIDs. Omit
the bazel sandbox to ensure that it can function correctly.

PiperOrigin-RevId: 343927190
2020-11-23 14:18:20 -08:00
Adin ScannellandgVisor bot 5f4b0d1995 Ignore permission failures in CheckDuplicatesRecursively.
Not all files are always accessible by the process itself. This
was specifically seen with map_files, but there's no rule that
every entry must be accessible by the process itself.

PiperOrigin-RevId: 343919117
2020-11-23 13:38:41 -08:00
gVisor bot a9e2120a64 Internal change.
PiperOrigin-RevId: 343419851
2020-11-19 20:03:53 -08:00
Fabricio VoznikaandgVisor bot 61acdaaaec Propagate IP address prefix from host to netstack
Closes #4022

PiperOrigin-RevId: 343378647
2020-11-19 15:11:17 -08:00
Ayush RanjanandgVisor bot 827beeb3d1 [netstack] Move SO_KEEPALIVE and SO_ACCEPTCONN option to SocketOptions.
PiperOrigin-RevId: 343217712
2020-11-18 21:24:55 -08:00
Ayush RanjanandgVisor bot 6d66aeb734 [netstack] Move SO_REUSEPORT and SO_REUSEADDR option to SocketOptions.
This changes also introduces:
- `SocketOptionsHandler` interface which can be implemented by endpoints to
  handle endpoint specific behavior on SetSockOpt. This is analogous to what
  Linux does.
- `DefaultSocketOptionsHandler` which is a default implementation of the above.
  This is embedded in all endpoints so that we don't have to uselessly
  implement empty functions. Endpoints with specific behavior can override the
  embedded method by manually defining its own implementation.

PiperOrigin-RevId: 343158301
2020-11-18 14:36:41 -08:00
Ayush RanjanandgVisor bot 7af43c7fff [netstack] Move SO_NO_CHECK option to SocketOptions.
PiperOrigin-RevId: 343146856
2020-11-18 13:42:27 -08:00
Ayush RanjanandgVisor bot e5c8395579 [netstack] Move SO_PASSCRED option to SocketOptions.
This change also makes the following fixes:
- Make SocketOptions use atomic operations instead of having to acquire/drop
  locks upon each get/set option.
- Make documentation more consistent.
- Remove tcpip.SocketOptions from socketOpsCommon because it already exists
  in transport.Endpoint.
- Refactors get/set socket options tests to be easily extendable.

PiperOrigin-RevId: 343103780
2020-11-18 10:19:33 -08:00
Bhasker HariharanandgVisor bot db5a4fbd34 Fix possible deadlock in UDP.Write().
In UDP endpoint.Write() sendUDP is called with e.mu Rlocked. But if this happens
to send a datagram over loopback which ends up generating an ICMP response of
say ErrNoPortReachable, the handling of the response in HandleControlPacket also
acquires e.mu using RLock. This is mostly fine unless there is a competing
caller trying to acquire e.mu in exclusive mode using Lock(). This will deadlock
as a caller waiting in Lock() disallows an new RLocks() to ensure it can
actually acquire the Lock.

This is documented here https://golang.org/pkg/sync/#RWMutex.

This change releases the endpoint mutex before calling sendUDP to resolve the
possibility of the deadlock.

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 342894148
2020-11-17 10:36:29 -08:00
Bhasker HariharanandgVisor bot be3478ec65 Fix SO_ERROR behavior for TCP in gVisor.
Fixes the behaviour of SO_ERROR for tcp sockets where in linux it returns
sk->sk_err and if sk->sk_err is 0 then it returns sk->sk_soft_err. In gVisor TCP
we endpoint.HardError is the equivalent of sk->sk_err and endpoint.LastError
holds soft errors. This change brings this into alignment with Linux such that
both hard/soft errors are cleared when retrieved using getsockopt(.. SO_ERROR)
is called on a socket.

Fixes #3812

PiperOrigin-RevId: 342868552
2020-11-17 08:33:03 -08:00
Jamie LiuandgVisor bot 9da6db2a5f Reset watchdog timer between sendfile() iterations.
As part of this, change Task.interrupted() to not drain Task.interruptChan, and
do so explicitly using new function Task.unsetInterrupted() instead.

PiperOrigin-RevId: 342768365
2020-11-16 18:55:24 -08:00
Jamie LiuandgVisor bot d7ed52ee3c Disable save/restore in PartialBadBufferTest.SendMsgTCP.
PiperOrigin-RevId: 342314586
2020-11-13 12:24:53 -08:00
Mithun IyerandgVisor bot 69a1a8c77f Deflake tcp_socket test.
Increase the wait time for the thread to be blocked on read/write
syscall.

PiperOrigin-RevId: 342204627
2020-11-12 23:04:12 -08:00
Nayana BidariandgVisor bot 1d38f400f4 Refactor SOL_SOCKET options
Store all the socket level options in a struct and call {Get/Set}SockOpt on
this struct. This will avoid implementing socket level options on all
endpoints. This CL contains implementing one socket level option for tcp and
udp endpoints.

PiperOrigin-RevId: 342203981
2020-11-12 22:57:00 -08:00
Mithun IyerandgVisor bot c675d535d2 Skip EventHUp notify in FIN_WAIT2 on a socket close.
This Notify was added as part of cl/279106406; but notifying `EventHUp`
in `FIN_WAIT2` is incorrect, as we want to only notify later on
`TIME_WAIT` or a reset. However, we do need to notify any blocked
waiters of an activity on the endpoint with `EventIn`|`EventOut`.

PiperOrigin-RevId: 341490913
2020-11-09 14:54:57 -08:00
Andrei VaginandgVisor bot 98ae07557c net: connect to the ipv4 localhost returns ENETUNREACH if the address isn't set
cl/340002915 modified the code to return EADDRNOTAVAIL if connect
is called for a localhost address which isn't set.

But actually, Linux returns EADDRNOTAVAIL for ipv6 addresses and ENETUNREACH
for ipv4 addresses.

Updates #4735

PiperOrigin-RevId: 341479129
2020-11-09 13:57:51 -08:00
Jing ChenandgVisor bot 56ccd9aad9 Implement command GETNCNT for semctl.
PiperOrigin-RevId: 341154192
2020-11-06 18:38:13 -08:00
Nicolas LacasseandgVisor bot 15f268b4f0 Fix infinite loop when splicing to pipes/eventfds.
Writes to pipes of size < PIPE_BUF are guaranteed to be atomic, so writes
larger than that will return EAGAIN if the pipe has capacity < PIPE_BUF.

Writes to eventfds will return EAGAIN if the write would cause the eventfd
value to go over the max.

In both such cases, calling Ready() on the FD will return true (because it is
possible to write), but specific kinds of writes will in fact return EAGAIN.

This CL fixes an infinite loop in splice and sendfile (VFS1 and VFS2) by
forcing skipping the readiness check for the outfile in send, splice, and tee.

PiperOrigin-RevId: 341102260
2020-11-06 12:55:29 -08:00
Ghanan GowripalanandgVisor bot 2dd8eb0785 Do not send to the zero port
Port 0 is not meant to identify any remote port so attempting to send
a packet to it should return an error.

PiperOrigin-RevId: 341009528
2020-11-06 01:47:09 -08:00
Jamie LiuandgVisor bot 957a749bcb Deflake semaphore_test.
- Disable saving in tests that wait for EINTR.

- Do not execute async-signal-unsafe code after fork() (see fork(2)'s manpage,
  "After a fork in a multithreaded program ...")

- Check for errors returned by semctl(GETZCNT).

PiperOrigin-RevId: 340901353
2020-11-05 12:07:12 -08:00
Jing ChenandgVisor bot 3e67015622 Implement command GETZCNT for semctl.
PiperOrigin-RevId: 340389884
2020-11-02 23:58:45 -08:00
Andrei VaginandgVisor bot 11ea6a3b43 Clean up the code of setupTimeWaitClose
The active_closefd has to be shutdown only for write,
otherwise the second poll will always return immediately.

The second poll should not be called from a separate thread.

PiperOrigin-RevId: 340319071
2020-11-02 14:42:03 -08:00
Ian LewisandgVisor bot 9ae81a5f63 Fix returned error when deleting non-existant address
PiperOrigin-RevId: 340149214
2020-11-01 18:03:43 -08:00
Andrei VaginandgVisor bot 9a1f20e8fb net/tcpip: connect to unset loopback address has to return EADDRNOTAVAIL
In the docker container, the ipv6 loopback address is not set,
and connect("::1") has to return ENEADDRNOTAVAIL in this case.

Without this fix, it returns EHOSTUNREACH.

PiperOrigin-RevId: 340002915
2020-10-31 01:19:40 -07:00
Jamie LiuandgVisor bot 4f9be2d6d4 Separate kernel.Task.AsCopyContext() into CopyContext() and OwnCopyContext().
kernel.copyContext{t} cannot be used outside of t's task goroutine, for three
reasons:

- t.CopyScratchBuffer() is task-goroutine-local.

- Calling t.MemoryManager() without running on t's task goroutine or locking
  t.mu violates t.MemoryManager()'s preconditions.

- kernel.copyContext passes t as context.Context to MM IO methods, which is
  illegal outside of t's task goroutine (cf. kernel.Task.Value()).

Fix this by splitting AsCopyContext() into CopyContext() (which takes an
explicit context.Context and is usable outside of the task goroutine) and
OwnCopyContext() (which uses t as context.Context, but is only usable by t's
task goroutine).

PiperOrigin-RevId: 339933809
2020-10-30 13:54:47 -07:00