Commit Graph

1191 Commits

Author SHA1 Message Date
Fabricio Voznika 209a95a35a Propagate IP address prefix from host to netstack
Closes #4022

PiperOrigin-RevId: 343378647
2020-11-19 15:11:17 -08:00
Ghanan Gowripalan 27ee4fe76a Don't hold AddressEndpoints for multicast addresses
Group addressable endpoints can simply check if it has joined the
multicast group without maintaining address endpoints. This also
helps remove the dependency on AddressableEndpoint from
GroupAddressableEndpoint.

Now that group addresses are not tracked with address endpoints, we can
avoid accidentally obtaining a route with a multicast local address.

PiperOrigin-RevId: 343336912
2020-11-19 11:48:15 -08:00
Ayush Ranjan e5650d1240 [netstack] Move SO_KEEPALIVE and SO_ACCEPTCONN option to SocketOptions.
PiperOrigin-RevId: 343217712
2020-11-18 21:24:55 -08:00
Ayush Ranjan df37babd57 [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 Ranjan 3e73c519a5 [netstack] Move SO_NO_CHECK option to SocketOptions.
PiperOrigin-RevId: 343146856
2020-11-18 13:42:27 -08:00
Zeling Feng d2b701758d Remove the redundant containerIP parameter
PiperOrigin-RevId: 343144023
2020-11-18 13:29:03 -08:00
Ayush Ranjan fc342fb439 [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
Fabricio Voznika e2d9a68eef Add support for TTY in multi-container
Fixes #2714

PiperOrigin-RevId: 342950412
2020-11-17 14:51:24 -08:00
Bhasker Hariharan 05d2a26f7a 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: syzbot+537989797548c66e8ee3@syzkaller.appspotmail.com
Reported-by: syzbot+eb0b73b4ab486f7673ba@syzkaller.appspotmail.com
PiperOrigin-RevId: 342894148
2020-11-17 10:36:29 -08:00
Bhasker Hariharan fb9a649f39 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 Liu 267560d159 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
Ghanan Gowripalan cc5cfce4c6 Remove ARP address workaround
- Make AddressableEndpoint optional for NetworkEndpoint.
Not all NetworkEndpoints need to support addressing (e.g. ARP), so
AddressableEndpoint should only be implemented for protocols that
support addressing such as IPv4 and IPv6.

With this change, tcpip.ErrNotSupported will be returned by the stack
when attempting to modify addresses on a network endpoint that does
not support addressing.

Now that packets are fully handled at the network layer, and (with this
change) addresses are optional for network endpoints, we no longer need
the workaround for ARP where a fake ARP address was added to each NIC
that performs ARP so that packets would be delivered to the ARP layer.

PiperOrigin-RevId: 342722547
2020-11-16 14:36:10 -08:00
Toshi Kikuchi 373fd83100 Add packetimpact tests for ICMPv6 Error message for fragment
Updates #4427

PiperOrigin-RevId: 342703931
2020-11-16 13:13:47 -08:00
Julian Elischer 0fee59c8c8 Requested Comment/Message wording changes
PiperOrigin-RevId: 342366891
2020-11-13 17:13:11 -08:00
Jamie Liu d5e17d2dbc Disable save/restore in PartialBadBufferTest.SendMsgTCP.
PiperOrigin-RevId: 342314586
2020-11-13 12:24:53 -08:00
Mithun Iyer 8e6963491c 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 Bidari 5bb64ce1b8 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
Julian Elischer 638d64c633 Change AllocationSize to SizeWithPadding as requested
RELNOTES: n/a
PiperOrigin-RevId: 342176296
2020-11-12 18:38:43 -08:00
Julian Elischer 9c4102896d Teach netstack how to add options to IPv4 packets
Most packets don't have options but they are an integral part of the
standard. Teaching the ipv4 code how to handle them will simplify future
testing and use.  Because Options are so rare it is worth making sure
that the extra work is kept out of the fast path as much as possible.

Prior to this change, all usages of the IHL field of the IPv4Fields/Encode
system set it to the same constant value except in a couple of tests
for bad values. From this change IHL will not be a constant as it will
depend on the size of any Options. Since ipv4.Encode() now handles the
options it becomes a possible source of errors to let the callers set
this value, so remove it entirely and calculate the value from the size
of the Options if present (or not) therefore guaranteeing a correct value.

Fixes #4709
RELNOTES: n/a
PiperOrigin-RevId: 341864765
2020-11-11 10:59:35 -08:00
Zach Koopmans 792cbc06de Add debug logs to startup benchmark.
PiperOrigin-RevId: 341757694
2020-11-10 21:20:52 -08:00
Jamie Liu 7f2183df9c Internal change
PiperOrigin-RevId: 341732791
2020-11-10 17:39:31 -08:00
Zach Koopmans 267d184084 Add all base and fs tests to Continuous Tests.
PiperOrigin-RevId: 341660511
2020-11-10 11:27:50 -08:00
Julian Elischer 3b353ff0ef Additions to ICMP and IPv4 parsers
Teach ICMP.Parser/ToBytes to handle some non echo ICMP packets.
Teach IPv4.Parser that fragments only have a payload, not an upper layer.
Fix IPv4 and IPv6 reassembly tests to handle the change.

Fixes #4758

PiperOrigin-RevId: 341549665
2020-11-09 21:59:53 -08:00
Mithun Iyer 199fcd0fe5 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 Vagin 2fcca60a7b 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
Zeling Feng c59bdd18d5 parameterize regexp in netdevs.ParseDevices
PiperOrigin-RevId: 341470647
2020-11-09 13:16:33 -08:00
Kevin Krakauer 16caaf79f8 iptables: add documentation about enabing docker ipv6
PiperOrigin-RevId: 341439435
2020-11-09 10:50:43 -08:00
gVisor bot 917b6094e7 Merge pull request #4719 from zhlhahaha:2005
PiperOrigin-RevId: 341172694
2020-11-06 22:53:11 -08:00
Zach Koopmans 9035422ea4 Change size of startup benchmark and lower number of startups.
PiperOrigin-RevId: 341155693
2020-11-06 19:00:15 -08:00
Ayush Ranjan fe9442d327 [vfs] Return EEXIST when file already exists and rp.MustBeDir() is true.
This is consistent with what Linux does. This was causing a PHP runtime test
failure. Fixed it for VFS2.

PiperOrigin-RevId: 341155209
2020-11-06 18:52:38 -08:00
Jing Chen 3ac00fe9c3 Implement command GETNCNT for semctl.
PiperOrigin-RevId: 341154192
2020-11-06 18:38:13 -08:00
Nicolas Lacasse 53eeb06ef1 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 Gowripalan 955e09dfbd 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
Ayush Ranjan f27edcc708 [runtime tests] Add partitions to runtime tests.
This will allow us to run massive runtime tests live java to run in parallel
across multiple jobs.

PiperOrigin-RevId: 340956246
2020-11-05 17:11:32 -08:00
Fabricio Voznika c47f8afe23 Fix failure setting OOM score adjustment
When OOM score adjustment needs to be set, all the containers need to be
loaded to find all containers that belong to the sandbox. However, each
load signals the container to ensure it is still alive. OOM score
adjustment is set during creation and deletion of every container, generating
a flood of signals to all containers. The fix removes the signal check
when it's not needed.

There is also a race fetching OOM score adjustment value from the parent when
the sandbox exits at the same  time (the time it took to signal containers above
made this window quite large). The fix is to store the original value
in the sandbox state file and use it when the value needs to be restored.

Also add more logging and made the existing ones more consistent to help with
debugging.

PiperOrigin-RevId: 340940799
2020-11-05 15:36:20 -08:00
Ayush Ranjan caf1e52e18 [runtime tests] Exclude ext/pcre/tests/cache_limit.phpt.
PiperOrigin-RevId: 340925131
2020-11-05 14:09:22 -08:00
Jamie Liu a00c5df98b 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
Zeling Feng e29972ec04 Make the regex for inet6Line in packetimpact/netdevs more accurate
PiperOrigin-RevId: 340763455
2020-11-04 18:19:44 -08:00
Jing Chen 1a3f417f4a Implement command GETZCNT for semctl.
PiperOrigin-RevId: 340389884
2020-11-02 23:58:45 -08:00
Howard Zhang b6a5204c51 ARM64:fuse:alian stat struct order on multiarch
fields order in stat struct is different from
x86 to arm64. Please refer to
x86_64-linux-gnu/bits/stat.h
aarch64-linux-gnu/bits/stat.h

Signed-off-by: Howard Zhang <howard.zhang@arm.com>
2020-11-03 10:35:28 +08:00
Andrei Vagin 9efaf67518 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
Andrei Vagin 73f980e97e Block external network for tests
And in this case, tests will run in separate network namespaces
and will not affect each other.

PiperOrigin-RevId: 340267734
2020-11-02 10:41:52 -08:00
Ian Lewis 5e606844df Fix returned error when deleting non-existant address
PiperOrigin-RevId: 340149214
2020-11-01 18:03:43 -08:00
Andrei Vagin df88f223bb 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 Liu 9ad864628d 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
Arthur Sfez dd056112b7 Add IPv4 reassembly packetimpact test
The IPv6 reassembly test was also refactored to be easily extended with
more cases.

PiperOrigin-RevId: 339768605
2020-10-29 16:22:46 -07:00
Arthur Sfez 337c4b9a19 Add support for bare IPv4 in packetimpact tests
PiperOrigin-RevId: 339699771
2020-10-29 10:44:59 -07:00
Arthur Sfez 906f912b7c Add the payload directly to the ICMPv4 type
This makes handling inbound fragmented packets easier, because a fragmented
packet might not have an actual ICMP header but only a payload. After this
change, the ICMPv4 is the last layer you can get because the payload is
embedded in it.

Note that this makes it consistent with the ICMPv6 implementation.

While I'm here, I've also added the Ident and Sequence fields on the ICMPv4
type. Defaults are still zero.

PiperOrigin-RevId: 339577094
2020-10-28 18:18:18 -07:00
gVisor bot 17e0a4adde Merge pull request #2849 from lubinszARM:pr_memory_barrier
PiperOrigin-RevId: 339504677
2020-10-28 11:45:01 -07:00
Ting-Yu Wang 8fa18e8ecb Bump honnef.co/go/tools to v0.0.1-2020.1.6
PiperOrigin-RevId: 339476515
2020-10-28 09:41:11 -07:00