Commit Graph

5382 Commits

Author SHA1 Message Date
Fabricio Voznika 276ff149a4 Add MultiGetAttr message to 9P
While using remote-validation, the vast majority of time spent during
FS operations is re-walking the path to check for modifications and
then closing the file given that in most cases it has not been
modified externally.

This change introduces a new 9P message called MultiGetAttr which bulks
query attributes of several files in one shot. The returned attributes are
then used to update cached dentries before they are walked. File attributes
are updated for files that still exist. Dentries that have been deleted are
removed from the cache. And negative cache entries are removed if a new
file/directory was created externally. Similarly, synthetic dentries are
replaced if a file/directory is created externally.

The bulk update needs to be carefull not to follow symlinks, cross mount
points, because the gofer doesn't know how to resolve symlinks and where
mounts points are located. It also doesn't walk to the parent ("..") to
avoid deadlocks.

Here are the results:

Workload        VFS1       VFS2     Change
bazel action     115s       70s	     28.8s
Stat/100      11,043us   7,623us      974us

Updates #1638

PiperOrigin-RevId: 369325957
2021-04-19 16:25:01 -07:00
Nayana Bidari 8ad6657a22 Fix TCP RACK flaky unit tests.
- Added delay to increase the RTT: In DSACK tests with RACK enabled and low
RTT, TLP can be detected before sending ACK and the tests flake. Increasing
the RTT will ensure that TLP does not happen before the ACK is sent.
- Fix TestRACKOnePacketTailLoss: The ACK does not contain DSACK, which means
either the original or retransmission (probe) was lost and SACKRecovery count
must be incremented.

Before: http://sponge2/c9bd51de-f72f-481c-a7f3-e782e7524883
After: http://sponge2/1307a796-103a-4a45-b699-e8d239220ed1
PiperOrigin-RevId: 369305720
2021-04-19 14:44:05 -07:00
Andrei Vagin b0333d33a2 Optimize safemem.Zero
There is a loop that fills a byte array with zero-s. Let's use copy() instead
of setting elements one by one.

The new implementation is two time faster than the previous one and it is more
than 10x faster with the race detector.

Reported-by: syzbot+5f57d988a5f929af5a91@syzkaller.appspotmail.com
PiperOrigin-RevId: 369283919
2021-04-19 13:01:59 -07:00
Mithun Iyer 9b4cc3d43b Avoid ignoring incoming packet by demuxer on endpoint lookup failure
This fixes a race that occurs while the endpoint is being unregistered
and the transport demuxer attempts to match the incoming packet to any
endpoint. The race specifically occurs when the unregistration (and
deletion of the endpoint) occurs, after a successful endpointsByNIC
lookup and before the endpoints map is further looked up with ingress
NICID of the packet.

The fix is to notify the caller of lookup-with-NICID failure, so that
the logic falls through to handling unknown destination packets.
For TCP this can mean replying back with RST.

The syscall test in this CL catches this race as the ACK completing the
handshake could get silently dropped on a listener close, causing no
RST sent to the peer and timing out the poll waiting for POLLHUP.

Fixes #5850

PiperOrigin-RevId: 369023779
2021-04-17 11:32:17 -07:00
Ayush Ranjan 3b685753b4 [perf] Reduce contention due to renameMu in gofer client.
Runsc build benchmark's mutex profile shows that we are wasting roughly 25-30
seconds waiting for filesystem.renameMu to get unlocked. Earlier
checkCachingLocked required the renameMu to be locked for writing. This is a
filesystem wide lock which puts all other filesystem operations on hold and
hence is really expensive. Something to note is that all path resolution
operations hold renameMu for reading.

With this change, we allow to check for caching without even holding renameMu.
This change introduces more fine grained locks (fs.cacheMu and dentry.cachingMu)
which protect the cache (removing the requirement to hold renameMu for writing
to modify the cache) and synchronize concurrent dentry caching attempts on a per
dentry basis. We still require to hold renameMu for writing while destroying
dentries and evicting from the cache but this still significantly reduces the
write locking critical section.

Local benchmarking showed that this improved runsc build benchmark time by 4-5%.
Across 6 runs, without this change it took 310.9025 seconds to build runsc
while with this change it took 296.127 seconds.

Runsc build benchmark's mutex profile: https://gvisor.dev/profile/gvisor-buildkite/78a3f968-36ca-4944-93f7-77a8792d56b4/28a1d260-790b-4a9e-94da-a4daede08ee3/tmp/profile/ptrace/BenchmarkBuildRunsc/page_cache.clean/filesystem.bindfs/benchmarks/runsc/mutex.pprof/flamegraph

PiperOrigin-RevId: 368958136
2021-04-16 18:47:08 -07:00
Dean Deng 0c3e8daf50 Allow runsc to generate coverage reports.
Add a coverage-report flag that will cause the sandbox to generate a coverage
report (with suffix .cov) in the debug log directory upon exiting. For the
report to be generated, runsc must have been built with the following Bazel
flags: `--collect_code_coverage --instrumentation_filter=...`.

With coverage reports, we should be able to aggregate results across all tests
to surface code coverage statistics for the project as a whole.

The report is simply a text file with each line representing a covered block
as `file:start_line.start_col,end_line.end_col`. Note that this is similar to
the format of coverage reports generated with `go test -coverprofile`,
although we omit the count and number of statements, which are not useful for
us.

Some simple ways of getting coverage reports:

bazel test <some_test> --collect_code_coverage \
  --instrumentation_filter=//pkg/...

bazel build //runsc --collect_code_coverage \
  --instrumentation_filter=//pkg/...
runsc -coverage-report=dir/ <other_flags> do ...

PiperOrigin-RevId: 368952911
2021-04-16 17:56:16 -07:00
Ayush Ranjan ee45334f14 [lisa] Make go_marshal pass correctly sized buffers to safecopy.
gohacks.Memmove() takes in the number of bytes to move. The current generated
code passes len(src) and len(dst) as the number of bytes to move.

However, the marshal.Marshallable interface allows passing in larger buffers.
The stated precondition is that the buffer should be "at least" SizeBytes()
in length but it is allowed to be larger.

This change now correctly calls Memmove with the argument for the number of
bytes to move as type.SizeBytes(). This was caught when I made lisafs use the
Unsafe marshalling API and got a lot of memory violations.

PiperOrigin-RevId: 368952642
2021-04-16 17:51:52 -07:00
Kevin Krakauer 32c18f443f Enlarge port range and fix integer overflow
Also count failed TCP port allocations

PiperOrigin-RevId: 368939619
2021-04-16 16:28:56 -07:00
Zeling Feng 6241f89f49 Include logs for packetimpact tests that are expected to fail
PiperOrigin-RevId: 368938936
2021-04-16 16:23:56 -07:00
Dean Deng 81ff6bd921 Use size_t instead of C integer types.
PiperOrigin-RevId: 368919557
2021-04-16 14:33:34 -07:00
Zach Koopmans 025cff180c Internal change
PiperOrigin-RevId: 368919504
2021-04-16 14:28:23 -07:00
Ayush Ranjan 064a849f36 [op] Split nogo target out of unit tests.
Building nogo targets takes a very long time. This change extracts it into its
own BuildKite job.

This change also additionally speeds up other targets that were using the bazel
flag --test_tag_filters. Without --build_tag_filters, the filter is not
applied while building the specified targets and so we might end up building
targets that are not actually tested.

PiperOrigin-RevId: 368918211
2021-04-16 14:20:46 -07:00
Chong Cai c980fe573d Add verity ioctl test for mount with root hash
PiperOrigin-RevId: 368779532
2021-04-15 22:12:37 -07:00
Nayana Bidari 14b7d775c9 Add field support to the sentry metrics.
Fields allow counter metrics to have multiple tabular values.

At most one field is supported at the moment.

PiperOrigin-RevId: 368767040
2021-04-15 20:02:50 -07:00
Dean Deng 82dc881dba Disable failing socket_ipv4_udp_unbound_loopback_test_linux tests.
PiperOrigin-RevId: 368749894
2021-04-15 17:26:23 -07:00
Kevin Krakauer 19dfc4f7af Reduce tcp_x_test runtime and memory usage
Reduce the ephemeral port range, which decreases the calls to makeEP.

PiperOrigin-RevId: 368748379
2021-04-15 17:16:08 -07:00
Fabricio Voznika 2e50229749 Add S/R logic for host.ConnectedEndpoint
Otherwise ConnectedEndpoint.sndbuf will be restored as 0 and writes
to the socket will fail with EAGAIN.

PiperOrigin-RevId: 368746660
2021-04-15 17:04:39 -07:00
Dean Deng b5919d3065 Generate notification when closing host fd.
Thanks ianlewis@ for discovering the bug/fix!

PiperOrigin-RevId: 368740744
2021-04-15 16:30:58 -07:00
Kevin Krakauer 10de8978f9 Use nicer formatting for IP addresses in tests
This was semi-automated -- there are many addresses that were not replaced.
Future commits should clean those up.

Parse4 and Parse6 were given their own package because //pkg/test can introduce
dependency cycles, as it depends transitively on //pkg/tcpip and some other
netstack packages.

PiperOrigin-RevId: 368726528
2021-04-15 15:11:04 -07:00
Michael Pratt 108410638a Use assembly stub to take the address of assembly functions
Go 1.17 is adding a new register-based calling convention [1] ("ABIInternal"),
which used is when calling between Go functions. Assembly functions are still
written using the old ABI ("ABI0"). That is, they still accept arguments on the
stack, and pass arguments to other functions on the stack. The call rules look
approximately like this:

1. Direct call from Go function to Go function: compiler emits direct
   ABIInternal call.
2. Indirect call from Go function to Go function: compiler emits indirect
   ABIInternal call.
3. Direct call from Go function to assembly function: compiler emits direct
   ABI0 call.
4. Indirect call from Go function to assembly function: compiler emits indirect
   ABIInternal call to ABI conversion wrapper function.
5. Direct or indirect call from assembly function to assembly function:
   assembly/linker emits call to original ABI0 function.
6. Direct or indirect call from assembly function to Go function:
   assembly/linker emits ABI0 call to ABI conversion wrapper function.

Case 4 is the interesting one here. Since the compiler can't know the ABI of an
indirect call, all indirect calls are made with ABIInternal. In order to
support indirect ABI0 assembly function calls, a wrapper is generated that
translates ABIInternal arguments to ABI0 arguments, calls the target function,
and then converts results back.

When the address of an ABI0 function is taken from Go code, it evaluates to the
address of this wrapper function rather than the target function so that later
indirect calls will work as expected.

This is normally fine, but gVisor does more than just call some of the assembly
functions we take the address of: either noting the start and end address for
future reference from a signal handler (safecopy), or copying the function text
to a new mapping (platforms).

Both of these fail with wrappers enabled (currently, this is Go tip with
 GOEXPERIMENT=regabiwrappers) because these operations end up operating on the
wrapper instead of the target function.

We work around this issue by taking advantage of case 5: references to assembly
symbols from other assembly functions resolve directly to the desired target
symbol. Thus, rather than using reflect to get the address of a Go reference to
the functions, we create assembly stubs that return the address of the
function. This approach works just as well on current versions of Go, so the
change can be made immediately and doesn't require any build tags.

[1] https://go.googlesource.com/go/+/refs/heads/master/src/cmd/compile/abi-internal.md

PiperOrigin-RevId: 368505655
2021-04-14 14:14:21 -07:00
Ting-Yu Wang 272d2e1168 Make the generated test binary name match the target name
PiperOrigin-RevId: 368495641
2021-04-14 13:25:17 -07:00
Zach Koopmans 5c1052b6bb [syserror] Remove syserror from go_marshal
PiperOrigin-RevId: 368470656
2021-04-14 11:28:49 -07:00
Kevin Krakauer 36dbd3b97d Automatically enforce limited netstack dependencies
Netstack is supposed to be somewhat independent of the rest of gVisor, and
others should be able to use it without pulling in excessive dependencies.
Currently, there is no way to fight dependency creep besides careful code
review.

This change introduces a test rule `netstack_deps_check` that ensures the target
only relies on gVisor targets and a short allowlist of external dependencies.
Users who add a dependency will see an error and have to manually update the
allowlist.

The set of packages to test comes from //runsc, as it uses packages we would
expect users to commonly rely on. It was generated via:
$ find ./runsc -name BUILD | xargs grep tcpip | awk '{print $2}' | sort | uniq

(Note: We considered giving //pkg/tcpip it's own go.mod, but this breaks go
tooling.)

PiperOrigin-RevId: 368456711
2021-04-14 10:26:02 -07:00
Adin Scannell e83cc06f1b Remove _NoRandomSave tests.
We do not currently run random save tests.

PiperOrigin-RevId: 368309921
2021-04-13 15:42:41 -07:00
Mithun Iyer 326394b79a Fix listener close, client connect race
Fix a race where the ACK completing the handshake can be dropped by
a closing listener without RST to the peer. The listener close would
reset the accepted queue and that causes the connecting endpoint
in SYNRCVD state to drop the ACK thinking the queue if filled up.

PiperOrigin-RevId: 368165509
2021-04-13 00:58:56 -07:00
Ting-Yu Wang e5f58e89bb Make AsSockAddr() to replace reinterpret_cast<sockaddr*>
It's a common pattern in test code to reinterpret_cast<sockaddr*> from
sockaddr_* structs. Make AsSockAddr() for them so code looks better.

Note: Why not a wrapper type for `sockaddr_storage` and etc?
It's also a common need to have a local in-out variable of socklen_t.
Creating a wrapper type may however lead to this wrong code:
  Wrapper addr;
  socklen_t addrlen = sizeof(addr);
where sizeof(Wrapper) may not equal to sizeof(sockaddr_storage).
PiperOrigin-RevId: 368126229
2021-04-12 18:35:09 -07:00
Ian Lewis 90900e4f8f Don't mark exported PRs as stale.
PiperOrigin-RevId: 368121539
2021-04-12 17:56:06 -07:00
Chong Cai c4c6a71fb9 Add DecRef for verity FDs that were missing
Some FileDescriptions in verity fs were opened but DecRef() were missing
after used. This could result in a ref leak.

PiperOrigin-RevId: 368096759
2021-04-12 15:26:57 -07:00
Rahat Mahmood f4f6ce337a Don't grab TaskSet mu recursively when reading task state.
Reported-by: syzbot+a6ef0f95a2c9e7da26f3@syzkaller.appspotmail.com
Reported-by: syzbot+2eaf8a9f115edec468fe@syzkaller.appspotmail.com
PiperOrigin-RevId: 368093861
2021-04-12 15:12:52 -07:00
Ayush Ranjan 982fc8b576 [op] Use faster go_marshal methods in netfilter.
Use MarshalUnsafe for packed types as it is faster than MarshalBytes.

PiperOrigin-RevId: 368076368
2021-04-12 13:53:24 -07:00
Tamir Duberstein a804b42fe5 Drop locks before calling waiterQueue.Notify
Holding this lock can cause the user's callback to deadlock if it
attempts to inspect the accept queue.

PiperOrigin-RevId: 368068334
2021-04-12 13:14:41 -07:00
Adin Scannell 9c87ef53fd Add /etc/containerd/runsc.toml to conffiles attribute.
Fixes #5817

PiperOrigin-RevId: 368060056
2021-04-12 12:34:46 -07:00
Tamir Duberstein c84ff99124 Use the SecureRNG to generate listener nonces
Some other cleanup while I'm here:
- Remove unused arguments
- Handle some unhandled errors
- Remove redundant casts
- Remove redundant parens
- Avoid shadowing `hash` package name

PiperOrigin-RevId: 367816161
2021-04-10 14:53:55 -07:00
Tamir Duberstein 2fea7d096b Don't store accepted endpoints in a channel
Use a linked list with cached length and capacity. The current channel
is already composed with a mutex and condition variable, and is never
used for its channel-like properties. Channels also require eager
allocation equal to their capacity, which a linked list does not.

PiperOrigin-RevId: 367766626
2021-04-10 01:00:41 -07:00
Toshi Kikuchi d1edabdca0 iptables: support postrouting hook and SNAT target
The current SNAT implementation has several limitations:
- SNAT source port has to be specified. It is not optional.
- SNAT source port range is not supported.
- SNAT for UDP is a one-way translation. No response packets
  are handled (because conntrack doesn't support UDP currently).
- SNAT and REDIRECT can't work on the same connection.

Fixes #5489

PiperOrigin-RevId: 367750325
2021-04-09 21:11:26 -07:00
Chong Cai ea7faa5057 Return integrity failure only if enabled
If the parent is not enabled in verity stepLocked(), failure to find
the child dentry could just mean an incorrect path.

PiperOrigin-RevId: 367733412
2021-04-09 17:37:47 -07:00
gVisor bot 7420821a7b Merge pull request #5767 from avagin:mxcsr
PiperOrigin-RevId: 367730917
2021-04-09 17:15:06 -07:00
Mithun Iyer dc8f6c6914 Move maxListenBacklog check to sentry
Move maxListenBacklog check to the caller of endpoint Listen so that it
is applicable to Unix domain sockets as well.
This was changed in cl/366935921.

Reported-by: syzbot+a35ae7cdfdde0c41cf7a@syzkaller.appspotmail.com
PiperOrigin-RevId: 367728052
2021-04-09 16:53:33 -07:00
Ghanan Gowripalan 973ace6bd9 Rename IsV6LinkLocalAddress to IsV6LinkLocalUnicastAddress
To match the V4 variant.

PiperOrigin-RevId: 367691981
2021-04-09 13:23:01 -07:00
Tamir Duberstein 070b76fe7f Remove duplicate accept queue fullness check
Both code paths perform this check; extract it and remove the comment
that suggests it is unique to one of the paths.

PiperOrigin-RevId: 367666160
2021-04-09 11:08:21 -07:00
Tamir Duberstein 1fe5dd8c68 Propagate SYN handling error
Both callers of this function still drop this error on the floor, but
progress is progress.

Updates #4690.

PiperOrigin-RevId: 367604788
2021-04-09 03:43:23 -07:00
Chong Cai edf30a9bc5 Set root dentry and hash for verity before verify
Set root dentry and root hash in verity fs before we verify the root
directory if a root hash is provided. These are used during
verification.

PiperOrigin-RevId: 367547346
2021-04-08 18:33:20 -07:00
Chong Cai 496a3654e7 Set parent after child is verified
We should only set parent after child is verified. Also, if the parent
is set before verified, destroyLocked() will try to grab parent.dirMu,
which may cause deadlock.

PiperOrigin-RevId: 367543655
2021-04-08 18:01:49 -07:00
gVisor bot ae019e39b0 Merge pull request #5736 from lubinszARM:pr_bblu_tlb_asid
PiperOrigin-RevId: 367523491
2021-04-08 15:53:37 -07:00
Ghanan Gowripalan 091badcb9c Do not forward link-local packets
As per RFC 3927 section 7 and RFC 4291 section 2.5.6.

Test: forward_test.TestMulticastForwarding
PiperOrigin-RevId: 367519336
2021-04-08 15:30:53 -07:00
Adin Scannell 5ac79e1545 Drop unused escapes information.
PiperOrigin-RevId: 367517305
2021-04-08 15:19:02 -07:00
Chong Cai ffeb2a2f54 Add Children in merkletree generate
This field was missing and should be provided.

PiperOrigin-RevId: 367474481
2021-04-08 11:45:54 -07:00
Ghanan Gowripalan 9e4a1e31d4 Join all routers group when forwarding is enabled
See comments inline code for rationale.

Test: ip_test.TestJoinLeaveAllRoutersGroup
PiperOrigin-RevId: 367449434
2021-04-08 09:49:59 -07:00
Adin Scannell cbf00d633d Clarify platform errors.
PiperOrigin-RevId: 367446222
2021-04-08 09:34:01 -07:00
Adin Scannell 192f20788b Add internal staging tags to //runsc and //shim binaries.
PiperOrigin-RevId: 367328273
2021-04-07 17:13:11 -07:00