Commit Graph

447 Commits

Author SHA1 Message Date
Bhasker Hariharan a611fdaee3 Changes TCP packet dispatch to use a pool of goroutines.
All inbound segments for connections in ESTABLISHED state are delivered to the
endpoint's queue but for every segment delivered we also queue the endpoint for
processing to a selected processor. This ensures that when there are a large
number of connections in ESTABLISHED state the inbound packets are all handled
by a small number of goroutines and significantly reduces the amount of work the
goscheduler has to perform.

We let connections in other states follow the current path where the
endpoint's goroutine directly handles the segments.

Updates #231

PiperOrigin-RevId: 289728325
2020-01-14 14:15:50 -08:00
Tamir Duberstein 50625cee59 Implement {g,s}etsockopt(IP_RECVTOS) for UDP sockets
PiperOrigin-RevId: 289718534
2020-01-14 13:33:23 -08:00
Tamir Duberstein debd213da6 Allow dual stack sockets to operate on AF_INET
Fixes #1490
Fixes #1495

PiperOrigin-RevId: 289523250
2020-01-13 14:47:22 -08:00
Andrei Vagin f54b9c0ee6 tests: fix errors detected by asan.
PiperOrigin-RevId: 289467083
2020-01-13 10:16:07 -08:00
Brad Burlage bf6429b944 Don't set RWF_HIPRI on InvalidOffset test.
This test fails on ubuntu 18.04 because preadv2 for some reason returns
EOPNOTSUPP instead of EINVAL. Instead of root-causing the failure, I'm dropping
the flag in the preadv2 call since it isn't under test in this scenario.

PiperOrigin-RevId: 289188358
2020-01-10 16:36:34 -08:00
Bhasker Hariharan 356d81146b Deflake a couple of TCP syscall tests when run under gotsan.
PiperOrigin-RevId: 289010316
2020-01-09 17:58:48 -08:00
Ian Lewis fbb2c008e2 Return correct length with MSG_TRUNC for unix sockets.
This change calls a new Truncate method on the EndpointReader in RecvMsg for
both netlink and unix sockets.  This allows readers such as sockets to peek at
the length of data without actually reading it to a buffer.

Fixes #993 #1240

PiperOrigin-RevId: 288800167
2020-01-08 17:24:05 -08:00
Ting-Yu Wang b3ae8a62cf Fix slice bounds out of range panic in parsing socket control message.
Panic found by syzakller.

PiperOrigin-RevId: 288799046
2020-01-08 16:32:34 -08:00
Tamir Duberstein d01240d871 Take addresses as const
PiperOrigin-RevId: 288767927
2020-01-08 13:54:19 -08:00
Andrei Vagin a53ac7307a fs/splice: don't report a partialResult error if there is no data loss
PiperOrigin-RevId: 288642552
2020-01-07 23:54:14 -08:00
Adin Scannell e77ad57423 Fix partial_bad_buffer write tests.
The write tests are fitted to Linux-specific behavior, but it is not
well-specified. Tweak the tests to allow for both acceptable outcomes.

PiperOrigin-RevId: 288606386
2020-01-07 17:26:42 -08:00
Kevin Krakauer ed60bc326b Fix readme formatting.
PiperOrigin-RevId: 288402480
2020-01-06 16:49:34 -08:00
gVisor bot 87e4d03fdf Automated rollback of changelist 287029703
PiperOrigin-RevId: 287217899
2019-12-26 13:05:52 -08:00
Ryan Heacock e013c48c78 Enable IP_RECVTOS socket option for datagram sockets
Added the ability to get/set the IP_RECVTOS socket option on UDP endpoints. If
enabled, TOS from the incoming Network Header passed as ancillary data in the
ControlMessages.

Test:
* Added unit test to udp_test.go that tests getting/setting as well as
verifying that we receive expected TOS from incoming packet.
* Added a syscall test
PiperOrigin-RevId: 287029703
2019-12-24 08:49:39 -08:00
Andrei Vagin 29955a4797 futex: wake one waiter if futex_wake is called with a non-positive value
This change is needed to be compatible with the Linux kernel.

There is no glibc wrapper for the futex system call, so it is easy to
make a mistake and call syscall(__NR_futex, FUTEX_WAKE, addr) without
the fourth argument. This works on Linux, because it wakes one waiter
even if val is nonpositive.

PiperOrigin-RevId: 286494396
2019-12-19 17:26:44 -08:00
Dean Deng 7419e0e5d7 Parameterize mmap tests.
This test suite has existed for quite a while and has become kind of messy.
Various tests can be joined together by parameterizing.

PiperOrigin-RevId: 286482240
2019-12-19 16:07:04 -08:00
Andrei Vagin 57ce26c0b4 net/tcp: allow to call listen without bind
When listen(2) is called on an unbound socket, the socket is
automatically bound to a random free port with the local address
set to INADDR_ANY.

PiperOrigin-RevId: 286305906
2019-12-18 18:24:17 -08:00
Jay Zhuang 18d6e59b45 Switch to netinet/tcp.h and poll.h to for better platform portability.
PiperOrigin-RevId: 286249699
2019-12-18 13:58:38 -08:00
Jay Zhuang 65f53c5833 Put GetSocketPairs() in unnamed namespace
This avoids conflicting definitions of GetSocketPairs() in outer namespace when
multiple such cc files are complied for one binary.

PiperOrigin-RevId: 286243045
2019-12-18 12:50:04 -08:00
Kevin Krakauer 64d00cc63d Internal change.
PiperOrigin-RevId: 286083614
2019-12-17 16:21:48 -08:00
gVisor bot 3f4d8fefb4 Internal change.
PiperOrigin-RevId: 286003946
2019-12-17 10:10:06 -08:00
gVisor bot 67000b929b Explicitly export files needed by other packages
PiperOrigin-RevId: 285968611
2019-12-17 06:33:08 -08:00
Dean Deng e6f4124afd Implement checks for get/setxattr at the syscall layer.
Add checks for input arguments, file type, permissions, etc. that match
the Linux implementation. A call to get/setxattr that passes all the
checks will still currently return EOPNOTSUPP. Actual support will be
added in following commits.

Only allow user.* extended attributes for the time being.

PiperOrigin-RevId: 285835159
2019-12-16 13:20:07 -08:00
Kevin Krakauer be2754a4b9 Add iptables testing framework.
It would be preferrable to test iptables via syscall tests, but there are some
problems with that approach:

* We're limited to loopback-only, as syscall tests involve only a single
  container. Other link interfaces (e.g. fdbased) should be tested.
* We'd have to shell out to call iptables anyways, as the iptables syscall
  interface itself is too large and complex to work with alone.
* Running the Linux/native version of the syscall test will require root, which
  is a pain to configure, is inherently unsafe, and could leave host iptables
  misconfigured.

Using the go_test target allows there to be no new test runner.

PiperOrigin-RevId: 285274275
2019-12-12 14:42:11 -08:00
Andrei Vagin 378d6c1f36 unix: allow to bind unix sockets only to AF_UNIX addresses
Reported-by: syzbot+2c0bcfd87fb4e8b7b009@syzkaller.appspotmail.com
PiperOrigin-RevId: 285228312
2019-12-12 11:08:56 -08:00
Bhasker Hariharan 6fc9f0aefd Add support for TCP_USER_TIMEOUT option.
The implementation follows the linux behavior where specifying
a TCP_USER_TIMEOUT will cause the resend timer to honor the
user specified timeout rather than the default rto based timeout.

Further it alters when connections are timedout due to keepalive
failures. It does not alter the behavior of when keepalives are
sent. This is as per the linux behavior.

PiperOrigin-RevId: 285099795
2019-12-11 17:52:53 -08:00
Dean Deng 1601e78a52 Add syscall tests for getxattr and setxattr.
Support for getxattr and setxattr are in subsequent commits.

PiperOrigin-RevId: 285088817
2019-12-11 16:41:17 -08:00
Dean Deng 769e1cdcbe Re-enable execveat test that was causing files in /bin to be deleted.
Test now no longer deletes files incorrectly, due to a fix in fs utils
used by TempPath (github.com/google/gvisor/pull/1368).

Fixes #1366

PiperOrigin-RevId: 284814605
2019-12-10 11:42:03 -08:00
Dean Deng f47eaffd5c Do not consider symlinks as directories in fs utils.
IsDirectory() is used in RecursivelyDelete(), which should not follow symlinks.
The only other use (syscalls/linux/rename.cc) is not affected by this change.

Updates #1366.

PiperOrigin-RevId: 284803968
2019-12-10 11:09:44 -08:00
Dean Deng aadbf322c6 Disable execveat test that is causing files in /bin to be deleted.
Disable until gvisor.dev/issue/1366 is resolved.

Updates #1366

PiperOrigin-RevId: 284786895
2019-12-10 09:41:07 -08:00
Dean Deng 4a19ebd431 Add hostinet tests for sendmsg and recvmsg with TOS/TCLASS.
PiperOrigin-RevId: 284786069
2019-12-10 09:34:38 -08:00
Ian Gudger 98aafb1334 Add test for SO_BINDTODEVICE state bug.
This was accidentally dropped from the change which fixed the bug.

Updates #1217

PiperOrigin-RevId: 284689362
2019-12-09 20:09:23 -08:00
Ian Gudger 18af75db9d Add UDP SO_REUSEADDR support to the port manager.
Next steps include adding support to the transport demuxer and the UDP endpoint.

PiperOrigin-RevId: 284652151
2019-12-09 15:53:00 -08:00
Jay Zhuang 17867c88f7 Include <netinet/tcp.h> for TCP enums in proc_net tests
These are currently duplicated in ip_socket_test_util, so tests including
both netinet/tcp.h and ip_socket_test_util won't compile.

PiperOrigin-RevId: 284623958
2019-12-09 13:37:32 -08:00
Bhasker Hariharan cb5f9b8f86 Mark test as non flaky.
PiperOrigin-RevId: 284606133
2019-12-09 12:04:51 -08:00
Michael Pratt 498595d543 Add tests for rseq(2)
Add a decent set of syscall tests for rseq(2). These are a bit awkward because
of issues with library integration. libc may register rseq on thread start
(including before main on the initial thread), precluding much testing. Thus we
run tests in a libc-free subprocess.

Support for rseq(2) in gVisor will come in a later commit.

PiperOrigin-RevId: 284595994
2019-12-09 11:22:31 -08:00
Dean Deng b0066217ec Add hostinet tests for UDP sockets.
We need to skip a subset of the tests, because of features that hostinet does
not currently support.

Fixes #1209

PiperOrigin-RevId: 284235911
2019-12-06 12:14:23 -08:00
Ian Gudger 13f0f6069a Implement F_GETOWN_EX and F_SETOWN_EX.
Some versions of glibc will convert F_GETOWN fcntl(2) calls into F_GETOWN_EX in
some cases.

PiperOrigin-RevId: 284089373
2019-12-05 17:28:52 -08:00
Bhasker Hariharan f053c52812 Reduce flakiness under gotsan runs.
TcpPortReuseMultiThread creates lots of connections which result in
a lot of goroutines in the sentry. This can cause gotsan runs to
take really long and timeout. Increasing listen backlog and
reducing number of connections should help the connections complete
faster as well as reduce the number of goroutines that gotsan needs
to track.

PiperOrigin-RevId: 284046018
2019-12-05 13:57:08 -08:00
Zach Koopmans 0a32c02357 Create correct file for /proc/[pid]/task/[tid]/io
PiperOrigin-RevId: 284038840
2019-12-05 13:24:05 -08:00
gVisor bot 05758f34b2 Explicitly export files needed by other packages
PiperOrigin-RevId: 283955946
2019-12-05 05:45:09 -08:00
Dean Deng 6ae64d7935 Allow syscall tests to run with hostinet.
Fixes #1207

PiperOrigin-RevId: 283914438
2019-12-04 23:45:49 -08:00
Dean Deng 80b7ba0c97 Clean up readv_socket test suite.
Get rid of the SocketTest class, which is only extended by ReadvSocketTest.
Also, get rid of TCP sockets (which were unused anyway) from readv_socket.cc.
This is a very old test suite that isn't the right place for TCP loopback
tests.

PiperOrigin-RevId: 283672772
2019-12-03 19:42:20 -08:00
Fabricio Voznika bb641c5403 Point TODO to gvisor.dev
PiperOrigin-RevId: 283657725
2019-12-03 17:33:50 -08:00
Andrei Vagin cf7f27c167 net/udp: return a local route address as the bound-to address
If the socket is bound to ANY and connected to a loopback address,
getsockname() has to return the loopback address. Without this fix,
getsockname() returns ANY.

PiperOrigin-RevId: 283647781
2019-12-03 16:32:13 -08:00
Bhasker Hariharan 27e2c4ddca Fix panic due to early transition to Closed.
The code in rcv.consumeSegment incorrectly transitions to
CLOSED state from LAST-ACK before the final ACK for the FIN.

Further if receiving a segment changes a socket to a closed state
then we should not invoke the sender as the socket is now closed
and sending any segments is incorrect.

PiperOrigin-RevId: 283625300
2019-12-03 14:41:55 -08:00
Andrei Vagin 43643752f0 strace: don't create a slice with a negative value
PiperOrigin-RevId: 283613824
2019-12-03 13:49:38 -08:00
Michael Pratt d7cc2480cb Add RunfilesPath to test_util
A few tests have their own ad-hoc implementations. Add a single common one.

PiperOrigin-RevId: 283601666
2019-12-03 12:47:03 -08:00
Andrei Vagin b41277049c test/syscal: Don't skip ClockGettime.CputimeId
We skipped it due to the issue in the golang scheduler
which has been fixed in go1.13.

PiperOrigin-RevId: 283432226
2019-12-02 15:37:17 -08:00
Jay Zhuang 1518f7fd38 Fix typo, s/Convertable/Convertible/g
PiperOrigin-RevId: 283345791
2019-12-02 08:33:43 -08:00