Commit Graph

241 Commits

Author SHA1 Message Date
Zach Koopmans f0507e1db1 Fix flaky stat.cc test.
This test flaked on my current CL. Linux makes no guarantee
that two inodes will consecutive (overflows happen).

https://github.com/avagin/linux-task-diag/blob/master/fs/inode.c#L880

PiperOrigin-RevId: 260608240
2019-07-29 16:47:58 -07:00
Kevin Krakauer 09be87bbee Add iptables types for syscalls tests.
Unfortunately, Linux's ip_tables.h header doesn't compile in C++ because it
implicitly converts from void* to struct xt_entry_target*. C allows this, but
C++ does not. So we have to re-implement many types ourselves.

Relevant code here:
https://github.com/torvalds/linux/blob/master/include/uapi/linux/netfilter_ipv4/ip_tables.h#L222

PiperOrigin-RevId: 260565570
2019-07-29 13:20:09 -07:00
Fabricio Voznika 7052d21dc4 Automated rollback of changelist 255679453
PiperOrigin-RevId: 260047477
2019-07-25 16:48:49 -07:00
Tamir Duberstein 12c256568b Deduplicate EndpointState.connected some
This fixes a bug introduced in cl/251934850 that caused
connect-accept-close-connect races to result in the second connect call
failiing when it should have succeeded.

PiperOrigin-RevId: 259584525
2019-07-23 12:10:18 -07:00
gVisor bot f544509c01 Merge pull request #450 from Pixep:feature/add-clock-boottime-as-monotonic
PiperOrigin-RevId: 258996346
2019-07-19 10:44:45 -07:00
Chris Kuiper 0e040ba6e8 Handle interfaceAddr and NIC options separately for IP_MULTICAST_IF
This tweaks the handling code for IP_MULTICAST_IF to ignore the InterfaceAddr
if a NICID is given.

PiperOrigin-RevId: 258982541
2019-07-19 09:29:04 -07:00
Andrei Vagin eefa817cfd net/tcp/setockopt: impelment setsockopt(fd, SOL_TCP, TCP_INQ)
PiperOrigin-RevId: 258859507
2019-07-18 15:41:04 -07:00
Kevin Krakauer 9f1189130e Add AF_UNIX, SOCK_RAW sockets, which exist for some reason.
tcpdump creates these.

PiperOrigin-RevId: 258611829
2019-07-17 11:49:16 -07:00
gVisor bot 682fd2d68f Merge pull request #533 from kevinGC:stub-dev-tty
PiperOrigin-RevId: 258607547
2019-07-17 11:28:30 -07:00
Michael Pratt ca829158e3 Properly invalidate cache in rename and remove
We were invalidating the wrong overlayEntry in rename and missing invalidation
in rename and remove if lower exists.

PiperOrigin-RevId: 258604685
2019-07-17 11:14:57 -07:00
Adrien Leravat 02d1bd67f0 Add CLOCK_BOOTTIME tests to timerfd.cc 2019-07-16 21:30:48 -07:00
gVisor bot 74dc663bbb Internal change.
PiperOrigin-RevId: 258424489
2019-07-16 13:03:37 -07:00
Kevin Krakauer 3d78baf06d Replace vector of arrays with array of arrays.
C++ does not like vectors of arrays (because arrays are not copy-constructable).

PiperOrigin-RevId: 258270980
2019-07-15 17:29:13 -07:00
Neel Natu ab44d145bb Fix initialization of badhandler_low_water_mark in SigaltstackTest.
It is now correctly initialized to the top of the signal stack.
Previously it was initialized to the address of 'stack.ss_sp' on
the main thread stack.

PiperOrigin-RevId: 258248363
2019-07-15 15:22:24 -07:00
Kevin Krakauer 9b4d3280e1 Add IPPROTO_RAW, which allows raw sockets to write IP headers.
iptables also relies on IPPROTO_RAW in a way. It opens such a socket to
manipulate the kernel's tables, but it doesn't actually use any of the
functionality. Blegh.

PiperOrigin-RevId: 257903078
2019-07-12 18:09:12 -07:00
Kevin Krakauer 6ebb925acd Add permission, char device, and uid checks.
Change-Id: I8307bfb390a56424aaa651285a218aad277c4aed
2019-07-12 15:16:01 -07:00
Bhasker Hariharan 6116473b2f Stub out support for TCP_MAXSEG.
Adds support to set/get the TCP_MAXSEG value but does not
really change the segment sizes emitted by netstack or
alter the MSS advertised by the endpoint. This is currently
being added only to unblock iperf3 on gVisor. Plumbing
this correctly requires a bit more work which will come
in separate CLs.

PiperOrigin-RevId: 257859112
2019-07-12 13:35:17 -07:00
gVisor bot eff2c264a4 Merge pull request #282 from zhangningdlut:chris_test_proc
PiperOrigin-RevId: 257855479
2019-07-12 13:11:01 -07:00
Kevin 44427d8e26 Add a stub for /dev/tty.
Actual implementation to follow, but this will satisfy applications that
want it to just exist.
2019-07-11 21:24:27 -07:00
Liu Hua 7581e84cb6 tss: block userspace access to all I/O ports.
A userspace process (CPL=3) can access an i/o port if the bit corresponding to
the port is set to 0 in the I/O permission bitmap.

Configure the I/O permission bitmap address beyond the last valid byte in the
TSS so access to all i/o ports is blocked.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
Change-Id: I3df76980c3735491db768f7210e71703f86bb989
PiperOrigin-RevId: 257336518
2019-07-09 22:21:56 -07:00
Nicolas Lacasse 6db3f8d54c Don't mask errors in createAt loop.
The error set in the loop in createAt was being masked
by other errors declared with ":=". This allowed an
ErrResolveViaReadlink error to escape, which can cause
a sentry panic.

Added test case which repros without the fix.

PiperOrigin-RevId: 257061767
2019-07-08 14:57:15 -07:00
Andrei Vagin 116cac053e netstack/udp: connect with the AF_UNSPEC address family means disconnect
PiperOrigin-RevId: 256433283
2019-07-03 14:19:02 -07:00
Neel Natu 1178a278ae Mark timers_test flaky because setrlimit(RLIMIT_CPU) is broken in some kernels.
https://bugzilla.redhat.com/show_bug.cgi?id=1568337

PiperOrigin-RevId: 256276198
2019-07-02 17:58:15 -07:00
Nicolas Lacasse 06537129a6 Check remaining traversal limit when creating a file through a symlink.
This fixes the case when an app tries to create a file that already exists, and
is a symlink to itself. A test was added.

PiperOrigin-RevId: 256044811
2019-07-01 15:25:22 -07:00
Nicolas Lacasse cf51e77d6d Fix suggestions from clang.
PiperOrigin-RevId: 255679603
2019-06-28 15:32:29 -07:00
Nicolas Lacasse 295078fa7a Automated rollback of changelist 255263686
PiperOrigin-RevId: 255679453
2019-06-28 15:28:41 -07:00
Fabricio Voznika b2907595e5 Complete pipe support on overlayfs
Get/Set pipe size and ioctl support were missing from
overlayfs. It required moving the pipe.Sizer interface
to fs so that overlay could get access.

Fixes #318

PiperOrigin-RevId: 255511125
2019-06-27 17:22:53 -07:00
Michael Pratt 5b41ba5d0e Fix various spelling issues in the documentation
Addresses obvious typos, in the documentation only.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/443 from Pixep:fix/documentation-spelling 4d0688164eafaf0b3010e5f4824b35d1e7176d65
PiperOrigin-RevId: 255477779
2019-06-27 14:25:50 -07:00
gVisor bot 7188790f92 Merge pull request #461 from brb-g:128_procseekend
PiperOrigin-RevId: 255462850
2019-06-27 13:58:14 -07:00
Fabricio Voznika 42e212f6b7 Preserve permissions when checking lower
The code was wrongly assuming that only read access was
required from the lower overlay when checking for permissions.
This allowed non-writable files to be writable in the overlay.

Fixes #316

PiperOrigin-RevId: 255263686
2019-06-26 14:24:44 -07:00
Nicolas Lacasse 857e5c47e9 Follow symlinks when creating a file, and create the target.
If we have a symlink whose target does not exist, creating the symlink (either
via 'creat' or 'open' with O_CREAT flag) should create the target of the
symlink. Previously, gVisor would error with EEXIST in this case

PiperOrigin-RevId: 255232944
2019-06-26 11:49:20 -07:00
Adrien Leravat 3688e6e99d Add CLOCK_BOOTTIME as a CLOCK_MONOTONIC alias
Makes CLOCK_BOOTTIME available with
* clock_gettime
* timerfd_create
* clock_gettime vDSO

CLOCK_BOOTTIME is implemented as an alias to CLOCK_MONOTONIC.
CLOCK_MONOTONIC already keeps track of time across save
and restore. This is the closest possible behavior to Linux
CLOCK_BOOTIME, as there is no concept of suspend/resume.

Updates google/gvisor#218
2019-06-24 21:14:38 -07:00
Andrei Vagin e9ea7230f7 fs: synchronize concurrent writes into files with O_APPEND
For files with O_APPEND, a file write operation gets a file size and uses it as
offset to call an inode write operation. This means that all other operations
which can change a file size should be blocked while the write operation doesn't
complete.

PiperOrigin-RevId: 254873771
2019-06-24 17:45:02 -07:00
Rahat Mahmood 94a6bfab5d Implement /proc/net/tcp.
PiperOrigin-RevId: 254854346
2019-06-24 15:56:36 -07:00
Nicolas Lacasse 87df9aab24 Use correct statx syscall number for amd64.
The previous number was for the arm architecture.

Also change the statx tests to force them to run on gVisor, which would have
caught this issue.

PiperOrigin-RevId: 254846831
2019-06-24 15:19:36 -07:00
brb-g 6f0a7de44b Add regression test for #128 (fixed in ab6774ce)
Tests run at HEAD (35719d52):
```
$ bazel test $(bazel query 'filter(".*getdents.*", //test/syscalls:all)')
<snip>
//test/syscalls:getdents_test_native                                     PASSED in 0.3s
//test/syscalls:getdents_test_runsc_ptrace                               PASSED in 4.9s
//test/syscalls:getdents_test_runsc_ptrace_overlay                       PASSED in 4.7s
//test/syscalls:getdents_test_runsc_ptrace_shared                        PASSED in 5.2s
//test/syscalls:getdents_test_runsc_kvm                                  FAILED in 4.0s
```

Tests run at ab6774ce~1 (6f933a93):
```
$ bazel test $(bazel query 'filter(".*getdents.*", //test/syscalls:all)')
//test/syscalls:getdents_test_native                                     PASSED in 0.2s
//test/syscalls:getdents_test_runsc_kvm                                  FAILED in 4.2s
  /usr/local/google/home/brb/.cache/bazel/_bazel_brb/967240a6aae7d353a221d73f4375e038/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/syscalls/getdents_test_runsc_kvm/test.log
//test/syscalls:getdents_test_runsc_ptrace                               FAILED in 5.3s
  /usr/local/google/home/brb/.cache/bazel/_bazel_brb/967240a6aae7d353a221d73f4375e038/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/syscalls/getdents_test_runsc_ptrace/test.log
//test/syscalls:getdents_test_runsc_ptrace_overlay                       FAILED in 4.9s
  /usr/local/google/home/brb/.cache/bazel/_bazel_brb/967240a6aae7d353a221d73f4375e038/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/syscalls/getdents_test_runsc_ptrace_overlay/test.log
//test/syscalls:getdents_test_runsc_ptrace_shared                        FAILED in 5.2s
  /usr/local/google/home/brb/.cache/bazel/_bazel_brb/967240a6aae7d353a221d73f4375e038/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/syscalls/getdents_test_runsc_ptrace_shared/test.log
```

(I think all runsc_kvm tests are broken on my machine -- I'll rerun them
if you can point me at the documentation to set it up)
2019-06-24 14:37:14 -07:00
chris.zn f957fb23cf Return ENOENT when reading /proc/{pid}/task of an exited process
There will be a deadloop when we use getdents to read /proc/{pid}/task
of an exited process

Like this:

Process A is running
                         Process B: open /proc/{pid of A}/task
Process A exits
                         Process B: getdents /proc/{pid of A}/task

Then, process B will fall into deadloop, and return "." and ".."
in loops and never ends.

This patch returns ENOENT when use getdents to read /proc/{pid}/task
if the process is just exited.

Signed-off-by: chris.zn <chris.zn@antfin.com>
2019-06-24 15:49:53 +08:00
Nicolas Lacasse 35719d52c7 Implement statx.
We don't have the plumbing for btime yet, so that field is left off. The
returned mask indicates that btime is absent.

Fixes #343

PiperOrigin-RevId: 254575752
2019-06-22 13:29:26 -07:00
Bhasker Hariharan c1761378a9 Fix the logic for sending zero window updates.
Today we have the logic split in two places between endpoint Read() and the
worker goroutine which actually sends a zero window. This change makes it so
that when a zero window ACK is sent we set a flag in the endpoint which can be
read by the endpoint to decide if it should notify the worker to send a
nonZeroWindow update.

The worker now does not do the check again but instead sends an ACK and flips
the flag right away.

Similarly today when SO_RECVBUF is set the SetSockOpt call has logic
to decide if a zero window update is required. Rather than do that we move
the logic to the worker goroutine and it can check the zeroWindow flag
and send an update if required.

PiperOrigin-RevId: 254505447
2019-06-21 18:31:31 -07:00
Ian Gudger dc36c34a76 Close FD on TcpSocketTest loop failure.
This helps prevent the blocking call from getting stuck and causing a test
timeout.

PiperOrigin-RevId: 254325926
2019-06-20 20:40:31 -07:00
Neel Natu 3c7448ab6f Deflake TestSIGALRMToMainThread.
Bump up the threshold on number of SIGALRMs received by worker
threads from 50 to 200. Even with the new threshold we still
expect that the majority of SIGALRMs are received by the
thread group leader.

PiperOrigin-RevId: 254289787
2019-06-20 15:58:18 -07:00
Neel Natu 0b2135072d Implement madvise(MADV_DONTFORK)
PiperOrigin-RevId: 254253777
2019-06-20 12:56:00 -07:00
Michael Pratt c2d87d5d7c Mark tcp_socket test flaky (for real)
The tag on the binary has no effect. It must be on the test.

PiperOrigin-RevId: 254103480
2019-06-19 17:18:11 -07:00
Nicolas Lacasse 9781128d5a Deflake mount_test.
Inode ids are only stable across Save/Restore if we have an open FD on the
inode. All tests that compare inode ids must therefor hold an FD open.

PiperOrigin-RevId: 254086603
2019-06-19 15:46:11 -07:00
Michael Pratt 773423a997 Abort loop on failure
As-is, on failure these will infinite loop, resulting in test timeout
instead of failure.

PiperOrigin-RevId: 254074989
2019-06-19 14:48:18 -07:00
Neel Natu 0d1dc50b70 Mark tcp_socket test flaky.
PiperOrigin-RevId: 253997465
2019-06-19 08:08:12 -07:00
Rahat Mahmood 546b2948cb Use return values from syscalls in eventfd tests.
PiperOrigin-RevId: 253890611
2019-06-18 16:21:56 -07:00
Brad Burlage 2e1379867a Replace usage of deprecated strtoul/strtoull
PiperOrigin-RevId: 253864770
2019-06-18 14:18:47 -07:00
Fabricio Voznika ec15fb1162 Fix PipeTest_Streaming timeout
Test was calling Size() inside read and write loops. Size()
makes 2 syscalls to return the pipe size, making the test
do a lot more work than it should.

PiperOrigin-RevId: 253824690
2019-06-18 11:03:33 -07:00
Ian Gudger 0a5ee6f7b2 Fix deadlock in fasync.
The deadlock can occur when both ends of a connected Unix socket which has
FIOASYNC enabled on at least one end are closed at the same time. One end
notifies that it is closing, calling (*waiter.Queue).Notify which takes
waiter.Queue.mu (as a read lock) and then calls (*FileAsync).Callback, which
takes FileAsync.mu. The other end tries to unregister for notifications by
calling (*FileAsync).Unregister, which takes FileAsync.mu and calls
(*waiter.Queue).EventUnregister which takes waiter.Queue.mu.

This is fixed by moving the calls to waiter.Waitable.EventRegister and
waiter.Waitable.EventUnregister outside of the protection of any mutex used
in (*FileAsync).Callback.

The new test is related, but does not cover this particular situation.

Also fix a data race on FileAsync.e.Callback. (*FileAsync).Callback checked
FileAsync.e.Callback under the protection of FileAsync.mu, but the waiter
calling (*FileAsync).Callback could not and did not. This is fixed by making
FileAsync.e.Callback immutable before passing it to the waiter for the first
time.

Fixes #346

PiperOrigin-RevId: 253138340
2019-06-13 17:26:22 -07:00