Commit Graph

712 Commits

Author SHA1 Message Date
Fabricio Voznika 7bde26934a Add IsRunningWithVFS1 to test util
VFS2 is adding more functionality than VFS1. In order to test
new functionality, it's required to skip some tests with VFS1.
To skip tests, use:

SKIP_IF(IsRunningWithVFS1());

The test will run in Linux and gVisor with VFS2 enabled.

Updates #1035

PiperOrigin-RevId: 312698616
2020-05-21 10:48:25 -07:00
Jay Zhuang 8298c5bd4d Avoid all caps FIONREAD as test name.
PiperOrigin-RevId: 312596169
2020-05-20 18:40:16 -07:00
Zeling Feng 5f3eeb4728 Test that we have PAWS mechanism
If there is a Timestamps option in the arriving segment and SEG.TSval
< TS.Recent and if TS.Recent is valid, then treat the arriving segment
as not acceptable: Send an acknowledgement in reply as specified in
RFC-793 page 69 and drop the segment.

https://tools.ietf.org/html/rfc1323#page-19

PiperOrigin-RevId: 312590678
2020-05-20 17:53:35 -07:00
gVisor bot a338eed1d8 Internal change.
PiperOrigin-RevId: 312559963
2020-05-20 14:57:59 -07:00
Jamie Liu 064347afdf Skip itimer "fairness" tests on ptrace.
With additional logging, the issue described by the new comment looks like:

D0518 21:28:08.416810    6777 task_signals.go:459] [   8] Notified of signal 27
D0518 21:28:08.416852    6777 task_block.go:223] [   8] Interrupt queued
D0518 21:28:08.417013    6777 task_run.go:250] [   8] Switching to sentry
D0518 21:28:08.417033    6777 task_signals.go:220] [   8] Signal 27: delivering to handler
D0518 21:28:08.417127    6777 task_run.go:248] [   8] Switching to app
D0518 21:28:08.443765    6777 task_signals.go:519] [   8] Refusing masked signal 27 // ED: note the ~26ms elapsed since TID 8 "switched to app"
D0518 21:28:08.443814    6777 task_signals.go:465] [   6] Notified of group signal 27
D0518 21:28:08.443832    6777 task_block.go:223] [   6] Interrupt queued
D0518 21:28:08.443914    6777 task_block.go:223] [   6] Interrupt queued
D0518 21:28:08.443859    6777 task_run.go:250] [   8] Switching to sentry
I0518 21:28:08.443936    6777 strace.go:576] [   8] exe E rt_sigreturn()

Slow context switches on ptrace are probably due to kernel scheduling delays.
Slow context switches on KVM are less clear, so leave that bug and TODO open.

PiperOrigin-RevId: 312322782
2020-05-19 11:53:03 -07:00
Dean Deng d06de1bede 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
Zeling Feng 99a18ec8b4 Support TCP options for packetimpact
PiperOrigin-RevId: 312119730
2020-05-18 11:31:38 -07:00
Jamie Liu fb7e5f1676 Make utimes_test pass on VFS2.
PiperOrigin-RevId: 311657502
2020-05-14 20:09:55 -07:00
gVisor bot 326abf5e36 Internal change.
PiperOrigin-RevId: 311645222
2020-05-14 18:17:33 -07:00
gVisor bot bdf7bb71d2 Merge pull request #2663 from lubinszARM:pr_sigfp_fork
PiperOrigin-RevId: 311573552
2020-05-14 11:38:57 -07:00
Mithun Iyer f1ad2d54ab Fix TCP segment retransmit timeout handling.
As per RFC 1122 and Linux retransmit timeout handling:
- The segment retransmit timeout needs to exponentially increase and
  cap at a predefined value.
- TCP connection needs to timeout after a predefined number of
  segment retransmissions.
- TCP connection should not timeout when the retranmission timeout
  exceeds MaxRTO, predefined upper bound.

Fixes #2673

PiperOrigin-RevId: 311463961
2020-05-13 21:26:54 -07:00
Bhasker Hariharan 8b8774d715 Stub support for TCP_SYNCNT and TCP_WINDOW_CLAMP.
This change adds support for TCP_SYNCNT and TCP_WINDOW_CLAMP options
in GetSockOpt/SetSockOpt. This change does not really change any
behaviour in Netstack and only stores/returns the stored value.

Actual honoring of these options will be added as required.

Fixes #2626, #2625

PiperOrigin-RevId: 311453777
2020-05-13 19:49:09 -07:00
Nicolas Lacasse db655f020e Resolve remaining TODOs for tmpfs.
Closes #1197

PiperOrigin-RevId: 311438223
2020-05-13 17:36:37 -07:00
Bhasker Hariharan 8605c97136 Automated rollback of changelist 311285868
PiperOrigin-RevId: 311424257
2020-05-13 16:13:37 -07:00
Jamie Liu d846077628 Enable overlayfs_stale_read by default for runsc.
Linux 4.18 and later make reads and writes coherent between pre-copy-up and
post-copy-up FDs representing the same file on an overlay filesystem. However,
memory mappings remain incoherent:

- Documentation/filesystems/overlayfs.rst, "Non-standard behavior": "If a file
  residing on a lower layer is opened for read-only and then memory mapped with
  MAP_SHARED, then subsequent changes to the file are not reflected in the
  memory mapping."

- fs/overlay/file.c:ovl_mmap() passes through to the underlying FD without any
  management of coherence in the overlay.

- Experimentally on Linux 5.2:

```
$ cat mmap_cat_page.c
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>

int main(int argc, char **argv) {
  if (argc < 2) {
    errx(1, "syntax: %s [FILE]", argv[0]);
  }
  const int fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    err(1, "open(%s)", argv[1]);
  }
  const size_t page_size = sysconf(_SC_PAGE_SIZE);
  void* page = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
  if (page == MAP_FAILED) {
    err(1, "mmap");
  }
  for (;;) {
    write(1, page, strnlen(page, page_size));
    if (getc(stdin) == EOF) {
      break;
    }
  }
  return 0;
}

$ gcc -O2 -o mmap_cat_page mmap_cat_page.c
$ mkdir lowerdir upperdir workdir overlaydir
$ echo old > lowerdir/file
$ sudo mount -t overlay -o "lowerdir=lowerdir,upperdir=upperdir,workdir=workdir" none overlaydir
$ ./mmap_cat_page overlaydir/file
old
^Z
[1]+  Stopped                 ./mmap_cat_page overlaydir/file
$ echo new > overlaydir/file
$ cat overlaydir/file
new
$ fg
./mmap_cat_page overlaydir/file

old
```

Therefore, while the VFS1 gofer client's behavior of reopening read FDs is only
necessary pre-4.18, replacing existing memory mappings (in both sentry and
application address spaces) with mappings of the new FD is required regardless
of kernel version, and this latter behavior is common to both VFS1 and VFS2.
Re-document accordingly, and change the runsc flag to enabled by default.

New test:
- Before this CL: https://source.cloud.google.com/results/invocations/5b222d2c-e918-4bae-afc4-407f5bac509b
- After this CL: https://source.cloud.google.com/results/invocations/f28c747e-d89c-4d8c-a461-602b33e71aab

PiperOrigin-RevId: 311361267
2020-05-13 10:53:37 -07:00
Ian Gudger e4058c0355 Replace test_runner.sh bash script with Go.
PiperOrigin-RevId: 311285868
2020-05-13 01:22:42 -07:00
Nayana Bidari 27b1f19cab iptables: support gid match for owner matching.
- Added support for matching gid owner and invert flag for uid
and gid.
$ iptables -A OUTPUT -p tcp -m owner --gid-owner root -j ACCEPT
$ iptables -A OUTPUT -p tcp -m owner ! --uid-owner root -j ACCEPT
$ iptables -A OUTPUT -p tcp -m owner ! --gid-owner root -j DROP

- Added tests for uid, gid and invert flags.
2020-05-12 12:20:47 -07:00
gVisor bot 633e1b89bb Internal change.
PiperOrigin-RevId: 311011004
2020-05-11 15:54:08 -07:00
gVisor bot c5ab21b048 Internal change.
PiperOrigin-RevId: 310949277
2020-05-11 11:04:31 -07:00
gVisor bot af2bc1c72a Internal change.
PiperOrigin-RevId: 310941717
2020-05-11 10:31:02 -07:00
Bin Lu 257a6bf883 passed the syscall test case 'fpsig_fork' on Arm64 platform
Some functions were added for Arm64 platform:
a, get_fp/set_fp
b, inline_tgkill

Test step:
bazel test //test/syscalls:fpsig_fork_test_runsc_ptrace

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-05-11 01:57:16 -04:00
gVisor bot cfd30665c1 iptables - filter packets using outgoing interface.
Enables commands with -o (--out-interface) for iptables rules.
$ iptables -A OUTPUT -o eth0 -j ACCEPT

PiperOrigin-RevId: 310642286
2020-05-08 15:44:54 -07:00
Bhasker Hariharan e4d2d21f6b Add UDP send/recv packetimpact tests.
Fixes #2654

PiperOrigin-RevId: 310642216
2020-05-08 15:40:27 -07:00
Zeling Feng 5d7d5ed7d6 Send ACK to OTW SEQs/unacc ACKs in CLOSE_WAIT
This fixed the corresponding packetimpact test.

PiperOrigin-RevId: 310593470
2020-05-08 11:23:24 -07:00
gVisor bot 92cab8e2c3 Internal change.
PiperOrigin-RevId: 310409922
2020-05-07 12:10:02 -07:00
gVisor bot 4631de620a Internal change.
PiperOrigin-RevId: 310213705
2020-05-06 13:13:48 -07:00
Andrei Vagin 9509c0b388 gvisor/test: use RetryEINTR for connect()
connect() returns EINTR after S/R and usually we
use RetryEINTR to workaround this.

PiperOrigin-RevId: 310038525
2020-05-05 16:01:00 -07:00
Mithun Iyer e590314fec Support TCP zero window probes.
As per RFC 1122 4.2.2.17, when the remote advertizes zero receive window,
the sender needs to probe for the window-size to become non-zero starting
from the next retransmission interval. The TCP connection needs to be kept
open as long as the remote is acknowledging the zero window probes.
We reuse the retransmission timers to support this.

Fixes #1644

PiperOrigin-RevId: 310021575
2020-05-05 14:30:52 -07:00
gVisor bot e5d9e7c3b2 Internal change.
PiperOrigin-RevId: 310001058
2020-05-05 12:43:28 -07:00
Nicolas Lacasse da71dc7fdd Port eventfd to VFS2.
And move sys_timerfd.go to just timerfd.go for consistency.

Updates #1475.

PiperOrigin-RevId: 309835029
2020-05-04 16:02:07 -07:00
gVisor bot e7ed68d225 Internal change.
PiperOrigin-RevId: 309832671
2020-05-04 15:48:45 -07:00
Andrei Vagin 006f978829 Deflake //third_party/gvisor/test/syscalls:proc_test_native
There is the known issue of the linux procfs, that two consequent calls of
readdir can return the same entry twice if between these calls one or more
entries have been removed from this directory.

PiperOrigin-RevId: 309803066
2020-05-04 12:58:24 -07:00
gVisor bot 711439b1c3 Merge pull request #2275 from nybidari:iptables
PiperOrigin-RevId: 309783486
2020-05-04 11:23:55 -07:00
Adin Scannell 56c64e4bb9 Fix include type.
PiperOrigin-RevId: 309506957
2020-05-01 18:03:09 -07:00
Nayana Bidari b660f16d18 Support for connection tracking of TCP packets.
Connection tracking is used to track packets in prerouting and
output hooks of iptables. The NAT rules modify the tuples in
connections. The connection tracking code modifies the packets by
looking at the modified tuples.
2020-05-01 16:59:40 -07:00
gVisor bot e7b8a71156 Internal change.
PiperOrigin-RevId: 309467878
2020-05-01 13:52:21 -07:00
Zeling Feng 4875cda8d1 Make tcp_close_wait_ack_test more accurate
Previously the test used an out-dated window size which is advertised
during the handshake to generate testing packets, but the window size
has changed since the handshake; currently it is using the most recent
one which is advertised in DUT's ACK to our FIN packet to generate the
testing outside-the-window packets.

PiperOrigin-RevId: 309222921
2020-04-30 07:40:34 -07:00
Dean Deng ce19497c1c Fix Unix socket permissions.
Enforce write permission checks in BoundEndpointAt, which corresponds to the
permission checks in Linux (net/unix/af_unix.c:unix_find_other).
Also, create bound socket files with the correct permissions in VFS2.

Fixes #2324.

PiperOrigin-RevId: 308949084
2020-04-28 20:13:01 -07:00
gVisor bot 24abccbc1c Internal change.
PiperOrigin-RevId: 308940886
2020-04-28 18:50:44 -07:00
Jamie Liu 4282260355 Don't unlink named pipes in pipe test.
TempPath's destructor runs at the end of the named pipe creation functions,
deleting the named pipe. If the named pipe is backed by a "non-virtual"
filesystem (!fs.Inode.IsVirtual()), this causes the following save attempt to
fail because there are FDs holding the deleted named pipe open.

PiperOrigin-RevId: 308861999
2020-04-28 11:28:44 -07:00
Fabricio Voznika 4af39dd1c5 Propagate PID limit from OCI to sandbox cgroup
Closes #2489

PiperOrigin-RevId: 308362434
2020-04-24 18:17:01 -07:00
Eyal Soha dfff265fe4 Add ICMP6 param problem test
Tested:
  When run on Linux, a correct ICMPv6 response is received.  On netstack, no
  ICMPv6 response is received.
PiperOrigin-RevId: 308343113
2020-04-24 15:56:27 -07:00
Eyal Soha 3d860530a9 Better error message from ExpectFrame
Display the errors as diffs between the expected and wanted frame.

PiperOrigin-RevId: 308333271
2020-04-24 15:04:03 -07:00
Eyal Soha d5776be3fb Improve and update packetimpact README.md
PiperOrigin-RevId: 308328860
2020-04-24 14:43:02 -07:00
Adin Scannell c60613475c Standardize all Docker images.
This change moves all Docker images to a standard location, and abstracts the
build process so that they can be maintained in an automated fashion. This also
allows the images to be architecture-independent.

All images will now be referred to by the test framework via the canonical
`gvisor.dev/images/<name>`, where `<name>` is a function of the path within the
source tree.

In a subsequent change, continuous integration will be added so that the images
will always be correct and available locally.

In the end, using `bazel` for Docker containers is simply not possible. Given
that we already have the need to use `make` with the base container (for
Docker), we extend this approach to get more flexibility.

This change also adds a self-documenting and powerful Makefile that is intended
to replace the collection of scripts in scripts. Canonical (self-documenting)
targets can be added here for targets that understand which images need to be
loaded and/or built.

PiperOrigin-RevId: 308322438
2020-04-24 14:11:42 -07:00
Eyal Soha 79542417fe Fix Layer merge and add unit tests
mergo was improperly merging nil and empty strings

PiperOrigin-RevId: 308170862
2020-04-23 18:24:31 -07:00
Eyal Soha cc5de905e6 Fix test output so that filenames have the correct path.
Tested:
  Intentionally introduce an error and then run:
  blaze test --test_output=streamed //third_party/gvisor/test/packetimpact/tests:tcp_outside_the_window_linux_test
PiperOrigin-RevId: 308114194
2020-04-23 13:18:59 -07:00
Adin Scannell 1481499fe2 Simplify Docker test infrastructure.
This change adds a layer of abstraction around the internal Docker APIs,
and eliminates all direct dependencies on Dockerfiles in the infrastructure.

A subsequent change will automated the generation of local images (with
efficient caching). Note that this change drops the use of bazel container
rules, as that experiment does not seem to be viable.

PiperOrigin-RevId: 308095430
2020-04-23 11:33:30 -07:00
Eyal Soha a2925a079f Run failing packetimpact test and expect failure.
This will make it easier to notice if a code change causes an existing test to
pass.

PiperOrigin-RevId: 308057978
2020-04-23 08:36:19 -07:00
Andrei Vagin 37f863f628 tcp: handle listen after shutdown properly
Right now, sentry panics in this case:
panic: close of nil channel

goroutine 67 [running]:
pkg/tcpip/transport/tcp/tcp.(*endpoint).listen(0xc0000ce000, 0x9, 0x0)
        pkg/tcpip/transport/tcp/endpoint.go:2208 +0x170
pkg/tcpip/transport/tcp/tcp.(*endpoint).Listen(0xc0000ce000, 0x9, 0xc0003a1ad0)
        pkg/tcpip/transport/tcp/endpoint.go:2179 +0x50

Fixes #2468

PiperOrigin-RevId: 307896725
2020-04-22 14:17:11 -07:00