Commit Graph

321 Commits

Author SHA1 Message Date
Jamie Liu 69afd0438e Return srclen in proc.idMapFileOperations.Write.
PiperOrigin-RevId: 241037926
Change-Id: I4b0381ac1c7575e8b861291b068d3da22bc03850
2019-03-29 13:16:46 -07:00
chris.zn 31c2236e97 set task's name when fork
When fork a child process, the name filed of TaskContext is not set.
It results in that when we cat /proc/{pid}/status, the name filed is
null.

Like this:
Name:
State:  S (sleeping)
Tgid:   28
Pid:    28
PPid:   26
TracerPid:      0
FDSize: 8
VmSize: 89712 kB
VmRSS:  6648 kB
Threads:        1
CapInh: 00000000a93d35fb
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 00000000a93d35fb
Seccomp:        0
Change-Id: I5d469098c37cedd19da16b7ffab2e546a28a321e
PiperOrigin-RevId: 240893304
2019-03-28 18:05:42 -07:00
Nicolas Lacasse 99195b0e16 Setting timestamps should trigger an inotify event.
PiperOrigin-RevId: 240850187
Change-Id: I1458581b771a1031e47bba439e480829794927b8
2019-03-28 14:15:23 -07:00
Jamie Liu f005350c93 Clean up gofer handle caching.
- Document fsutil.CachedFileObject.FD() requirements on access
permissions, and change gofer.inodeFileState.FD() to honor them.
Fixes #147.

- Combine gofer.inodeFileState.readonly and
gofer.inodeFileState.readthrough, and simplify handle caching logic.

- Inline gofer.cachePolicy.cacheHandles into
gofer.inodeFileState.setSharedHandles, because users with access to
gofer.inodeFileState don't necessarily have access to the fs.Inode
(predictably, this is a save/restore problem).

Before this CL:

$ docker run --runtime=runsc-d -v $(pwd)/gvisor/repro:/root/repro -it ubuntu bash
root@34d51017ed67:/# /root/repro/runsc-b147
mmap: 0x7f3c01e45000
Segmentation fault

After this CL:

$ docker run --runtime=runsc-d -v $(pwd)/gvisor/repro:/root/repro -it ubuntu bash
root@d3c3cb56bbf9:/# /root/repro/runsc-b147
mmap: 0x7f78987ec000
o
PiperOrigin-RevId: 240818413
Change-Id: I49e1d4a81a0cb9177832b0a9f31a10da722a896b
2019-03-28 11:43:51 -07:00
Nicolas Lacasse 9c18897887 Add rsslim field in /proc/pid/stat.
PiperOrigin-RevId: 240681675
Change-Id: Ib214106e303669fca2d5c744ed5c18e835775161
2019-03-27 17:44:38 -07:00
Nicolas Lacasse 2d355f0e8f Add start time to /proc/<pid>/stat.
The start time is the number of clock ticks between the boot time and
application start time.

PiperOrigin-RevId: 240619475
Change-Id: Ic8bd7a73e36627ed563988864b0c551c052492a5
2019-03-27 12:41:27 -07:00
Rahat Mahmood 06ec97a3f8 Implement memfd_create.
Memfds are simply anonymous tmpfs files with no associated
mounts. Also implementing file seals, which Linux only implements for
memfds at the moment.

PiperOrigin-RevId: 240450031
Change-Id: I31de78b950101ae8d7a13d0e93fe52d98ea06f2f
2019-03-26 16:16:57 -07:00
Andrei Vagin 79aca14a0c Use toolchain configs from bazel_0.23.0
bazel 0.24.0 isn't compatible with bazel_0.20.0 configs:
(10:32:27) ERROR:
bazel_toolchains/configs/ubuntu16_04_clang/1.1/bazel_0.20.0/default/BUILD:57:1:
no such attribute 'dynamic_runtime_libs' in 'cc_toolchain' rule

PiperOrigin-RevId: 240436868
Change-Id: Iee68c9b79d907ca2bdd124386aaa77c786e089ce
2019-03-26 15:10:49 -07:00
Nicolas Lacasse b81bfd6013 lstat should resolve the final path component if it ends in a slash.
PiperOrigin-RevId: 239896221
Change-Id: I0949981fe50c57131c5631cdeb10b225648575c0
2019-03-22 17:38:13 -07:00
Jamie Liu 3d0b960112 Implement PTRACE_SEIZE, PTRACE_INTERRUPT, and PTRACE_LISTEN.
PiperOrigin-RevId: 239803092
Change-Id: I42d612ed6a889e011e8474538958c6de90c6fcab
2019-03-22 08:55:44 -07:00
Ian Gudger 7d0227ff16 Add test for short recvmsg iovec length.
PiperOrigin-RevId: 239718991
Change-Id: Idc78557a8e9bfdd3cb7d8ec4db708364652640a4
2019-03-21 18:53:17 -07:00
Ian Gudger 125d3a19e3 Test TCP sockets with MSG_TRUNC|MSG_PEEK.
PiperOrigin-RevId: 239714368
Change-Id: I35860b880a1d8885eb8c2d4ff267caaf72d91088
2019-03-21 18:11:22 -07:00
Ian Gudger ba828233b9 Clear msghdr flags on successful recvmsg.
.net sets these flags to -1 and then uses their result, especting it to be
zero.

Does not set actual flags (e.g. MSG_TRUNC), but setting to zero is more correct
than what we did before.

PiperOrigin-RevId: 239657951
Change-Id: I89c5f84bc9b94a2cd8ff84e8ecfea09e01142030
2019-03-21 13:19:11 -07:00
Andrei Vagin 87cce0ec08 netstack: reduce MSS from SYN to account tcp options
See: https://tools.ietf.org/html/rfc6691#section-2
PiperOrigin-RevId: 239305632
Change-Id: Ie8eb912a43332e6490045dc95570709c5b81855e
2019-03-19 17:33:20 -07:00
Michael Pratt 8a499ae65f Remove references to replaced child in Rename in ramfs/agentfs
In the case of a rename replacing an existing destination inode, ramfs
Rename failed to first remove the replaced inode. This caused:

1. A leak of a reference to the inode (making it live indefinitely).
2. For directories, a leak of the replaced directory's .. link to the
   parent. This would cause the parent's link count to incorrectly
   increase.

(2) is much simpler to test than (1), so that's what I've done.

agentfs has a similar bug with link count only, so the Dirent layer
informs the Inode if this is a replacing rename.

Fixes #133

PiperOrigin-RevId: 239105698
Change-Id: I4450af2462d8ae3339def812287213d2cbeebde0
2019-03-18 18:40:06 -07:00
Fabricio Voznika eb69542807 Internal change
PiperOrigin-RevId: 239031539
Change-Id: I783127d0287a647d21de40c301c5a5c2e62b7640
2019-03-18 11:57:19 -07:00
Kevin Krakauer 88d791c259 Replace use of ucontext with ucontext_t.
PiperOrigin-RevId: 239026571
Change-Id: Ifd01674855094f3abad497776f418023452033a1
2019-03-18 11:32:20 -07:00
Kevin Krakauer 6ee3d6614b Fix flaky RawPingAndSockets (and MultipleSocketsRecieve just in case).
PiperOrigin-RevId: 238474202
Change-Id: Ib8c431e973e8cf1e1c8ee2f8c1978ddb8e88b0b8
2019-03-15 13:57:24 -07:00
Ian Gudger 71d53382bf Fix getsockopt(IP_MULTICAST_IF).
getsockopt(IP_MULTICAST_IF) only supports struct in_addr.

Also adds support for setsockopt(IP_MULTICAST_IF) with struct in_addr.

PiperOrigin-RevId: 237620230
Change-Id: I75e7b5b3e08972164eb1906f43ddd67aedffc27c
2019-03-09 11:40:51 -08:00
Ian Gudger 281092e842 Make IP_MULTICAST_LOOP and IP_MULTICAST_TTL allow setting int or char.
This is the correct Linux behavior, and at least PHP depends on it.

PiperOrigin-RevId: 237565639
Change-Id: I931af09c8ed99a842cf70d22bfe0b65e330c4137
2019-03-08 20:27:58 -08:00
Ian Gudger 86036f979b Validate multicast addresses in multicast group operations.
PiperOrigin-RevId: 237559843
Change-Id: I93a9d83a08cd3d49d5fc7fcad5b0710d0aa04aaa
2019-03-08 19:05:26 -08:00
Ian Gudger 56a6128295 Implement IP_MULTICAST_LOOP.
IP_MULTICAST_LOOP controls whether or not multicast packets sent on the default
route are looped back. In order to implement this switch, support for sending
and looping back multicast packets on the default route had to be implemented.

For now we only support IPv4 multicast.

PiperOrigin-RevId: 237534603
Change-Id: I490ac7ff8e8ebef417c7eb049a919c29d156ac1c
2019-03-08 15:49:17 -08:00
Andrei Vagin 832589cb07 Fix tests which fail in kokoro
* open_create_test_runsc_ptrace_shared doesn't expect the write access to /
* exec_test_runsc_ptrace_shared could not find /usr/share/zoneinfo/
* clock_gettime_test_runsc_ptrace_shared didn't expect that
  a thread cpu time can be zero.
* affinity_test_runsc_ptrace_shared expected minimum 3 cpus

PiperOrigin-RevId: 237509429
Change-Id: I477937e5d2cdf3f8720836bfa972abd35d8220a3
2019-03-08 13:33:32 -08:00
Michael Pratt cdd63375d3 Increase ipv4_udp_unbound_loopback size to medium
Now that tests aren't running in parallel, this test occassionally
takes too long and times out.

PiperOrigin-RevId: 237106971
Change-Id: I195a4b77315c9f5511c9e8ffadddb7aaa78beafd
2019-03-06 13:19:29 -08:00
Michael Pratt 54ac76c305 Remove unsafe ScopedSigaction
ScopedSigaction is not async-signal-safe, so it cannot be used after fork.
Replace it with plain sigaction, which is safe. This is in a unique child
anyways, so it doesn't need any cleanup.

PiperOrigin-RevId: 237102411
Change-Id: I5c6ea373bbac67b9c4db204ceb1db62d338d9178
2019-03-06 12:55:52 -08:00
Fabricio Voznika 0b76887147 Priority-inheritance futex implementation
It is Implemented without the priority inheritance part given
that gVisor defers scheduling decisions to Go runtime and doesn't
have control over it.

PiperOrigin-RevId: 236989545
Change-Id: I714c8ca0798743ecf3167b14ffeb5cd834302560
2019-03-05 23:40:18 -08:00
Michael Pratt bd46185e24 Add NoRandomSave to tests with correctness DisableSave
Tests using DisableSave because a portion of the test is *incompatible*
with S/R clearly cannot use random S/R, as the saves may occur in the
DisableSave critical section.

Most such tests already have NoRandomSave. Add it to the rest.

PiperOrigin-RevId: 236914708
Change-Id: Iee1cf044cfa7cb8d5aba21ddc130926218210c48
2019-03-05 13:54:38 -08:00
Nicolas Lacasse 0d683c9961 Make tmpfs respect MountNoATime now that fs.Handle is gone.
PiperOrigin-RevId: 236752802
Change-Id: I9e50600b2ae25d5f2ac632c4405a7a185bdc3c92
2019-03-04 16:57:14 -08:00
Ian Gudger 2d613f8e30 Deflake socket_ipv4_udp_unbound_loopback.
When run in parallel, multicast packets can be received by the wrong test. The
tests in the target are run in an isolated network namespace, but if
parallelism is enabled, multiple tests from the same target will run in
parallel within the target's network namespace. Disabling parallelism only
allows one test to run in the network namespace at a time, which prevents
interaction.

PiperOrigin-RevId: 236709160
Change-Id: If828db44f0ae4002af36de6097866137c8d9da5c
2019-03-04 13:06:04 -08:00
Michael Pratt 96226f9a47 Mark socket_ipv4_udp_unbound_loopback flaky
To do so, we must add the ability to add tags to the syscall tests.

PiperOrigin-RevId: 236380371
Change-Id: I76d15feb2700f20115b27aab362a88cebe8c7a6a
2019-03-01 14:38:10 -08:00
Fabricio Voznika 3dbd4a16f8 Add semctl(GETPID) syscall
Also added unimplemented notification for semctl(2)
commands.

PiperOrigin-RevId: 236340672
Change-Id: I0795e3bd2e6d41d7936fabb731884df426a42478
2019-03-01 10:57:02 -08:00
Kevin Krakauer 420a89acd3 Fix flaky raw socket test.
The specific issue was:

- Test creates a raw ICMP socket
- Test sends an ICMP echo request (aka ping request) to itself via loopback
- Now two events race:
  - The raw socket recieves the ICMP echo request
  - Netstack receives the request and generates a reply (aka ping reply),
    which it sends back over loopback, where it is eventually received by the
    raw socket
- The test was written to expect packets in a specific order, but they can
  come in any order.

PiperOrigin-RevId: 236179066
Change-Id: I02c07c919d3d28093add3d18dd9196fbbc870813
2019-02-28 12:53:02 -08:00
Kevin Krakauer 121db29a93 Ping support via IPv4 raw sockets.
Broadly, this change:
* Enables sockets to be created via `socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)`.
* Passes the network-layer (IP) header up the stack to the transport endpoint,
  which can pass it up to the socket layer. This allows a raw socket to return
  the entire IP packet to users.
* Adds functions to stack.TransportProtocol, stack.Stack, stack.transportDemuxer
  that enable incoming packets to be delivered to raw endpoints. New raw sockets
  of other protocols (not ICMP) just need to register with the stack.
* Enables ping.endpoint to return IP headers when created via SOCK_RAW.

PiperOrigin-RevId: 235993280
Change-Id: I60ed994f5ff18b2cbd79f063a7fdf15d093d845a
2019-02-27 14:31:21 -08:00
Fabricio Voznika 6df212b831 Don't log twice to debug log when --log isn't set
PiperOrigin-RevId: 235940853
Change-Id: I9c5b4cf18b199fb74044a5edb131bfff59dec945
2019-02-27 10:06:35 -08:00
Brian Geffon aeb7283a91 Improve PosixErrorOr messages using gtest matchers.
There was a minor bug whth IsPosixErrorOkAndHoldsMatcher where
it wouldn't display the actual value contained. This fixes that
and adds a few other minor improvements.

PiperOrigin-RevId: 235809065
Change-Id: I487e5072e9569eb06104522963e9a1b34204daaf
2019-02-26 15:47:42 -08:00
Michael Pratt 563c9ed1d6 Use a custom, world-accessible, /tmp mount
This solves two problems:

1. Using the host /tmp directly meant that concurrent tests could
   collide attempting to use the same file, and that misbehaving tests
   never have their /tmp output cleaned up.
2. Host /tmp is not world-accessible on all hosts. Some tests (e.g.,
   sticky) access files in /tmp from other users, so we need to ensure
   that its /tmp is world-accessible.

PiperOrigin-RevId: 235637873
Change-Id: I7555224685ac5b93af88c403196b09ce1bb2bfe7
2019-02-25 18:06:43 -08:00
Fabricio Voznika 10426e0f31 Handle invalid offset in sendfile(2)
PiperOrigin-RevId: 235578698
Change-Id: I608ff5e25eac97f6e1bda058511c1f82b0e3b736
2019-02-25 12:17:46 -08:00
Amanda Tait ea070b9d5f Implement Broadcast support
This change adds support for the SO_BROADCAST socket option in gVisor Netstack.
This support includes getsockopt()/setsockopt() functionality for both UDP and
TCP endpoints (the latter being a NOOP), dispatching broadcast messages up and
down the stack, and route finding/creation for broadcast packets. Finally, a
suite of tests have been implemented, exercising this functionality through the
Linux syscall API.

PiperOrigin-RevId: 234850781
Change-Id: If3e666666917d39f55083741c78314a06defb26c
2019-02-20 12:54:13 -08:00
Kevin Krakauer ec2460b189 netstack: Add SIOCGSTAMP support.
Ping sometimes uses this instead of SO_TIMESTAMP.

PiperOrigin-RevId: 234699590
Change-Id: Ibec9c34fa0d443a931557a2b1b1ecd83effe7765
2019-02-19 16:41:32 -08:00
Jamie Liu bed6f8534b Set rax to syscall number on SECCOMP_RET_TRAP.
PiperOrigin-RevId: 234690475
Change-Id: I1cbfb5aecd4697a4a26ec8524354aa8656cc3ba1
2019-02-19 15:49:37 -08:00
Jamie Liu bb47d8a545 Fix clone(CLONE_NEWUSER).
- Use new user namespace for namespace creation checks.

- Ensure userns is never nil since it's used by other namespaces.

PiperOrigin-RevId: 234673175
Change-Id: I4b9d9d1e63ce4e24362089793961a996f7540cd9
2019-02-19 14:20:05 -08:00
Jamie Liu 22d8b6eba1 Break /proc/[pid]/{uid,gid}_map's dependence on seqfile.
In addition to simplifying the implementation, this fixes two bugs:

- seqfile.NewSeqFile unconditionally creates an inode with mode 0444,
  but {uid,gid}_map have mode 0644.

- idMapSeqFile.Write implements fs.FileOperations.Write ... but it
  doesn't implement any other fs.FileOperations methods and is never
  used as fs.FileOperations. idMapSeqFile.GetFile() =>
  seqfile.SeqFile.GetFile() uses seqfile.seqFileOperations instead,
  which rejects all writes.

PiperOrigin-RevId: 234638212
Change-Id: I4568f741ab07929273a009d7e468c8205a8541bc
2019-02-19 11:21:46 -08:00
Ian Gudger c611dbc5a7 Implement IP_MULTICAST_IF.
This allows setting a default send interface for IPv4 multicast. IPv6 support
will come later.

PiperOrigin-RevId: 234251379
Change-Id: I65922341cd8b8880f690fae3eeb7ddfa47c8c173
2019-02-15 18:40:15 -08:00
Andrei Vagin 3ff9dc9cc1 gvisor: check that ptrace properly handles int3
PiperOrigin-RevId: 233516412
Change-Id: I7a0f1443de7eeebb5d8ad59e4759ca2e036a3c4d
2019-02-11 18:05:34 -08:00
Andrei Vagin ecce96bab5 gvisor: Run syscall tests in kokoro on the rbe cluster
PiperOrigin-RevId: 233458853
Change-Id: I92c734b8075aa31e040fe7b4770bcf608e271e7a
2019-02-11 12:43:38 -08:00
Ian Gudger 85d53d81d9 Use socket address functions in unbound IPv4 UDP tests.
Also switch to the correct casing style for local address variables.

PiperOrigin-RevId: 233161128
Change-Id: Ibc4a10a5d3ab04c40907aa885e8237b255c65a79
2019-02-08 18:23:38 -08:00
Ian Gudger 80f901b16b Plumb IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP to netstack.
Also includes a few fixes for IPv4 multicast support. IPv6 support is coming in
a followup CL.

PiperOrigin-RevId: 233008638
Change-Id: If7dae6222fef43fda48033f0292af77832d95e82
2019-02-07 23:15:23 -08:00
Andrei Vagin fda4d1f4f1 gvisor/tests: save runsc logs for each container in a separate directory
PiperOrigin-RevId: 232990964
Change-Id: Icfa426d5e83c7d3e56b0b92e6a9e1229bcb8361b
2019-02-07 19:32:51 -08:00
Rahat Mahmood 2ba74f84be Implement /proc/net/unix.
PiperOrigin-RevId: 232948478
Change-Id: Ib830121e5e79afaf5d38d17aeef5a1ef97913d23
2019-02-07 14:44:21 -08:00
Fabricio Voznika 9ef3427ac1 Implement semctl(2) SETALL and GETALL
PiperOrigin-RevId: 232914984
Change-Id: Id2643d7ad8e986ca9be76d860788a71db2674cda
2019-02-07 11:41:44 -08:00
Googler 3c71e025e8 Internal change.
PiperOrigin-RevId: 232776481
Change-Id: Ic19d4aa6322fef71621bad0e9fb8bdedf6694114
2019-02-06 17:00:24 -08:00
Zach Koopmans 0cf7fc4e11 Change /proc/PID/cmdline to read environment vector.
- Change proc to return envp on overwrite of argv with limitations from
upstream.
- Add unit tests
- Change layout of argv/envp on the stack so that end of argv is contiguous with
beginning of envp.

PiperOrigin-RevId: 232506107
Change-Id: I993880499ab2c1220f6dc456a922235c49304dec
2019-02-05 10:02:06 -08:00
Kevin Krakauer 3eae03fe4f Deflake unlink test.
Multiple tests were creating the same directory before removing it, making it
possible for concurrent tests to fail because the directory already exists.

PiperOrigin-RevId: 232389814
Change-Id: I35d409fff4b3fd864b30fee742cb587b14975c23
2019-02-04 16:35:37 -08:00
Andrei Vagin 4f5fd311dc gvisor/test: Remove gtest shard env variables
PiperOrigin-RevId: 232071420
Change-Id: I5aa57f3dc4aac637d6f467445b4b3110fc08ac80
2019-02-01 18:13:27 -08:00
Fabricio Voznika aec5b67c81 Add syscall test dimension for --file_access=shared
PiperOrigin-RevId: 231856279
Change-Id: I175db87374890a62a3a3c2ddef727668ff854ce4
2019-01-31 14:38:12 -08:00
Michael Pratt 2a0c69b19f Remove license comments
Nothing reads them and they can simply get stale.

Generated with:
$ sed -i "s/licenses(\(.*\)).*/licenses(\1)/" **/BUILD

PiperOrigin-RevId: 231818945
Change-Id: Ibc3f9838546b7e94f13f217060d31f4ada9d4bf0
2019-01-31 11:12:53 -08:00
Jamie Liu 3c5f8dfd4b Don't assume that stdout is always writable in PollTest.Nfds.
stdout can be (and, in automated testing, often is) a host pipe or
similar resource shared between multiple parallel tests, such that it
can become transiently full during testing.

PiperOrigin-RevId: 231413569
Change-Id: Id14991b5f71e53c894695899e65e1be4dd228cc6
2019-01-29 09:06:59 -08:00
Jamie Liu 57c202ead2 Refactor out NewEventFD to a test utility.
PiperOrigin-RevId: 231404512
Change-Id: I31efcc23a0c4a48ef6fbba3ca07415d79290f55c
2019-01-29 08:01:48 -08:00
Jamie Liu 9114471a5a Remove obsolete gVisor-specific test condition.
PiperOrigin-RevId: 231274510
Change-Id: I8f65157dbe18dae1c6235147fc4d27e0c844c833
2019-01-28 13:03:07 -08:00
Zhaozhong Ni 196e9f9d82 Convert outdated TODO to NOTE.
PiperOrigin-RevId: 231263193
Change-Id: Ib732c9639462f7994d473050495d88c2855434af
2019-01-28 11:59:43 -08:00
Jamie Liu a8b8e13154 Deflake socket_stream_blocking tests.
PiperOrigin-RevId: 231020482
Change-Id: Idd9168678b18d03aac473adcc40902e27e06d0a1
2019-01-25 22:38:48 -08:00
Jamie Liu 876b241fac Remove O_CLOEXEC from socket test configurations where irrelevant.
The implementation of O_CLOEXEC is orthogonal to every property tested
by these tests; removing it significantly reduces the number of
redundant tests we run.

Also remove no-op calls to VecCat (calls with a single argument).

PiperOrigin-RevId: 230959537
Change-Id: I83fe7db24e481ef67ca1f1992228af423f640b5c
2019-01-25 13:35:32 -08:00
Fabricio Voznika cc99520753 Add runsc logs to test results
PiperOrigin-RevId: 230850177
Change-Id: I34eb24e8ff8dd9ce3e7f5eb2dc2ee58eeac49f07
2019-01-24 22:42:39 -08:00
Fabricio Voznika 01679f3b5a Increase gofer coverage in tests
Lots of tests use /tmp for the tests. Force /tmp to be
mounted over fsgofer instead of tmpfs.

PiperOrigin-RevId: 230788985
Change-Id: Id6597ed88133232d15e808c48126bf77cb32673e
2019-01-24 14:20:16 -08:00
Jamie Liu 79e0451bd1 Explicitly std::move() returned std::vector<Mapping>.
Otherwise, C++11-compliant compilers may select PosixErrorOr(const T&)
as the relevant constructor, and fail because std::vector<Mapping> is
not copyable (because Mapping is not copyable).

This is a C++11 defect that is fixed in C++14 (and in C++11 mode for
Clang, but not GCC). See DR 1579,
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579.

PiperOrigin-RevId: 230767401
Change-Id: I65f481f5188d91db6cbbbd65ed0a60bc55df3401
2019-01-24 12:18:10 -08:00
Michael Pratt 74f5100a92 Fix cases of missing braces on if
PiperOrigin-RevId: 230641540
Change-Id: Icccc3cdeec191138940f0ecea0a29798359d2b1f
2019-01-23 18:24:48 -08:00
Andrei Vagin af89fb49af socket_netlink_route: ignore negative port ID values
netlink_autobind() sets a port id to a process ID, if this address is
available. Otherwise, it will set a port id to a random negative value.

PiperOrigin-RevId: 230631956
Change-Id: I11692e4fe9421e77d9406627b4e7772e4d9b105a
2019-01-23 17:08:48 -08:00
Andrei Vagin ceb3dcfb72 gvisor/test: fix a compile time error in socket_netdevice
Compilation of this test fails in kokoro:

In file included from /usr/include/linux/netdevice.h:28:0,
                 from /usr/include/linux/if_arp.h:26,
                 from ./test/syscalls/linux/socket_netlink_util.h:18,
                 from test/syscalls/linux/socket_netdevice.cc:24:
/usr/include/linux/if.h:143:8: error: redefinition of 'struct ifmap'
 struct ifmap {
        ^~~~~
In file included from test/syscalls/linux/socket_netdevice.cc:18:0:
/usr/include/net/if.h:111:8: note: previous definition of 'struct ifmap'
 struct ifmap
        ^~~~~
In file included from /usr/include/linux/netdevice.h:28:0,
                 from /usr/include/linux/if_arp.h:26,
                 from ./test/syscalls/linux/socket_netlink_util.h:18,
                 from test/syscalls/linux/socket_netdevice.cc:24:
/usr/include/linux/if.h:177:8: error: redefinition of 'struct ifreq'
 struct ifreq {
        ^~~~~
In file included from test/syscalls/linux/socket_netdevice.cc:18:0:
/usr/include/net/if.h:126:8: note: previous definition of 'struct ifreq'
 struct ifreq
        ^~~~~
In file included from /usr/include/linux/netdevice.h:28:0,
                 from /usr/include/linux/if_arp.h:26,
                 from ./test/syscalls/linux/socket_netlink_util.h:18,
                 from test/syscalls/linux/socket_netdevice.cc:24:
/usr/include/linux/if.h:226:8: error: redefinition of 'struct ifconf'
 struct ifconf  {
        ^~~~~~
In file included from test/syscalls/linux/socket_netdevice.cc:18:0:
/usr/include/net/if.h:176:8: note: previous definition of 'struct ifconf'
 struct ifconf

PiperOrigin-RevId: 230381931
Change-Id: I3c422c53e50cf2b90022778599d3a8a4a61fd1a3
2019-01-22 11:49:36 -08:00
Nicolas Lacasse 12bc7834dc Allow fsync on a directory.
PiperOrigin-RevId: 229781337
Change-Id: I1f946cff2771714fb1abd83a83ed454e9febda0a
2019-01-17 11:06:59 -08:00
Fabricio Voznika e4d3ca7263 Prevent internal tmpfs mount to override files in /tmp
Runsc wants to mount /tmp using internal tmpfs implementation for
performance. However, it risks hiding files that may exist under
/tmp in case it's present in the container. Now, it only mounts
over /tmp iff:
  - /tmp was not explicitly asked to be mounted
  - /tmp is empty

If any of this is not true, then /tmp maps to the container's
image /tmp.

Note: checkpoint doesn't have sentry FS mounted to check if /tmp
is empty. It simply looks for explicit mounts right now.
PiperOrigin-RevId: 229607856
Change-Id: I10b6dae7ac157ef578efc4dfceb089f3b94cde06
2019-01-16 12:48:32 -08:00
Yong He 6c117a01e9 Set end of subslice as begin of next subslice
syscall test split testcase via shard count, reset
high bound as begin of next subslice, cause the slice
is half-open range.

Change-Id: I1954f57c93cbfd9be518153315da305a2de377a0
PiperOrigin-RevId: 229405199
2019-01-15 11:16:10 -08:00
Nicolas Lacasse dc8450b567 Remove fs.Handle, ramfs.Entry, and all the DeprecatedFileOperations.
More helper structs have been added to the fsutil package to make it easier to
implement fs.InodeOperations and fs.FileOperations.

PiperOrigin-RevId: 229305982
Change-Id: Ib6f8d3862f4216745116857913dbfa351530223b
2019-01-14 20:34:28 -08:00
Andrei Vagin 343ebe9789 Fix a few compilation warnings
test/syscalls/linux/wait.cc:626:8: warning: lambda capture 'this' is not
used
302
  [this, stack] { ASSERT_THAT(FreeStack(stack), SyscallSucceeds()); });
303
   ^~~~~

test/syscalls/linux/priority.cc:195:17: warning: lambda capture
'kParentPriority' is not required to be captured for this use
273
ScopedThread([kParentPriority, kChildPriority]() {
274
	    ^~~~~~~~~~~~~~~~

PiperOrigin-RevId: 229275900
Change-Id: I6f0c88efc7891c6c729378a2fa70f70b1b9046a7
2019-01-14 16:13:14 -08:00
Ian Gudger 003eedea1c Deflake RecvLessThanBufferWaitAll.
PiperOrigin-RevId: 229238781
Change-Id: Ib5a1e46293583efcb09e255fcd400c3fcc53ef1b
2019-01-14 13:07:29 -08:00
Nicolas Lacasse 36f5468e7a Automated rollback of changelist 228945914
PiperOrigin-RevId: 229214698
Change-Id: Ib4ea2e330e61ee34bf913938d6120a52ecc38ce1
2019-01-14 11:04:00 -08:00
Jamie Liu bf65e06c5f Clean up some uses of fork() in tests.
- Fix a few cases where async-signal-unsafe code is executed in a forked
  process pre-execve.

- Ensure that the return value of fork() is always checked.

PiperOrigin-RevId: 228949310
Change-Id: I3096cb7d7394b8d9ab81b0e0245f2060713ef589
2019-01-11 14:49:39 -08:00
Jamie Liu 290bcb6de9 Require CAP_SYS_CHROOT in ChrootTest.ProcMountsMountinfoNoEscape.
PiperOrigin-RevId: 228949227
Change-Id: I8f47bcd56aab706081218ec7498af8049ccd6d63
2019-01-11 14:48:26 -08:00
Nicolas Lacasse 1bcc1229e8 Make syscall_test_runner binary testonly.
PiperOrigin-RevId: 228945914
Change-Id: Idfa0a3c27434655b5f9ac241f1726e0bc9ef0392
2019-01-11 14:30:13 -08:00
Michael Pratt bde588ff05 Define name earlier
PiperOrigin-RevId: 228805981
Change-Id: I4f4c4a5d8de325dff38f6dfb92108fc848d823fd
2019-01-10 17:16:36 -08:00
Zach Koopmans 7f8de3bf92 Fixing select call to not enforce RLIMIT_NOFILE.
Removing check to RLIMIT_NOFILE in select call.
Adding unit test to select suite to document behavior.
Moving setrlimit class from mlock to a util file for reuse.
Fixing flaky test based on comments from Jamie.

PiperOrigin-RevId: 228726131
Change-Id: Ie9dbe970bbf835ba2cca6e17eec7c2ee6fadf459
2019-01-10 09:44:45 -08:00
Nicolas Lacasse 6e91a98f6b Avoid $(location) in syscall tests.
Instead just find the syscall_test_runner binary in the shell script.

PiperOrigin-RevId: 228621230
Change-Id: I274ee0874e47d53f59474b1ac730ee45e3dff977
2019-01-09 17:37:52 -08:00
Jamie Liu 0676843875 Make CooperativeSaveEnabled() async-signal-safe(r).
The static local variable `enabled` in CooperativeSaveEnabled() is not
initialized until the first call to CooperativeSaveEnabled(), per the
C++14 standard, section 6.7 ("Declaration statement"), paragraph 4. This
initialization is thread-safe as of C++11, but it is *not* required to
be async-signal-safe. Use a namespace-scope variable instead, since this
is guaranteed to be zero-initialized before main() by section 3.6.2
("Initialization of non-local variables").

getenv() is technically not async-signal-safe either, hence the hedging
in the change summary line. However, glibc's implementation of getenv()
appears to be async-signal-safe in the absence of calls to setenv().

PiperOrigin-RevId: 228588617
Change-Id: I669f555d1c91352d55c606970bb237ec888fa7ca
2019-01-09 14:27:59 -08:00
Andrei Vagin 252e57992d Allow to specify a custom path to runsc for syscall-test-runner
PiperOrigin-RevId: 228574092
Change-Id: Id93abcca1ce964eb595907df9355702d469bc33b
2019-01-09 13:14:28 -08:00
Brian Geffon bc19103d58 Enable proc/self/fd test on linux and disable only on gvisor.
PiperOrigin-RevId: 228403149
Change-Id: Iab212e49d9eb27d785bddc9fd447835ce8c485ae
2019-01-08 14:46:23 -08:00
Jamie Liu 901ed5da44 Implement /proc/[pid]/smaps.
PiperOrigin-RevId: 228245523
Change-Id: I5a4d0a6570b93958e51437e917e5331d83e23a7e
2019-01-07 15:17:44 -08:00
Jamie Liu e44cb43b9c Default syscall_test shard_count to 5.
PiperOrigin-RevId: 228243120
Change-Id: I2726d580f4f9fad0ecc6a912e0e576ed9e08ce72
2019-01-07 15:05:10 -08:00
Brian Geffon d89836fe51 Add test for reopening socketpair end via procfs.
PiperOrigin-RevId: 227738801
Change-Id: Ic0c5d10c3b1f21b3f85ff9a661a55db77fab77b0
2019-01-03 13:23:18 -08:00
Andrei Vagin 652d068119 Implement SO_REUSEPORT for TCP and UDP sockets
This option allows multiple sockets to be bound to the same port.

Incoming packets are distributed to sockets using a hash based on source and
destination addresses. This means that all packets from one sender will be
received by the same server socket.

PiperOrigin-RevId: 227153413
Change-Id: I59b6edda9c2209d5b8968671e9129adb675920cf
2018-12-28 11:27:14 -08:00
Fabricio Voznika 46e6577014 Fix deadlock between epoll_wait and getdents
epoll_wait acquires EventPoll.listsMu (in EventPoll.ReadEvents) and
then calls Inotify.Readiness which tries to acquire Inotify.evMu.

getdents acquires Inotify.evMu (in Inotify.queueEvent) and then calls
readyCallback.Callback which tries to acquire EventPoll.listsMu.

The fix is to release Inotify.evMu before calling Queue.Notify. Queue
is thread-safe and doesn't require Inotify.evMu to be held.

Closes #121

PiperOrigin-RevId: 227066695
Change-Id: Id29364bb940d1727f33a5dff9a3c52f390c15761
2018-12-27 14:59:50 -08:00
Ian Gudger bce2f9751f Plumb IP_MULTICAST_TTL to netstack.
PiperOrigin-RevId: 226993086
Change-Id: I71757f231436538081d494da32ca69f709bc71c7
2018-12-26 23:52:12 -08:00
Ian Gudger 0df0df35fc Stub out SO_OOBINLINE.
We don't explicitly support out-of-band data and treat it like normal in-band
data. This is equilivent to SO_OOBINLINE being enabled, so always report that
it is enabled.

PiperOrigin-RevId: 226572742
Change-Id: I4c30ccb83265e76c30dea631cbf86822e6ee1c1b
2018-12-21 19:46:55 -08:00
Nicolas Lacasse d2f8586a1f Kokoro: Build all packages as part of presubmit.
We now build all packages (including //test/...) with RBE as part of the Kokoro
presubmit.

The tests do not yet use RBE, because there are some failures. The Golang unit,
integration, and image tests still run locally.

The syscall test suite needs even more work to make it pass on RBE. Those will
be enabled in follow-up CLs. They currently are not enabled at all on Kokoro.

PiperOrigin-RevId: 226562208
Change-Id: Idd2b81b3e8f07bf300c77e68990493ba97d16e23
2018-12-21 17:13:34 -08:00
Andrei Vagin 89b18f7108 Remove gunit_no_heapcheck from deps
heapcheck works fine now.

PiperOrigin-RevId: 226552252
Change-Id: Ifcf17a377b3d6512a576f54462dd81c1d4c7b17c
2018-12-21 15:40:08 -08:00
Ian Gudger b515556519 Implement SO_KEEPALIVE, TCP_KEEPIDLE, and TCP_KEEPINTVL.
Within gVisor, plumb new socket options to netstack.

Within netstack, fix GetSockOpt and SetSockOpt return value logic.

PiperOrigin-RevId: 226532229
Change-Id: If40734e119eed633335f40b4c26facbebc791c74
2018-12-21 13:13:45 -08:00
Michael Pratt 0e9b324856 Fix test util tests
We actually need to include test main!

PiperOrigin-RevId: 226524447
Change-Id: I9d9e631611183c7c1fbae1c20a222c9aeef269b2
2018-12-21 12:15:21 -08:00
Fabricio Voznika 1679ef31ef inotify notifies watchers when control events bit are set
The code that matches the event being published with events watchers
was wronly matching all watchers in case any of the control event bits
were set.

Issue #121

PiperOrigin-RevId: 226521230
Change-Id: Ie2c42bc4366faaf59fbf80a74e9297499bd93f9e
2018-12-21 11:54:02 -08:00
Jamie Liu 9a442fa4b5 Automated rollback of changelist 226224230
PiperOrigin-RevId: 226493053
Change-Id: Ia98d1cb6dd0682049e4d907ef69619831de5c34a
2018-12-21 08:23:34 -08:00
Ian Gudger f6274804e1 Make read and write respect SO_RCVTIMEO and SO_SNDTIMEO
PiperOrigin-RevId: 226387521
Change-Id: I0579ab262320fde6c72d2994dd38437f01a99ea5
2018-12-20 13:48:52 -08:00
Zhaozhong Ni 25d62850ce test: deflake socket_inet_loopback.
PiperOrigin-RevId: 226350590
Change-Id: Idff080705f644f8f78ce92b53c77eecc37e002e7
2018-12-20 09:52:27 -08:00
Googler 86c9bd2547 Automated rollback of changelist 225861605
PiperOrigin-RevId: 226224230
Change-Id: Id24c7d3733722fd41d5fe74ef64e0ce8c68f0b12
2018-12-19 13:30:08 -08:00
Zach Koopmans ff7178a4d1 Implement pwritev2.
Implement pwritev2 and associated unit tests.
Clean up preadv2 unit tests.
Tag RWF_ flags in both preadv2 and pwritev2 with associated bug tickets.

PiperOrigin-RevId: 226222119
Change-Id: Ieb22672418812894ba114bbc88e67f1dd50de620
2018-12-19 13:16:06 -08:00
Jamie Liu 0759f3afee Allow PosixErrorOr<T> to be implicitly constructible from copyable T.
PiperOrigin-RevId: 226037787
Change-Id: I5fb5f55f68b67dd86bbff46349b46e3e8e6b9d1b
2018-12-18 12:16:25 -08:00
Googler 41903586fd Deflake socket tests
PiperOrigin-RevId: 226029237
Change-Id: I6fcdb241d635468beb6d6c173f2e7f96d715bf26
2018-12-18 11:27:36 -08:00
Fabricio Voznika 03226cd950 Add BPFAction type with Stringer
PiperOrigin-RevId: 226018694
Change-Id: I98965e26fe565f37e98e5df5f997363ab273c91b
2018-12-18 10:28:28 -08:00
Jamie Liu e7b47844d9 Correctly handle filenames containing spaces in ParseProcMapsLine.
PiperOrigin-RevId: 225992500
Change-Id: Icc8b1675f1cb625fc5e8ef7389beb42fa7bfaa13
2018-12-18 07:23:53 -08:00
Ian Gudger 12c7430a01 Fix recv blocking for connectionless Unix sockets.
Connectionless Unix sockets (DGRAM Unix sockets created with the socket system
call) inherently only have a read queue. They do not establish bidirectional
connections, instead, the connect system call only sets a default send
location. Writes give the data to the other endpoint which has its own read
queue.

To simplify the code, connectionless Unix sockets still get read and write
queues, but the write queue is a dummy and never waited on. The read queue is
the connectionless endpoint's queue. This change fixes a bug where the dummy
queue was incorrectly set as the read queue and the endpoint's queue was
incorrectly set as the write queue. This meant that read notifications went
to the dummy queue and were black holed.

PiperOrigin-RevId: 225921042
Change-Id: I8d9059def787a2c3c305185b92d05093fbd2be2a
2018-12-17 17:53:22 -08:00
Rahat Mahmood e9c4f69f36 Enable recently-fixed test case for shm_test.
PiperOrigin-RevId: 225887356
Change-Id: Iee000dcfc9e0168c2566edf41c66108be9b68cd6
2018-12-17 14:12:24 -08:00
Jamie Liu 2421006426 Implement mlock(), kind of.
Currently mlock() and friends do nothing whatsoever. However, mlocking
is directly application-visible in a number of ways; for example,
madvise(MADV_DONTNEED) and msync(MS_INVALIDATE) both fail on mlocked
regions. We handle this inconsistently: MADV_DONTNEED is too important
to not work, but MS_INVALIDATE is rejected.

Change MM to track mlocked regions in a manner consistent with Linux.
It still will not actually pin pages into host physical memory, but:

- mlock() will now cause sentry memory management to precommit mlocked
pages.

- MADV_DONTNEED and MS_INVALIDATE will interact with mlocked pages as
described above.

PiperOrigin-RevId: 225861605
Change-Id: Iee187204979ac9a4d15d0e037c152c0902c8d0ee
2018-12-17 11:38:59 -08:00
Ian Gudger f74eed464b Add blocking recv tests
PiperOrigin-RevId: 225646045
Change-Id: Ic712ebc627587ef4a9486f0b39fe8c96100f10ff
2018-12-14 22:11:26 -08:00
Ian Gudger e1dcf92ec5 Implement SO_SNDTIMEO
PiperOrigin-RevId: 225620490
Change-Id: Ia726107b3f58093a5f881634f90b071b32d2c269
2018-12-14 16:15:06 -08:00
Nicolas Lacasse cd1e9a3fd4 Shard the syscall tests.
PiperOrigin-RevId: 225574278
Change-Id: If5060a37e8a9b0120bec2b5de4037354f0eaba16
2018-12-14 11:25:36 -08:00
Nicolas Lacasse 8f18b69cb1 Remove unused variable.
PiperOrigin-RevId: 225455503
Change-Id: I327fc6e7ba26532b628f343dece3bd9fc4d3b524
2018-12-13 16:21:41 -08:00
Rahat Mahmood a0c8aeb73d Clean up shm segments created by shm_test.
This test suite was creating shm segments without ensuring they were
cleaned up. Shm segments outlive the process creating them, so on a
standard linux machine the test was leaving segments behind after each
run. This would often cause failures as test cases would be affected
by the cases that ran before them and left unexpected segments lying
around.

Also skip some assertions around memory usage when running on a Linux
host, as we can't reason about external users of shm segments.

PiperOrigin-RevId: 225435523
Change-Id: Ia299dacf59045002436f5e30dcc131f679bb7272
2018-12-13 14:24:51 -08:00
Ian Gudger 4659f7ed1a Fix WAITALL and RCVTIMEO interaction
PiperOrigin-RevId: 225424296
Change-Id: I60fcc2b859339dca9963cb32227a287e719ab765
2018-12-13 13:20:46 -08:00
Ian Gudger f484b6d4c2 Flush socket test description
This ensures that we know what type of socket caused a timeout.

PiperOrigin-RevId: 225294255
Change-Id: I9033bd0f3791d3b5714aa08d111cf58a3014d252
2018-12-12 18:41:14 -08:00
Jamie Liu a2c868a098 Add rvalue ref-qualified PosixErrorOr<T>::ValueOrDie() overloads.
This allows ValueOrDie() to be called on PosixErrorOr rvalues (e.g.
temporaries) holding move-only types without extraneous std::move()s.

PiperOrigin-RevId: 225098036
Change-Id: I662862e4f3562141f941845fc6e197edb27ce29b
2018-12-11 17:05:53 -08:00
Michael Pratt 437f567ff7 Fix README typos
PiperOrigin-RevId: 225054712
Change-Id: I26e8bc3ef04fe96a4640e50ba4b635d4aa72cc50
2018-12-11 12:57:09 -08:00
Christopher Koch cbe3c20e4e Fix typo.
PiperOrigin-RevId: 225046313
Change-Id: I95fe9c353a5bec13e6ad99094b7741a0e160e4d0
2018-12-11 12:06:14 -08:00
Michael Pratt 77a443269a Fix test tag argument typo
The argument is --test_tag_filters, not --test_tag_filter.

Also switch to ... instead of :*, as it doesn't require special shell
quoting to avoid * expansion.

PiperOrigin-RevId: 224949618
Change-Id: I45dd6acbaeae29f2cc0baa977b086b5c037c6a88
2018-12-10 23:59:18 -08:00
Ian Gudger 5d87d8865f Implement MSG_WAITALL
MSG_WAITALL requests that recv family calls do not perform short reads. It only
has an effect for SOCK_STREAM sockets, other types ignore it.

PiperOrigin-RevId: 224918540
Change-Id: Id97fbf972f1f7cbd4e08eec0138f8cbdf1c94fe7
2018-12-10 17:56:34 -08:00
Brian Geffon d3bc79bc84 Open source system call tests.
PiperOrigin-RevId: 224886231
Change-Id: I0fccb4d994601739d8b16b1d4e6b31f40297fb22
2018-12-10 14:42:34 -08:00