Commit Graph

810 Commits

Author SHA1 Message Date
Mithun Iyer 326394b79a 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 Wang e5f58e89bb 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
gVisor bot 7420821a7b Merge pull request #5767 from avagin:mxcsr
PiperOrigin-RevId: 367730917
2021-04-09 17:15:06 -07:00
Mithun Iyer dc8f6c6914 Move maxListenBacklog check to sentry
Move maxListenBacklog check to the caller of endpoint Listen so that it
is applicable to Unix domain sockets as well.
This was changed in cl/366935921.

Reported-by: syzbot+a35ae7cdfdde0c41cf7a@syzkaller.appspotmail.com
PiperOrigin-RevId: 367728052
2021-04-09 16:53:33 -07:00
Mithun Iyer 56c69fb0e7 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
Rahat Mahmood 7a7fcf2dba Report task CPU usage through the cpuacct cgroup controller.
PiperOrigin-RevId: 366923274
2021-04-05 19:46:26 -07:00
Chong Cai 63340e6138 Add initial verity ioctl syscall tests
PiperOrigin-RevId: 366907152
2021-04-05 17:31:48 -07:00
Kevin Krakauer e7b2023647 deflake semaphore test
There's no reason to actually increment the semaphore, it just introduces the
chance of a race.

PiperOrigin-RevId: 366851795
2021-04-05 12:37:31 -07:00
Chong Cai e21a71bff1 Allow user mount for verity fs
Allow user mounting a verity fs on an existing mount by specifying mount
flags root_hash and lower_path.

PiperOrigin-RevId: 366843846
2021-04-05 12:01:44 -07:00
Rahat Mahmood 932c8abd0f Implement cgroupfs.
A skeleton implementation of cgroupfs. It supports trivial cpu and
memory controllers with no support for hierarchies.

PiperOrigin-RevId: 366561126
2021-04-02 21:10:44 -07:00
Adin Scannell 513de4039c Remove invalid dependency.
PiperOrigin-RevId: 366344222
2021-04-01 15:34:56 -07:00
gVisor bot 6c10c772e4 Internal change.
PiperOrigin-RevId: 366292533
2021-04-01 11:24:04 -07:00
Kevin Krakauer 6b085ba477 setgid: skip tests when we can't find usable GIDs
PiperOrigin-RevId: 365092320
2021-03-25 12:00:24 -07:00
Bhasker Hariharan e7ca2a51a8 Add POLLRDNORM/POLLWRNORM support.
On Linux these are meant to be equivalent to POLLIN/POLLOUT. Rather
than hack these on in sys_poll etc it felt cleaner to just cleanup
the call sites to notify for both events. This is what linux does
as well.

Fixes #5544

PiperOrigin-RevId: 364859977
2021-03-24 12:11:44 -07:00
Kevin Krakauer 92374e5197 setgid directory support in goferfs
Also adds support for clearing the setuid bit when appropriate (writing,
truncating, changing size, changing UID, or changing GID).

VFS2 only.

PiperOrigin-RevId: 364661835
2021-03-23 15:42:12 -07:00
Fabricio Voznika 7fac7e32f3 Translate syserror when validating partial IO errors
syserror allows packages to register translators for errors. These
translators should be called prior to checking if the error is valid,
otherwise it may not account for possible errors that can be returned
from different packages, e.g. safecopy.BusError => syserror.EFAULT.

Second attempt, it passes tests now :-)

PiperOrigin-RevId: 363714508
2021-03-18 12:19:57 -07:00
Mithun Iyer 5eede4e756 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
Kevin Krakauer 607a1e481c setgid directory support in overlayfs
PiperOrigin-RevId: 363276495
2021-03-16 14:55:29 -07:00
Fabricio Voznika 34d0d72067 Deflake proc_test_native
Terminating tasks from other tests can mess up with the task
list of the current test. Tests were changed to look for added/removed
tasks, ignoring other tasks that may exist while the test is running.

PiperOrigin-RevId: 363084261
2021-03-15 19:06:03 -07:00
Nicolas Lacasse 6ef5bdab21 Allow reading from PTY into bad buffer to return EAGAIN.
Kernels after 3b830a9c return EAGAIN in this case.

PiperOrigin-RevId: 361936327
2021-03-09 17:37:54 -08:00
Kevin Krakauer abbdcebc54 Implement /proc/sys/net/ipv4/ip_local_port_range
Speeds up the socket stress tests by a couple orders of magnitude.

PiperOrigin-RevId: 361721050
2021-03-08 20:40:34 -08:00
Fabricio Voznika 3c4485966c Fix proc test flakiness
Thread from earlier test can show up in `/proc/self/tasks` while the
thread tears down. Account for that when searching for procs for the
first time in the test.

PiperOrigin-RevId: 361689673
2021-03-08 17:01:30 -08:00
Fabricio Voznika cabbbb373a 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
Andrei Vagin 865ca64ee8 tcp: endpoint.Write has to send all data that has been read from payload
io.Reader.ReadFull returns the number of bytes copied and an error if fewer
bytes were read.

PiperOrigin-RevId: 360247614
2021-03-01 12:17:20 -08:00
Jing Chen e50ee26207 Implement SEM_STAT_ANY cmd of semctl.
PiperOrigin-RevId: 359591577
2021-02-25 12:57:01 -08:00
Nicolas Lacasse f5692f7dcc Kernfs should not try to rename a file to itself.
One precondition of VFS.PrepareRenameAt is that the `from` and `to` dentries
are not the same. Kernfs was not checking this, which could lead to a deadlock.

PiperOrigin-RevId: 359385974
2021-02-24 15:39:32 -08:00
Dean Deng acd516cfe2 Add YAMA security module restrictions on ptrace(2).
Restrict ptrace(2) according to the default configurations of the YAMA security
module (mode 1), which is a common default among various Linux distributions.
The new access checks only permit the tracer to proceed if one of the following
conditions is met:

a) The tracer is already attached to the tracee.

b) The target is a descendant of the tracer.

c) The target has explicitly given permission to the tracer through the
PR_SET_PTRACER prctl.

d) The tracer has CAP_SYS_PTRACE.

See security/yama/yama_lsm.c for more details.

Note that these checks are added to CanTrace, which is checked for
PTRACE_ATTACH as well as some other operations, e.g., checking a process'
memory layout through /proc/[pid]/mem.

Since this patch adds restrictions to ptrace, it may break compatibility for
applications run by non-root users that, for instance, rely on being able to
trace processes that are not descended from the tracer (e.g., `gdb -p`). YAMA
restrictions can be turned off by setting /proc/sys/kernel/yama/ptrace_scope
to 0, or exceptions can be made on a per-process basis with the PR_SET_PTRACER
prctl.

Reported-by: syzbot+622822d8bca08c99e8c8@syzkaller.appspotmail.com
PiperOrigin-RevId: 359237723
2021-02-24 02:03:16 -08:00
Andrei Vagin c5a4e10008 unix: sendmmsg and recvmsg have to cap a number of message to UIO_MAXIOV
Reported-by: syzbot+f2489ba0b999a45d1ad1@syzkaller.appspotmail.com
PiperOrigin-RevId: 358866218
2021-02-22 11:51:30 -08:00
Bhasker Hariharan ec7f44f36b Make socketops reflect correct sndbuf value for host UDS.
Also skips a test if the setsockopt to increase send buffer did not result in an
increase. This is possible when the underlying socket is a host backed unix
domain socket as in such cases gVisor does not permit increasing SO_SNDBUF.

PiperOrigin-RevId: 358285158
2021-02-18 16:00:38 -08:00
Fabricio Voznika 582f7bf6c0 Remove side effect from pty tests
Individual test cases must not rely on being executed in a clean environment.

PiperOrigin-RevId: 358207468
2021-02-18 10:19:04 -08:00
Andrei Vagin a6d813ad55 tests: getsockname expects that addrlen will be initialized
PiperOrigin-RevId: 357224877
2021-02-12 10:58:17 -08:00
Jing Chen c833eed80a Implement semtimedop.
PiperOrigin-RevId: 357031904
2021-02-11 12:21:59 -08:00
Kevin Krakauer ae8d966f5a Assign controlling terminal when tty is opened and support NOCTTY
PiperOrigin-RevId: 357015186
2021-02-11 11:09:22 -08:00
Kevin Krakauer 81ea0016e6 Support setgid directories in tmpfs and kernfs
PiperOrigin-RevId: 356868412
2021-02-10 17:45:18 -08:00
Bhasker Hariharan 298c129cc1 Add support for setting SO_SNDBUF for unix domain sockets.
The limits for snd/rcv buffers for unix domain socket is controlled by the
following sysctls on linux

 - net.core.rmem_default
 - net.core.rmem_max
 - net.core.wmem_default
 - net.core.wmem_max

Today in gVisor we do not expose these sysctls but we do support setting the
equivalent in netstack via stack.Options() method. But AF_UNIX sockets in gVisor
can be used without netstack, with hostinet or even without any networking stack
at all. Which means ideally these sysctls need to live as globals in gVisor.

But rather than make this a big change for now we hardcode the limits in the
AF_UNIX implementation itself (which in itself is better than where we were
before) where it SO_SNDBUF was hardcoded to 16KiB. Further we bump the initial
limit to a default value of 208 KiB to match linux from the paltry 16 KiB we use
today.

Updates #5132

PiperOrigin-RevId: 356665498
2021-02-09 21:55:16 -08:00
Fabricio Voznika 0f84ea5afe Fix fd leak from test
PiperOrigin-RevId: 356587965
2021-02-09 14:12:53 -08:00
Andrei Vagin fe4f478960 kernel: reparentLocked has to update children maps of old and new parents
Reported-by: syzbot+9ffc71246fe72c73fc25@syzkaller.appspotmail.com
PiperOrigin-RevId: 356536113
2021-02-09 10:37:04 -08:00
Andrei Vagin d6dbe6e5ca pipe: writeLocked has to return ErrWouldBlock if the pipe is full
PiperOrigin-RevId: 356450303
2021-02-09 01:34:45 -08:00
Zeling Feng 95500ece56 Allow UDP sockets connect()ing to port 0
We previously return EINVAL when connecting to port 0, however this is not the
observed behavior on Linux. One of the observable effects after connecting to
port 0 on Linux is that getpeername() will fail with ENOTCONN.

PiperOrigin-RevId: 356413451
2021-02-08 20:13:17 -08:00
Andrei Vagin bf4968e17d exec: don't panic if an elf file is malformed
Reported-by: syzbot+d54bc27a15aefe52c330@syzkaller.appspotmail.com
PiperOrigin-RevId: 356406975
2021-02-08 19:18:03 -08:00
Ayush Ranjan 09afd68326 [vfs] Handle `.` and `..` as last path component names in kernfs Rename.
According to vfs.FilesystemImpl.RenameAt documentation:

- If the last path component in rp is "." or "..", and opts.Flags contains
  RENAME_NOREPLACE, RenameAt returns EEXIST.
- If the last path component in rp is "." or "..", and opts.Flags does not
  contain RENAME_NOREPLACE, RenameAt returns EBUSY.

Reported-by: syzbot+6189786e64fe13fe43f8@syzkaller.appspotmail.com
PiperOrigin-RevId: 355959266
2021-02-05 17:17:30 -08:00
Tamir Duberstein 0dbc112979 Compile-time constants are constexpr
PiperOrigin-RevId: 355506299
2021-02-03 16:21:37 -08:00
Bhasker Hariharan 8c7c5abafb Add support for rate limiting out of window ACKs.
Netstack today will send dupACK's with no rate limit for incoming out of
window segments. This can result in ACK loops for example if a TCP socket
connects to itself (actually permitted by TCP). Where the ACK sent in
response to packets being out of order itself gets considered as an out
of window segment resulting in another ACK being generated.

PiperOrigin-RevId: 355206877
2021-02-02 11:05:28 -08:00
Tamir Duberstein 00d21b9ae0 Assert TCP_INFO size before checking content
Also sync syscall test expectations on Fuchisa.

PiperOrigin-RevId: 355163492
2021-02-02 07:45:47 -08:00
Fabricio Voznika ccf9138e6d Remove side effect from open tests
Individual test cases must not rely on being executed in a clean environment.

PiperOrigin-RevId: 354730126
2021-01-30 13:38:05 -08:00
Kevin Krakauer 66aa6f3d4f setgid directory syscall tests
PiperOrigin-RevId: 354615220
2021-01-29 14:49:04 -08:00
Fabricio Voznika fdbfd447a0 Remove side effect from test cases
Individual test cases must not rely on being executed in a clean environment.

PiperOrigin-RevId: 354604389
2021-01-29 13:56:17 -08:00
Nayana Bidari 0a52b64794 - Add more comments for the TCP_INFO struct fields.
PiperOrigin-RevId: 354595623
2021-01-29 13:15:57 -08:00
Fabricio Voznika 9cc2570ea7 Change EXPECT/ASSERT to TEST_CHECK inside InForkedProcess
PiperOrigin-RevId: 354441239
2021-01-28 18:24:58 -08:00
gVisor bot d8c330254a Add O_PATH support in vfs2
PiperOrigin-RevId: 354367665
2021-01-28 12:24:37 -08:00