96 Commits
Author SHA1 Message Date
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
Peter JohnstonandgVisor bot eef88ab2ae Fix a race condition in TCPDeferAcceptTimeout
The test is timing-dependent and it's possible for it to sleep for
longer than the TCP_DEFER_ACCEPT timeout. We currently check if this
happened after sleeping and skip the test if so, but we call `accept`
_after_ this check, so the race still exists. Move the `accept` call to
before the check.

PiperOrigin-RevId: 650240216
2024-07-08 07:20:38 -07:00
Bruno Dal BoandgVisor bot aded0b7474 Avoid spurious timeout in AcceptedInheritsTCPUserTimeout
The purpose of the test is only to verify inheritance, but a tight timeout
may cause spurious failures.

PiperOrigin-RevId: 647060702
2024-06-26 13:35:05 -07:00
Zeling FengandgVisor bot 45a2dd4b4f Remove TcpAcceptBacklogSizes test
This test is not helpful because it tries to do connect and accept in
a loop. This will always succeed no matter what backlog is used (the
connection created will immediately be accepted, there is no backlog
at all). I think the actual test intention is already covered by the
TCPBacklog test. Removing this test so we don't spend unnecessary
time on a 1024 iteration loop that is bound to succeed.

PiperOrigin-RevId: 625139127
2024-04-15 17:45:52 -07:00
Peter JohnstonandgVisor bot cd366d0d76 Skip TCP_DEFER_ACCEPT test if we sleep for longer than timeout
FIXED: https://fxbug.dev/326254381
PiperOrigin-RevId: 615470990
2024-03-13 10:46:46 -07:00
Bruno Dal BoandgVisor bot f260aabff4 Poll indefinitely on Fuchsia
PiperOrigin-RevId: 603794823
2024-02-02 14:56:07 -08:00
Bruno Dal BoandgVisor bot 36f0b956f9 Use infinite timeout on Fuchsia
PiperOrigin-RevId: 602783304
2024-01-30 11:11:52 -08:00
Jeff MartinandgVisor bot a13af09e5d Test send_to() when the local/remote address families are mismatched.
Verify that for UDP sockets, `send_to()` returns the correct errno when
asked to send to a remote IP in a different address family than the
socket's bound address.

PiperOrigin-RevId: 586074458
2023-11-28 12:49:21 -08:00
Jeff MartinandgVisor bot d538b6f6a1 Use the protocol specified by the Test Parameter in dualstack socket tests
Correct a typo which hard-coded the protocol to UDP for the
`V4ListenerV6Connect` test.

PiperOrigin-RevId: 582347221
2023-11-14 09:31:25 -08:00
Jeff MartinandgVisor bot 5fdbcc5687 Add a syscall test exercising dualstack address family mismatches
Verify that the connect call returns the proper errno when asked to
connect to a remote IP in a different address family than the local IP.

PiperOrigin-RevId: 581919473
2023-11-13 04:51:33 -08:00
gVisor bot aaa9c4e5ce Internal change.
PiperOrigin-RevId: 567370524
2023-09-21 11:42:16 -07:00
Lucas ManningandgVisor bot 621c632afc A few fixes to run tests on 6.2+ kernels
* disable broken socket_inet_loopback test // Lucas Manning
* disable lseek tests on anon inodes. They have been broken by
commit e7478158e1378325907edfdd960eca98a1be405b
Date:   Wed Jun 29 15:06:57 2022 +0200
    fs: clear or set FMODE_LSEEK based on llseek function

* don't check memory.kmem.limit_in_bytes, it has been deprecated and dropped:
commit 86327e8eb94c52eca4f93cfece2e29d1bf52acbf
Date:   Tue Jul 4 13:52:40 2023 +0200
    memcg: drop kmem.limit_in_bytes
commit 58056f77502f3567b760c9a8fc8d2e9081515b2d
Date:   Fri Nov 5 13:37:44 2021 -0700
    memcg, kmem: further deprecate kmem.limit_in_bytes
commit 0158115f702b0ba208ab0b5adf44cae99b3ebcc7
Date:   Mon Sep 23 15:37:22 2019 -0700
    memcg, kmem: deprecate kmem.limit_in_bytes
PiperOrigin-RevId: 562915457
2023-09-05 15:51:21 -07:00
gVisor bot b4d5243dbc Merge pull request #7356 from turekt:pollrdhup-fix
PiperOrigin-RevId: 547867839
2023-07-13 11:39:30 -07:00
Nayana BidariandgVisor bot 920bee37b7 Test to check setting IPV6_V6ONLY on datagram socket with IPV4 address fails.
PiperOrigin-RevId: 546955039
2023-07-10 12:58:50 -07:00
turekt 355bb3b1f2 POLLRDHUP delivery fix
Fixes https://github.com/google/gvisor/issues/6015 | Added EventRdHUp to waiter events | Added POLLRDHUP delivery on half-closed connection detection | Added POLLRDHUP delivery on local read end shutdown
2023-07-09 15:53:24 +02:00
Tony GongandgVisor bot 09aea91fc9 Use infinite poll timeout on Fuchsia
Use infinite timeout when polling on the connecting/connected socket
after the listening socket is closed/shutdown on Fuchsia, as this
particular poll has been observed to be very flaky in Fuchsia Infra.

PiperOrigin-RevId: 546006387
2023-07-06 09:14:24 -07:00
Nayana BidariandgVisor bot 33bc37de55 Return error while calling shutdown on a bound unconnected UDP socket.
PiperOrigin-RevId: 542057418
2023-06-20 14:57:45 -07:00
Nicolas LacasseandgVisor bot e75ff4f68c Enable socket_inet_loopback test on hostinet.
A few minor fixes. The biggest change is that the blocking implementation needs
to wait on POLLHUP and POLLERR events, in addition to readable/writable events.
We also need to track shutdown state in the socket.

PiperOrigin-RevId: 529816115
2023-05-05 14:35:57 -07:00
Nicolas LacasseandgVisor bot 8ee4c3bae7 Automated rollback of changelist 525849045
PiperOrigin-RevId: 526120544
2023-04-21 13:26:08 -07:00
Nicolas LacasseandgVisor bot 66fe1d19e0 Enable socket_inet_loopback test on hostinet.
The blocking implementation needs to wait on POLLHUP and POLLERR events, in
addition to readable/writable events. That fixed at least one test.

There's still two unresolved issues in the tests, but we can enable the rest
of the suite while we figure out those two.

PiperOrigin-RevId: 525849045
2023-04-20 14:25:27 -07:00
Kevin KrakauerandgVisor bot d34d604ee0 tests: bump timeout to address flakiness
This test flakes on Linux in BuildKite -- see whether it's a timeout problem.

PiperOrigin-RevId: 506929923
2023-02-03 10:03:59 -08:00
Alex KonradiandgVisor bot b75b5a7997 Internal change.
PiperOrigin-RevId: 506921220
2023-02-03 09:24:46 -08:00
Nick BrownandgVisor bot cca29fd3a2 Reduce timeouts when polling
Fuchsia runs these tests against an in-development stack (Netstack3) that
doesn't yet support the full space of TCP actions. This means we wait for the
full timeout when a test is expected to fail; since these timeouts are 10
seconds, the suite runs for ~20 minutes. Reduce these timeouts to ~2s in hope
that it will be long enough to catch the desired events while reducing runtime
in Fuchsia's CQ.

PiperOrigin-RevId: 498015652
2022-12-27 12:37:34 -08:00
Derek MauroandgVisor bot 7480d7b79f Internal change.
PiperOrigin-RevId: 481202690
2022-10-14 12:11:32 -07:00
Andrei Vagin 61dd004b97 Move BindToDeviceReusePort to socket_inet_loopback_isolated
SO_BINDTODEVICE required CAP_NET_RAW beofre the 5.7 kernel. This was
fixed in the kernel by c427bfec18f2 ("net: core: enable SO_BINDTODEVICE
for non-root users").
2022-05-25 13:01:34 -07:00
gVisor bot cf9707c73f Add test for SO_REUSEPORT and SO_BINDTODEVICE together
Check that when two sockets are bound to the same device and have SO_REUSEPORT
set, they can both be bound to the same address. This test provides missing
coverage for when the two socket options are set together.

Bug: https://fxbug.dev/97822
PiperOrigin-RevId: 450053747
2022-05-20 13:41:35 -07:00
Andrei VaginandgVisor bot ca1012c047 tests: fix compile time warnings
test/syscalls/linux/futex.cc:
In member function 'virtual void gvisor::testing::
{anonymous}::PrivateAndSharedFutexTest_PIWaiters_Test::TestBody()':

test/syscalls/linux/futex.cc:697:19:
warning: comparison of integer expressions of different signedness:
'std::__atomic_base<int>::__int_type' {aka 'int'} and 'unsigned int'
[-Wsign-compare]

  697 |   while (a.load() != (FUTEX_WAITERS | gettid())) {
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/proc_pid_uid_gid_map.cc:207:64:
warning: comparison of integer expressions of different signedness: 'size_t'
{aka 'long unsigned int'} and 'int' [-Wsign-compare]

  207 |         TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
test/syscalls/linux/socket_inet_loopback.cc:964:21:
warning: comparison of integer expressions of different signedness: 'int' and
'std::array<gvisor::testing::FileDescriptor, 1>::size_type' {aka 'long
unsigned int'} [-Wsign-compare]

  964 |   for (int i = 0; i < std::size(established_clients); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/socket_inet_loopback.cc:974:21:
warning: comparison of integer expressions of different signedness: 'int' and
'std::array<gvisor::testing::FileDescriptor, 1>::size_type' {aka 'long
unsigned int'} [-Wsign-compare]

  974 |   for (int i = 0; i < std::size(waiting_clients); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/udp_socket.cc:869:6:
warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]

  869 |if (!IsRunningWithHostinet() || GvisorPlatform() == Platform::kPtrace ||
      |   ^

test/syscalls/linux/socket_unix_unbound_abstract.cc:93:9:
warning: variable 'orig_opts' set but not used [-Wunused-but-set-variable]

   93 |     int orig_opts;
      |         ^~~~~~~~~

test/syscalls/linux/socket_unix_unbound_abstract.cc:107:9:
warning: variable 'orig_opts' set but not used [-Wunused-but-set-variable]

  107 |     int orig_opts;
      |         ^~~~~~~~~

PiperOrigin-RevId: 445545240
2022-04-29 17:59:14 -07:00
Andrei VaginandgVisor bot 78612707cb Deflake the socket_inet_loopback test
Don't close sockets for writing otherwise sendto can fail with EPIPE.

PiperOrigin-RevId: 419751558
2022-01-04 22:45:56 -08:00
Kevin KrakauerandgVisor bot ac03283938 update bug number in loopback tests
PiperOrigin-RevId: 386511209
2021-07-23 12:47:23 -07:00
Ghanan GowripalanandgVisor bot 129cc47c63 Move socket_test_util to //test/util
...and rename the library to socket_util.

PiperOrigin-RevId: 386348306
2021-07-22 16:37:15 -07:00
Ayush RanjanandgVisor bot 26c5a8817e [op] Make TCPNonBlockingConnectClose more reasonable.
This test single handedly causes the syscalls:socket_inet_loopback_test test
variants to take more than an hour to run on some of our testing environments.

Reduce how aggressively this test tries to replicate a fixed flake. This is a
regression test.

PiperOrigin-RevId: 382849039
2021-07-02 18:47:48 -07:00
Etienne PerotandgVisor bot cdae8b8820 socket_inet_loopback: Split off tests that need isolation in their own file.
This allows these tests, which can cause flakiness when run in the same network
namespace as the other `socket_inet_loopback` tests, to run as separate tests
in their own environment. It also means that all of the shards of those tests
can be more isolated from each other as well.

PiperOrigin-RevId: 380930198
2021-06-22 17:53:37 -07:00
Kevin KrakauerandgVisor bot 9ee709d249 Deflake SocketInetLoopbackTest.TCPBacklog
The value can be off by one depending on the kernel we're running.

Tested with --runs_per_test=1000.

PiperOrigin-RevId: 379535390
2021-06-15 11:33:01 -07:00
Mithun IyerandgVisor bot 08afdfc323 Ensure full shutdown of endpoint on notifyClose
Address a race with non-blocking connect and socket close, causing the
FIN (because of socket close) to not be sent out, even after completing
the handshake.

The race occurs with this sequence:
(1) endpoint Connect starts handshake, sending out SYN
(2) handshake complete() releases endpoint lock, waiting on sleeper.Fetch()
(3) endpoint Close acquires endpoint lock, does not enqueue FIN (as the
    endpoint is not yet connected) and asserts notifyClose
(4) SYNACK from peer gets enqueued asserting newSegmentWaker
(5) handshake complete() re-aqcuires lock, first processes newSegmentWaker
    event, transitions to ESTABLISHED and proceeds to protocolMainLoop()
(6) protocolMainLoop() exits while processing notifyClose
When the execution follows the above sequence, no FIN is sent to the peer.
This causes the listener side to have a half-open connection sitting in
the accept queue.

Fix this by ensuring that the protocolMainLoop() performs clean shutdown
when the endpoint state is still ESTABLISHED.

This would not be a bug, if during handshake complete(), sleeper.Fetch()
prioritized notificationWaker over newSegmentWaker. In that case, the
handshake would not have completed in (5) above.

Fixes #6067

PiperOrigin-RevId: 376994395
2021-06-01 23:37:48 -07:00
Tamir DubersteinandgVisor bot 0603dc338c Expect POLLRDHUP on Fuchsia
PiperOrigin-RevId: 375749377
2021-05-25 11:14:23 -07:00
Mithun IyerandgVisor bot 6f5e12ccc0 Add protocol state to TCPINFO
Add missing protocol state to TCPINFO struct and update packetimpact.
This re-arranges the TCP state definitions to align with Linux.

Fixes #478

PiperOrigin-RevId: 374996751
2021-05-20 19:15:49 -07:00
Mithun IyerandgVisor bot 2e59bb1dd1 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
Adin ScannellandgVisor bot ce8ee943e7 Remove _NoRandomSave tests.
We do not currently run random save tests.

PiperOrigin-RevId: 368309921
2021-04-13 15:42:41 -07:00
Mithun IyerandgVisor bot 0e5ea0d716 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 WangandgVisor bot 3984f2238e 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
Mithun IyerandgVisor bot a85065cdb7 Fix listen backlog handling to be in parity with Linux
- Change the accept queue full condition for a listening endpoint
  to only honor completed (and delivered) connections.
- Use syncookies if the number of incomplete connections is beyond
  listen backlog. This also cleans up the SynThreshold option code
  as that is no longer used with this change.
- Added a new stack option to unconditionally generate syncookies.
  Similar to sysctl -w net.ipv4.tcp_syncookies=2 on Linux.
- Enable keeping of incomplete connections beyond listen backlog.
- Drop incoming SYNs only if the accept queue is filled up.
- Drop incoming ACKs that complete handshakes when accept queue is full
- Enable the stack to accept one more connection than programmed by
  listen backlog.
- Handle backlog argument being zero, negative for listen, as Linux.
- Add syscall and packetimpact tests to reflect the changes above.
- Remove TCPConnectBacklog test which is polling for completed
  connections on the client side which is not reflective of whether
  the accept queue is filled up by the test. The modified syscall test
  in this CL addresses testing of connecting sockets.

Fixes #3153

PiperOrigin-RevId: 366935921
2021-04-05 21:53:41 -07:00
Mithun IyerandgVisor bot 4a3b688372 Fix a race with synRcvdCount and accept
There is a race in handling new incoming connections on a listening
endpoint that causes the endpoint to reply to more incoming SYNs than
what is permitted by the listen backlog.

The race occurs when there is a successful passive connection handshake
and the synRcvdCount counter is decremented, followed by the endpoint
delivered to the accept queue. In the window of time between
synRcvdCount decrementing and the endpoint being enqueued for accept,
new incoming SYNs can be handled without honoring the listen backlog
value, as the backlog could be perceived not full.

Fixes #5637

PiperOrigin-RevId: 363279372
2021-03-16 15:08:09 -07:00
Fabricio VoznikaandgVisor bot e2039cb39a Fix SocketInetLoopbackTest flakiness
Remove part of test that was making it flaky. It runs for native only,
so not really important since it's not testing gVisor.

Before: http://sponge2/37557c41-298e-408d-9b54-50ba3d41e22f
After: http://sponge2/7bca72be-cb9b-42f8-8c54-af4956c39455
PiperOrigin-RevId: 361611512
2021-03-08 11:18:09 -08:00
Tamir DubersteinandgVisor bot f710a1f8de Compile-time constants are constexpr
PiperOrigin-RevId: 355506299
2021-02-03 16:21:37 -08:00
Ting-Yu WangandgVisor bot 8af803fc5b netstack: Refactor tcpip.Endpoint.Read
Read now takes a destination io.Writer, count, options. Keeping the method name
Read, in contrast to the Write method.

This enables:
* direct transfer of views under VV
* zero copy

It also eliminates the need for sentry to keep a slice of view because
userspace had requested a read that is smaller than the view returned, removing
the complexity there.

Read/Peek/ReadPacket are now consolidated together and some duplicate code is
removed.

PiperOrigin-RevId: 350636322
2021-01-07 14:17:18 -08:00
Fabricio VoznikaandgVisor bot 61acdaaaec Propagate IP address prefix from host to netstack
Closes #4022

PiperOrigin-RevId: 343378647
2020-11-19 15:11:17 -08:00
Bhasker HariharanandgVisor bot be3478ec65 Fix SO_ERROR behavior for TCP in gVisor.
Fixes the behaviour of SO_ERROR for tcp sockets where in linux it returns
sk->sk_err and if sk->sk_err is 0 then it returns sk->sk_soft_err. In gVisor TCP
we endpoint.HardError is the equivalent of sk->sk_err and endpoint.LastError
holds soft errors. This change brings this into alignment with Linux such that
both hard/soft errors are cleared when retrieved using getsockopt(.. SO_ERROR)
is called on a socket.

Fixes #3812

PiperOrigin-RevId: 342868552
2020-11-17 08:33:03 -08:00
Andrei VaginandgVisor bot 11ea6a3b43 Clean up the code of setupTimeWaitClose
The active_closefd has to be shutdown only for write,
otherwise the second poll will always return immediately.

The second poll should not be called from a separate thread.

PiperOrigin-RevId: 340319071
2020-11-02 14:42:03 -08:00
Bhasker HariharanandgVisor bot 93b9056478 Decrement e.synRcvdCount once handshake is complete.
Earlier the count was dropped only after calling e.deliverAccepted. This lead to
an issue where there were no connections in SYN-RCVD state for the listening
endpoint but e.synRcvdCount would not be zero because it was being reduced only
when handleSynSegment returned after deliverAccepted returned.

This issue is seen when the Nth SYN for a listen backlog of size N which would
cause the listen backlog to be full gets dropped occasionally. This happens when
the new SYN comes at when the previous completed endpoint has been delivered to
the accept queue but the synRcvdCount hasn't yet been decremented because the
goroutine running handleSynSegment has not yet completed.

PiperOrigin-RevId: 338690646
2020-10-23 09:43:09 -07:00
Nayana BidariandgVisor bot 4983a9002a Automated rollback of changelist 329526153
PiperOrigin-RevId: 332097286
2020-09-16 15:06:55 -07:00