Commit Graph

4926 Commits

Author SHA1 Message Date
Ghanan Gowripalan 25570ac4f3 Track join count in multicast group protocol state
Before this change, the join count and the state for IGMP/MLD was held
across different types which required multiple locks to be held when
accessing a multicast group's state.

Bug #4682, #4861
Fixes #4916

PiperOrigin-RevId: 345019091
2020-12-01 07:52:40 -08:00
Dean Deng 6b1dbbbdc8 Fix typo in ptrace documentation.
PiperOrigin-RevId: 344958513
2020-11-30 23:16:39 -08:00
Zeling Feng 59a2c785bf Do not start a ContainerExec twice
ContainerExecStart and ContainerExecAttach both call the /exec/id/start API
endpoint.

PiperOrigin-RevId: 344946627
2020-11-30 21:22:55 -08:00
Bhasker Hariharan 79e2364933 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
Toshi Kikuchi 54ad145f2e Add more fragment reassembly tests
These tests check if a maximum-sized (64k) packet is reassembled without
receiving a fragment with MF flag set to zero.

PiperOrigin-RevId: 344913172
2020-11-30 16:36:51 -08:00
Jamie Liu 786f32c2b1 Do not os.Exit() from test/benchmarks/harness.Harness.Init with no args.
PiperOrigin-RevId: 344896991
2020-11-30 15:09:28 -08:00
Ghanan Gowripalan e813008664 Perform IGMP/MLD when the NIC is enabled/disabled
Test: ip_test.TestMGPWithNICLifecycle

Bug #4682, #4861

PiperOrigin-RevId: 344888091
2020-11-30 14:24:47 -08:00
Adin Scannell 3a60bc47a0 Ensure containerd is used from installed location.
Currently, if containerd is installed locally via tools/installers/containerd,
then it will not necessarily be used if containerd is installed in the system
path. This means that the existing containerd tests are all likely broken.

Also, use libbtrfs-dev instead of btrfs-tools, which is not actually required.

PiperOrigin-RevId: 344879109
2020-11-30 13:40:23 -08:00
Ghanan Gowripalan 4fd71a7b20 Don't add a temporary address to send DAD/RS packets
Bug #4803

PiperOrigin-RevId: 344553664
2020-11-27 12:55:28 -08:00
Ayush Ranjan ad83112423 [netstack] Add SOL_TCP options to SocketOptions.
Ports the following options:
- TCP_NODELAY
- TCP_CORK
- TCP_QUICKACK

Also deletes the {Get/Set}SockOptBool interface methods from all implementations

PiperOrigin-RevId: 344378824
2020-11-26 00:43:13 -08:00
Ayush Ranjan bebadb5182 [netstack] Add SOL_IP and SOL_IPV6 options to SocketOptions.
We will use SocketOptions for all kinds of options, not just SOL_SOCKET options
because (1) it is consistent with Linux which defines all option variables on
the top level socket struct, (2) avoid code complexity. Appropriate checks
have been added for matching option level to the endpoint type.

Ported the following options to this new utility:
- IP_MULTICAST_LOOP
- IP_RECVTOS
- IPV6_RECVTCLASS
- IP_PKTINFO
- IP_HDRINCL
- IPV6_V6ONLY

Changes in behavior (these are consistent with what Linux does AFAICT):
- Now IP_MULTICAST_LOOP can be set for TCP (earlier it was a noop) but does not
  affect the endpoint itself.
- We can now getsockopt IP_HDRINCL (earlier we would get an error).
- Now we return ErrUnknownProtocolOption if SOL_IP or SOL_IPV6 options are used
  on unix sockets.
- Now we return ErrUnknownProtocolOption if SOL_IPV6 options are used on non
  AF_INET6 endpoints.

This change additionally makes the following modifications:
- Add State() uint32 to commonEndpoint because both tcpip.Endpoint and
  transport.Endpoint interfaces have it. It proves to be quite useful.
- Gets rid of SocketOptionsHandler.IsListening(). It was an anomaly as it was
  not a handler. It is now implemented on netstack itself.
- Gets rid of tcp.endpoint.EndpointInfo and directly embeds
  stack.TransportEndpointInfo. There was an unnecessary level of embedding
  which served no purpose.
- Removes some checks dual_stack_test.go that used the errors from
  GetSockOptBool(tcpip.V6OnlyOption) to confirm some state. This is not
  consistent with the new design and also seemed to be testing the
  implementation instead of behavior.

PiperOrigin-RevId: 344354051
2020-11-25 20:01:10 -08:00
Ghanan Gowripalan bc81fcceda Support listener-side MLDv1
...as defined by RFC 2710. Querier (router)-side MLDv1 is not yet
supported.

The core state machine is shared with IGMPv2.

This is guarded behind a flag (ipv6.Options.MLDEnabled).

Tests: ip_test.TestMGP*

Bug #4861

PiperOrigin-RevId: 344344095
2020-11-25 18:00:41 -08:00
Ghanan Gowripalan 2485a4e2cb Make stack.Route safe to access concurrently
Multiple goroutines may use the same stack.Route concurrently so
the stack.Route should make sure that any functions called on it
are thread-safe.

Fixes #4073

PiperOrigin-RevId: 344320491
2020-11-25 14:52:59 -08:00
Zeling Feng 4d59a5a622 [3/3] Support isolated containers for parallel packetimpact tests
To create DUTs in parallel, we need to create goroutines to do the setup. The
old code base has a lot of t.Fatal(f) usage in those setup functions which is
not great for this change: "FailNow must be called from the goroutine running
the test or benchmark function, not from other goroutines created during the
test" (https://golang.org/pkg/testing/#T.FailNow).

- Cleanup all t.Fatal(f) usage in DUT.Prepare()
- use goroutines to create DUTs in parallel

PiperOrigin-RevId: 344275809
2020-11-25 10:24:37 -08:00
Zeling Feng d04144fbb7 [2/3] Support isolated containers for parallel packetimpact tests
Added a new flag num_duts to the test runner to create multiple DUTs for the
testbench can connect to.

PiperOrigin-RevId: 344195435
2020-11-24 23:22:05 -08:00
Robin Luk 3868c7dd40 arm64 kvm: add more handling of el0_exceptions
Add more comments and more handling for exceptions.

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2020-11-25 14:36:41 +08:00
Robin Luk be71d3569c arm64 test: add exceptions related test cases
For now, I only added a halt test case for Arm64.

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2020-11-25 13:43:11 +08:00
Sam Balana 99f2d0ea2f Correctly lock when removing neighbor entries
Fix a panic when two entries in Failed state are removed at the same time.

PiperOrigin-RevId: 344143777
2020-11-24 15:37:47 -08:00
Julian Elischer 4da63dc82e Report correct pointer value for "bad next header" ICMP error
Because the code handles a bad header as "payload" right up to the last moment
we need to make sure payload handling does not remove the error information.

Fixes #4909

PiperOrigin-RevId: 344141690
2020-11-24 15:25:40 -08:00
Sam Balana f90ab60a8a Track number of packets queued to Failed neighbors
Add a NIC-specific neighbor table statistic so we can determine how many
packets have been queued to Failed neighbors, indicating an unhealthy local
network. This change assists us to debug in-field issues where subsequent
traffic to a neighbor fails.

Fixes #4819

PiperOrigin-RevId: 344131119
2020-11-24 14:22:03 -08:00
Zeling Feng d492b21319 Fix a potential indefinite blocking in packetimpact testbench
1. setsockopt(SO_RCVTIMEO, 0) == never timeout
2. float64(time.Microsecond/time.Second) == 0
3. packetimpact tests use a lot of 1s timeouts

This becomes a more significant problem because of a recent change that binds
the sniffer only on the specific testNet interface so now the traffic on the
ctrlNet cannot wake up the blocking call anymore.

PiperOrigin-RevId: 344123465
2020-11-24 13:42:07 -08:00
Ghanan Gowripalan 732e989855 Extract IGMPv2 core state machine
The IGMPv2 core state machine can be shared with MLDv1 since they are
almost identical, ignoring specific addresses, constants and packets.

Bug #4682, #4861

PiperOrigin-RevId: 344102615
2020-11-24 11:50:00 -08:00
Dean Deng e5fd23c18d Remove outdated TODO.
The bug has been fixed.

PiperOrigin-RevId: 344088206
2020-11-24 10:39:31 -08:00
Ghanan Gowripalan 1de08889df Deduplicate code in ipv6.protocol
PiperOrigin-RevId: 344009602
2020-11-24 01:19:42 -08:00
Ghanan Gowripalan ba2d5cb7e1 Use time.Duration for IGMP Max Response Time field
Bug #4682

PiperOrigin-RevId: 343993297
2020-11-23 22:47:55 -08:00
Zeling Feng d4951e05a0 [1/3] Support isolated containers for parallel packetimpact tests
Summary of the approach: the test runner will set up a few DUTs according to
a flag and pass all the test networks to the testbench. The testbench will only
reside in a single container. The testbench will put all the test networks into
a buffered channel which served as a semaphore and now the user can freely use
t.Parallel() in (sub)tests and the true parallelism will be determined by how
many DUTs are configured. Creating DUTs on demand is not supported yet, the
test author should determine the number of DUTs to be used statically.

Specifically in this change:
- Don't export any global variables about the test network in testbench.
- Sniffer only binds on the local interface because it will be possible to have
  multiple interfaces to multiple DUTs in a single testbench container.
- Migrate existing tests to stop using global variables.

PiperOrigin-RevId: 343965962
2020-11-23 18:13:07 -08:00
Jamie Liu 986683124c Don't evict gofer.dentries with inotify watches before saving.
PiperOrigin-RevId: 343959348
2020-11-23 17:27:05 -08:00
Adin Scannell a94663ee56 Fix bad Makefile variable reference.
PiperOrigin-RevId: 343946859
2020-11-23 16:04:29 -08:00
Adin Scannell 756bc3e52b Clean up build output.
This change also simplifies and documents the build_cmd pipeline, and
reduces general noise for debugging Makefile issues.

It also drops the mapping for /etc/docker/daemon.json, which if it
does not exist initially will create this as a directory (causing lots
of confusion and breaks).

PiperOrigin-RevId: 343932456
2020-11-23 14:45:34 -08:00
Adin Scannell 3deb5d0c04 Fix link against runtime.goyield.
This function does not exist in Go 1.13. We need to add an adaptor
to build against Go 1.13, which is the default Ubuntu version.

PiperOrigin-RevId: 343929132
2020-11-23 14:30:23 -08:00
Adin Scannell 2320ce5b7d Fail gracefully if Docker is not configured with ipv6.
PiperOrigin-RevId: 343927315
2020-11-23 14:24:27 -08:00
Adin Scannell b6c00520d3 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 Scannell 5d5af88110 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
Adin Scannell 5212b4f7b2 Don't rely on HOME for tools/go_branch.sh
PiperOrigin-RevId: 343885770
2020-11-23 11:05:23 -08:00
Robin Luk 6a85d13ccf arm64 kvm: add to ext_dabt injection support
If no vild syndrome(data abort outside memslots) was reported by kvm, let userspace to do the
ext_dabt injection to bail out this issue.

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2020-11-23 16:47:19 +08:00
Chong Cai 60ae6c4d83 Refactor verity test for readability
1. Add getD/getDentry methods to avoid long casting line in each test
2. Factor all calls to vfs.OpenAt/UnlinkAt/RenameAt on lower filesystem
   to their own method (for both lower file and lower Merkle file) so
   the tests are more readable
3. Add descriptive test names for delete/remove tests

PiperOrigin-RevId: 343540202
2020-11-20 12:16:21 -08:00
gVisor bot ed8185fc75 Internal change.
PiperOrigin-RevId: 343419851
2020-11-19 20:03:53 -08:00
Ryan Heacock fbc4a8dbd1 Perform IGMPv2 when joining IPv4 multicast groups
Added headers, stats, checksum parsing capabilities from RFC 2236 describing
IGMPv2.

IGMPv2 state machine is implemented for each condition, sending and receiving
IGMP Membership Reports and Leave Group messages with backwards compatibility
with IGMPv1 routers.

Test:
* Implemented igmp header parser and checksum calculator in header/igmp_test.go
* ipv4/igmp_test.go tests incoming and outgoing IGMP messages and pathways.
* Added unit test coverage for IGMPv2 RFC behavior + IGMPv1 backwards
   compatibility in ipv4/igmp_test.go.

Fixes #4682

PiperOrigin-RevId: 343408809
2020-11-19 18:15:25 -08:00
Rahat Mahmood 9c553f2d4e Remove racy stringification of socket fds from /proc/net/*.
PiperOrigin-RevId: 343398191
2020-11-19 16:59:33 -08:00
Dean Deng d35a25cc88 Add a helpful message in stuck task logs.
This also makes the formatting nicer; the caller will add ":\n" to the end of
the message.

PiperOrigin-RevId: 343397099
2020-11-19 16:52:25 -08:00
Ghanan Gowripalan 4cf7956dde Add types to parse MLD messages
Preparing for upcoming CLs that add MLD functionality.

Bug #4861

Test: header.TestMLD
PiperOrigin-RevId: 343391556
2020-11-19 16:19:24 -08:00
Julian Elischer 49adf36ed7 Fix possible panic due to bad data.
Found by a Fuzzer.

Reported-by: syzbot+619fa10be366d553ef7f@syzkaller.appspotmail.com
PiperOrigin-RevId: 343379575
2020-11-19 15:17:00 -08:00
Fabricio Voznika 209a95a35a Propagate IP address prefix from host to netstack
Closes #4022

PiperOrigin-RevId: 343378647
2020-11-19 15:11:17 -08:00
Michael Pratt 3454d57219 Require sync.Mutex to lock and unlock from the same goroutine
We would like to track locks ordering to detect ordering violations. Detecting
violations is much simpler if mutexes must be unlocked by the same goroutine
that locked them.

Thus, as a first step to tracking lock ordering, add this lock/unlock
requirement to gVisor's sync.Mutex. This is more strict than the Go standard
library's sync.Mutex, but initial testing indicates only a single lock that is
used across goroutines. The new sync.CrossGoroutineMutex relaxes the
requirement (but will not provide lock order checking).

Due to the additional overhead, enforcement is only enabled with the
"checklocks" build tag. Build with this tag using:

bazel build --define=gotags=checklocks ...

From my spot-checking, this has no changed inlining properties when disabled.

Updates #4804

PiperOrigin-RevId: 343370200
2020-11-19 14:29:34 -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
Bruno Dal Bo 332671c339 Remove unused NoChecksumOption
Migration to unified socket options left this behind.

PiperOrigin-RevId: 343305434
2020-11-19 09:26:42 -08:00
Ting-Yu Wang e8df1ccef9 Fix some code not using NewPacketBuffer for creating a PacketBuffer.
PiperOrigin-RevId: 343299993
2020-11-19 08:56:58 -08:00
Robin Luk 4f79706ccd arm64 tlb: add support for tlbi-vale1ls/tlbi-aside1ls
This patch adds support for tlbi-vale1ls/tlbi-aside1ls.
And make the code consistent with the flush strategy of the x86 platform.

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2020-11-19 17:58:27 +08:00
Ayush Ranjan 74bc6e56cc [vfs] kernfs: Do not panic if destroyed dentry is cached.
If a kernfs user does not cache dentries, then cacheLocked will destroy the
dentry. The current DecRef implementation will be racy in this case as the
following can happen:
- Goroutine 1 calls DecRef and decreases ref count from 1 to 0.
- Goroutine 2 acquires d.fs.mu for reading and calls IncRef and increasing the
  ref count from 0 to 1.
- Goroutine 2 releases d.fs.mu and calls DecRef again decreasing ref count from
  1 to 0.
- Goroutine 1 now acquires d.fs.mu and calls cacheLocked which destroys the
  dentry.
- Goroutine 2 now acquires d.fs.mu and calls cacheLocked to find that the dentry
  is already destroyed!

Earlier we would panic in this case, we could instead just return instead of
adding complexity to handle this race. This is similar to what the gofer client
does.

We do not want to lock d.fs.mu in the case that the filesystem caches dentries
(common case as procfs and sysfs do this) to prevent congestion due to lock
contention.

PiperOrigin-RevId: 343229496
2020-11-18 23:10:30 -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