Commit Graph

768 Commits

Author SHA1 Message Date
Bhasker Hariharan ae332d96e4 Fix TCP_LINGER2 behavior to match linux.
We still deviate a bit from linux in how long we will actually wait in
FIN-WAIT-2. Linux seems to cap it with TIME_WAIT_LEN and it's not completely
obvious as to why it's done that way. For now I think we can ignore that and
fix it if it really is an issue.

PiperOrigin-RevId: 328324922
2020-08-25 07:17:32 -07:00
Ghanan Gowripalan 339d266be4 Consider loopback bound to all addresses in subnet
When a loopback interface is configurd with an address and associated
subnet, the loopback should treat all addresses in that subnet as an
address it owns.

This is mimicking linux behaviour as seen below:
```
$ ip addr show dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group ...
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
$ ping 192.0.2.1
PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
^C
--- 192.0.2.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1018ms

$ ping 192.0.2.2
PING 192.0.2.2 (192.0.2.2) 56(84) bytes of data.
^C
--- 192.0.2.2 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2039ms

$ sudo ip addr add 192.0.2.1/24 dev lo
$ ip addr show dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group ...
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 192.0.2.1/24 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
$ ping 192.0.2.1
PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
64 bytes from 192.0.2.1: icmp_seq=1 ttl=64 time=0.131 ms
64 bytes from 192.0.2.1: icmp_seq=2 ttl=64 time=0.046 ms
64 bytes from 192.0.2.1: icmp_seq=3 ttl=64 time=0.048 ms
^C
--- 192.0.2.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2042ms
rtt min/avg/max/mdev = 0.046/0.075/0.131/0.039 ms
$ ping 192.0.2.2
PING 192.0.2.2 (192.0.2.2) 56(84) bytes of data.
64 bytes from 192.0.2.2: icmp_seq=1 ttl=64 time=0.131 ms
64 bytes from 192.0.2.2: icmp_seq=2 ttl=64 time=0.069 ms
64 bytes from 192.0.2.2: icmp_seq=3 ttl=64 time=0.049 ms
64 bytes from 192.0.2.2: icmp_seq=4 ttl=64 time=0.035 ms
^C
--- 192.0.2.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3049ms
rtt min/avg/max/mdev = 0.035/0.071/0.131/0.036 ms
```

Test: integration_test.TestLoopbackAcceptAllInSubnet
PiperOrigin-RevId: 328188546
2020-08-24 12:28:35 -07:00
Mithun Iyer 69008b68b0 Add syscall tests for SO_REUSEADDR.
Add tests for socket re-bind/listen of client and server sockets
with the older connection still in TIME_WAIT state and with
SO_REUSEADDR enabled.

PiperOrigin-RevId: 327924702
2020-08-21 22:49:16 -07:00
Ting-Yu Wang bd3383a7e2 Move udp port exhaustion tests to a 'nogotsan' one.
It frequently times out under GoTSAN.

PiperOrigin-RevId: 327894343
2020-08-21 16:34:50 -07:00
Zach Koopmans c9e752b644 Fix Inotify tests in open source.
The order of unlink events (dir event/file event) is undefined,
so make tests accept both orderings.

PiperOrigin-RevId: 327873316
2020-08-21 14:21:44 -07:00
Zach Koopmans c24db90be5 Skip ElfInterpreterStaticTest for 5.X kernels.
gVisor emulates 4.6 kernel versions, and test doesn't work on 5.0 versions
(observed on our Ubuntu18.04 image). Skip it.

PiperOrigin-RevId: 327845037
2020-08-21 11:39:04 -07:00
Nicolas Lacasse 0324b94a73 Skip socket stress tests on KVM platform.
They time out.

PiperOrigin-RevId: 327830892
2020-08-21 10:23:43 -07:00
Fabricio Voznika e8a25a2834 Enable strace+debug in syscall tests
This is done to ease troubleshooting when tests fail. runsc
logs are not stored when tests passe, so this will only
affect failing tests and should not increase log storage
too badly.

PiperOrigin-RevId: 327717551
2020-08-20 16:19:10 -07:00
Bhasker Hariharan f12b545d8f Skip listening TCP ports when trying to bind a free port.
PiperOrigin-RevId: 327686558
2020-08-20 13:25:23 -07:00
Zach Koopmans f8a9483002 Fix return for rseq_test.
Accept 128 + SIGNAL as well as SIGNAL as valid
returns for fork/exec tests.

Also, make changes so that test compiles in opensource. Test
had compile errors on latest Ubuntu 16.04 image with updated bazel to
3.4.0 (as well as base 2.0) used for Kokoro tests.

PiperOrigin-RevId: 327510310
2020-08-19 14:46:55 -07:00
Kevin Krakauer 5cf330106a ip6tables: test initial state
Tests that we have the correct initial (empty) state for ip6tables.

#3549

PiperOrigin-RevId: 327477657
2020-08-19 12:03:34 -07:00
Zach Koopmans 3331722291 Skip ECN test for native/linux tests.
Skip check for ECN bits in native/linux tests. General advice
for the ECN field is to leave the setting to the kernel, so
behavior of the test is undefined for different kernels.

http://www.masterraghu.com/subjects/np/introduction/unix_network_programming_v1.3/ch07lev1sec6.html

PiperOrigin-RevId: 327451414
2020-08-19 09:51:04 -07:00
Dean Deng 33c60b893f Return appropriate errors when file locking is unsuccessful.
test_eintr now passes in the Python runtime tests.

Updates #3515.

PiperOrigin-RevId: 327441081
2020-08-19 08:53:12 -07:00
Zach Koopmans f6d2490482 Fix return value in shm_test for opensource
Some machines return 128 + signal for failures. Accept that
as a valid result.

PiperOrigin-RevId: 327326113
2020-08-18 16:07:35 -07:00
Zach Koopmans 4141dc0d2c Fix timeval for Socket test
tv_usec field should be a multiple of 4K to pass
in open source on linux/native, so make it one.

PiperOrigin-RevId: 327288405
2020-08-18 12:56:44 -07:00
Zach Koopmans 673b6cc7fc Fix readahead test for opensource.
Skip InvalidOffset and InvalidLength for Linux as the test is invalid for
later Kernel versions.

Add UnsupportedFile test as this check is in all kernel versions.

PiperOrigin-RevId: 327248035
2020-08-18 10:02:27 -07:00
Zach Koopmans da5c2ea6dc Fix return value for MMap Tests in OpenSource
Some systems return 128 + errno instead of just errno, which is the case
here.

PiperOrigin-RevId: 327247836
2020-08-18 09:54:48 -07:00
Ian Lewis ac324f646e
Merge branch 'master' into ip-forwarding
- Merges aleksej-paschenko's with HEAD
- Adds vfs2 support for ip_forward
2020-08-17 21:44:31 -04:00
Zach Koopmans 988ab27058 Fix AllSocketPairTest for open source.
Setting timeouts for sockets on GCP images (debian) for usecs only
respects multiples of 4K. Set the test with a multiple of 4K with a comment.

PiperOrigin-RevId: 327093848
2020-08-17 14:04:20 -07:00
Ayush Ranjan e3e1b36896 [vfs] Do O_DIRECTORY check after resolving symlinks.
Fixes python runtime test test_glob.
Updates #3515

We were checking is the to-be-opened dentry is a dir or not before resolving
symlinks. We should check that after resolving symlinks.
This was preventing us from opening a symlink which pointed to a directory
with O_DIRECTORY.

Also added this check in tmpfs and removed a duplicate check.

PiperOrigin-RevId: 327085895
2020-08-17 13:26:31 -07:00
Zach Koopmans e6ea59203b Skip UDPMulticast Tests when net interfaces aren't found.
PiperOrigin-RevId: 326686761
2020-08-14 10:53:04 -07:00
Ayush Ranjan d6520e1d05 [vfs2][gofer] Fix file creation flags sent to gofer.
Fixes php runtime test ext/standard/tests/file/readfile_basic.phpt
Fixes #3516

fsgofers only want the access mode in the OpenFlags passed to Create(). If more
flags are supplied (like O_APPEND in this case), read/write from that fd will
fail with EBADF. See runsc/fsgofer/fsgofer.go:WriteAt()
VFS2 was providing more than just access modes. So filtering the flags using
p9.OpenFlagsModeMask == linux.O_ACCMODE fixes the issue.

Gofer in VFS1 also only extracts the access mode flags while making the create
RPC. See pkg/sentry/fs/gofer/path.go:Create()

Even in VFS2, when we open a handle, we extract out only the access mode flags
+ O_TRUNC.
See third_party/gvisor/pkg/sentry/fsimpl/gofer/handle.go:openHandle()

Added a test for this.

PiperOrigin-RevId: 326574829
2020-08-13 19:33:56 -07:00
Ayush Ranjan 5036f135e4 Disable vfs2 for socket_stress_test.
PiperOrigin-RevId: 326553620
2020-08-13 16:58:43 -07:00
Bhasker Hariharan b928d074b4 Ensure TCP TIME-WAIT is not terminated prematurely.
Netstack's TIME-WAIT state for a TCP socket could be terminated prematurely if
the socket entered TIME-WAIT using shutdown(..., SHUT_RDWR) and then was closed
using close(). This fixes that bug and updates the tests to verify that Netstack
correctly honors TIME-WAIT under such conditions.

Fixes #3106

PiperOrigin-RevId: 326456443
2020-08-13 09:04:31 -07:00
Ayush Ranjan 42b610d567 [vfs2][gofer] Return appropriate errors when opening and creating files.
Fixes php test ext/standard/tests/file/touch_variation5.phpt on vfs2.
Updates #3516

Also spotted a bug with O_EXCL, where we did not return EEXIST when we tried
to open the root of the filesystem with O_EXCL | O_CREAT.

Added some more tests for open() corner cases.

PiperOrigin-RevId: 326346863
2020-08-12 17:19:09 -07:00
Ghanan Gowripalan 0a8ae4b32f Populate IPPacketInfo with destination address
IPPacketInfo.DestinationAddr should hold the destination of the IP
packet, not the source. This change fixes that bug.

PiperOrigin-RevId: 325910766
2020-08-10 16:22:31 -07:00
Ayush Ranjan a1af46c20a Enable VFS2 by default for all syscall tests.
Fixes #2923

PiperOrigin-RevId: 325904734
2020-08-10 15:50:22 -07:00
Andrei Vagin 10c13bccaf tcp: change the limit of TCP_LINGER2
It was changed in the Linux kernel:

commit f0628c524fd188c3f9418e12478dfdfadacba815
Date:   Fri Apr 24 16:06:16 2020 +0800
net: Replace the limit of TCP_LINGER2 with TCP_FIN_TIMEOUT_MAX
PiperOrigin-RevId: 325493859
2020-08-07 13:10:29 -07:00
Jamie Liu 93cb66825b Support separate read/write handles in fsimpl/gofer.dentry.
PiperOrigin-RevId: 325490674
2020-08-07 12:56:12 -07:00
Jamie Liu 8c1573ebab Tolerate EINTR from fallocate() in inotify test.
PiperOrigin-RevId: 325472312
2020-08-07 11:26:20 -07:00
Nayana Bidari 35312a95c4 Add loss recovery option for TCP.
/proc/sys/net/ipv4/tcp_recovery is used to enable RACK loss
recovery in TCP.

PiperOrigin-RevId: 325157807
2020-08-05 20:50:06 -07:00
Dean Deng 1fbbc795ef Add inotify events for fallocate and tests for fallocate/sendfile.
Updates #1479, #2923.

PiperOrigin-RevId: 324658826
2020-08-03 12:36:14 -07:00
gVisor bot 07267fc4c0 Merge pull request #3469 from craig08:fuse-fix-test-mount-failed
PiperOrigin-RevId: 324657612
2020-08-03 12:27:03 -07:00
Craig Chi e76c3c1064 Fix MountFuseFilesystem tests failing
Before kernel version 4.16-rc6, fuse mount is protected by
capable(CAP_SYS_ADMIN). After this version, it uses
ns_capable(CAP_SYS_ADMIN) to protect. Before the 4.16 kernel,
it was not allowed to mount fuse file systems without the
global CAP_SYS_ADMIN.

Fixes #3360
2020-07-31 16:18:40 -07:00
Andrei Vagin fd5f4ffed1 test/socket_netlink_route: check that there is a route on local or main tables
A new network namespace has only the local route table.

PiperOrigin-RevId: 324303629
2020-07-31 16:14:06 -07:00
Kevin Krakauer 5d2b09b71d s/github.dev/gvisor.dev
PiperOrigin-RevId: 324249991
2020-07-31 11:40:12 -07:00
Dean Deng c43305731e Fix SETOWN_EX return value.
Return on success should be 0, not size of the struct copied out.

PiperOrigin-RevId: 324029193
2020-07-30 10:27:44 -07:00
Adin Scannell 84496b3a61 Disable consistently failing test.
PiperOrigin-RevId: 324017310
2020-07-30 09:25:58 -07:00
Jamie Liu 4cd4759238 Force registration for EPOLLHUP, not EPOLLRDHUP, in vfs2's epoll.
Compare Linux's fs/eventpoll.c:do_epoll_ctl(). I don't know where EPOLLRDHUP
came from.

PiperOrigin-RevId: 323874419
2020-07-29 14:57:48 -07:00
Fabricio Voznika f82dd8ddb4 Redirect TODO to GitHub issues
PiperOrigin-RevId: 323715260
2020-07-28 21:24:26 -07:00
Rahat Mahmood c8fa685cb6 Fix when FUSE tests need to be skipped due to sentry configuration.
PiperOrigin-RevId: 323426851
2020-07-27 13:26:23 -07:00
Ayush Ranjan 65b5e64802 Enable open test
Updates #2923

PiperOrigin-RevId: 322953552
2020-07-24 01:13:06 -07:00
Nicolas Lacasse 4ec3516332 Implement get/set_robust_list.
PiperOrigin-RevId: 322904430
2020-07-23 17:42:50 -07:00
gVisor bot 5e34ee68c9 Merge pull request #3024 from ridwanmsharif:ridwanmsharif/fuse-stub-impl
PiperOrigin-RevId: 322890087
2020-07-23 16:34:09 -07:00
Ridwan Sharif 3e0e3b9b11 Added stub FUSE filesystem
Allow FUSE filesystems to be mounted using libfuse.
The appropriate flags and mount options are parsed and
understood by fusefs.
2020-07-23 17:13:24 -04:00
gVisor bot 15da310efa Internal change.
PiperOrigin-RevId: 322859907
2020-07-23 13:58:42 -07:00
Bhasker Hariharan 20b556e625 Fix wildcard bind for raw socket.
Fixes #3334

PiperOrigin-RevId: 322846384
2020-07-23 12:54:12 -07:00
Nicolas Lacasse b396d3882c Port sendfile to vfs2.
And do some refactoring of the wait logic in sendfile/splice/tee.

Updates #1035 #2923

PiperOrigin-RevId: 322815521
2020-07-23 10:36:17 -07:00
Ayush Ranjan 39525d64cb Add O_APPEND support in vfs2 gofer.
Helps in fixing open syscall tests: AppendConcurrentWrite and AppendOnly.

We also now update the file size for seekable special files (regular files)
which we were not doing earlier.

Updates #2923

PiperOrigin-RevId: 322670843
2020-07-22 15:42:33 -07:00
Bhasker Hariharan 71bf90c55b Support for receiving outbound packets in AF_PACKET.
Updates #173

PiperOrigin-RevId: 322665518
2020-07-22 15:33:33 -07:00
Dean Deng 13c0cca50e Skip RawHDRINCL tests that are blocking presubmits/releases.
Temporarily skip these, on bhaskherh@'s advice.

PiperOrigin-RevId: 322664955
2020-07-22 15:13:03 -07:00
Bhasker Hariharan dcf6ddc277 Add support to return protocol in recvmsg for AF_PACKET.
Updates #173

PiperOrigin-RevId: 321690756
2020-07-16 18:40:32 -07:00
Bhasker Hariharan 857d03f258 Add support for SO_ERROR to packet sockets.
Packet sockets also seem to allow double binding and do not return an error on
linux. This was tested by running the syscall test in a linux namespace as root
and the current test DoubleBind fails@HEAD.

Passes after this change.

Updates #173

PiperOrigin-RevId: 321445137
2020-07-15 14:56:39 -07:00
Bhasker Hariharan fef90c61c6 Fix minor bugs in a couple of interface IOCTLs.
gVisor incorrectly returns the wrong ARP type for SIOGIFHWADDR. This breaks
tcpdump as it tries to interpret the packets incorrectly.

Similarly, SIOCETHTOOL is used by tcpdump to query interface properties which
fails with an EINVAL since we don't implement it. For now change it to return
EOPNOTSUPP to indicate that we don't support the query rather than return
EINVAL.

NOTE: ARPHRD types for link endpoints are distinct from NIC capabilities
and NIC flags. In Linux all 3 exist eg. ARPHRD types are stored in dev->type
field while NIC capabilities are more like the device features which can be
queried using SIOCETHTOOL but not modified and NIC Flags are fields that can
be modified from user space. eg. NIC status (UP/DOWN/MULTICAST/BROADCAST) etc.

Updates #2746

PiperOrigin-RevId: 321436525
2020-07-15 14:15:44 -07:00
gVisor bot 8939fae0af Merge pull request #3165 from ridwanmsharif:ridwanmsharif/fuse-off-by-default
PiperOrigin-RevId: 321411758
2020-07-15 12:14:42 -07:00
Bhasker Hariharan 216dcebc06 Stub out SO_DETACH_FILTER.
Updates #2746

PiperOrigin-RevId: 320757963
2020-07-11 06:22:47 -07:00
Bhasker Hariharan 5946f11182 Add support for IP_HDRINCL IP option for raw sockets.
Updates #2746
Fixes #3158

PiperOrigin-RevId: 320497190
2020-07-09 16:25:57 -07:00
Ridwan Sharif abffebde7b Gate FUSE behind a runsc flag
This change gates all FUSE commands (by gating /dev/fuse) behind a runsc
flag. In order to use FUSE commands, use the --fuse flag with the --vfs2
flag. Check if FUSE is enabled by running dmesg in the sandbox.
2020-07-09 02:01:29 -04:00
Jamie Liu 5e05950c1c Deflake exec test.
- Only use MAXSYMLINKS/2+1 symlinks for each of the interpreter and script
  paths in SymlinkLimitRefreshedForInterpreter to tolerate cases where the
  original paths (/tmp, /bin, or /bin/echo) themselves contain symlinks.

- Ensure that UnshareFiles performs execve immediately after clone(CLONE_VFORK)
  (no heap allocation for ExecveArray/RunfilesPath).

- Use lstat() rather than stat() for the existence check in fs_util's Exists;
  the latter will fail if the symlink target does not exist, even if the
  symlink does.

PiperOrigin-RevId: 320110156
2020-07-07 19:45:16 -07:00
Tony Gong 76c7bc51b7 Set IPv4 ID on all non-atomic datagrams
RFC 6864 imposes various restrictions on the uniqueness of the IPv4
Identification field for non-atomic datagrams, defined as an IP datagram that
either can be fragmented (DF=0) or is already a fragment (MF=1 or positive
fragment offset). In order to be compliant, the ID field is assigned for all
non-atomic datagrams.

Add a TCP unit test that induces retransmissions and checks that the IPv4
ID field is unique every time. Add basic handling of the IP_MTU_DISCOVER
socket option so that the option can be used to disable PMTU discovery,
effectively setting DF=0. Attempting to set the sockopt to anything other
than disabled will fail because PMTU discovery is currently not implemented,
and the default behavior matches that of disabled.

PiperOrigin-RevId: 320081842
2020-07-07 16:14:49 -07:00
Ayush Ranjan 10930189c3 Fix mknod and inotify syscall test
This change fixes a few things:
- creating sockets using mknod(2) is supported via vfs2
- fsgofer can create regular files via mknod(2)
- mode = 0 for mknod(2) will be interpreted as regular file in vfs2 as well

Updates #2923

PiperOrigin-RevId: 320074267
2020-07-07 15:35:01 -07:00
Bhasker Hariharan b0f656184e Add support for SO_RCVBUF/SO_SNDBUF for AF_PACKET sockets.
Updates #2746

PiperOrigin-RevId: 319887810
2020-07-06 17:22:54 -07:00
gVisor bot 47bffa544a Merge pull request #3110 from craig08:add-missing-ICRNL
PiperOrigin-RevId: 319827554
2020-07-06 12:08:03 -07:00
Dean Deng 6c099d8300 Update preadv2/pwritev2 flag handling in vfs2.
We do not support RWF_SYNC/RWF_DSYNC and probably shouldn't silently accept
them, since the user may incorrectly believe that we are synchronizing I/O.
Remove the pwritev2 test verifying that we support these flags.

gvisor.dev/issue/2601 is the tracking bug for deciding which RWF_.* flags
we need and supporting them.

Updates #2923, #2601.

PiperOrigin-RevId: 319351286
2020-07-01 22:04:42 -07:00
Ayush Ranjan 514955c1a8 [vfs2][gofer] Fix mmap syscall test.
We were not invalidating mappings when the file size changed in shared mode.
Enabled the syscall test for vfs2.

Updates #2923

PiperOrigin-RevId: 319346569
2020-07-01 21:05:53 -07:00
Dean Deng 65d9985558 Port vfs1 implementation of sync_file_range to vfs2.
Currently, we always perform a full-file sync which could be extremely
expensive for some applications. Although vfs1 did not fully support
sync_file_range, there were some optimizations that allowed us skip some
unnecessary write-outs.

Updates #2923, #1897.

PiperOrigin-RevId: 319324213
2020-07-01 17:11:26 -07:00
Dean Deng e4b2087602 Use directory fds in sticky test to avoid permission issues.
After we change credentials, it is possible that we no longer have access to
the sticky directory where we are trying to delete files. Use an open fd so
this is not an issue.

PiperOrigin-RevId: 319306255
2020-07-01 15:19:16 -07:00
Zach Koopmans 6a90c88b97 Port fallocate to VFS2.
PiperOrigin-RevId: 319283715
2020-07-01 13:14:44 -07:00
Dean Deng cda2979b63 Complete async signal delivery support in vfs2.
- Support FIOASYNC, FIO{SET,GET}OWN, SIOC{G,S}PGRP (refactor getting/setting
  owner in the process).
- Unset signal recipient when setting owner with pid == 0 and
  valid owner type.

Updates #2923.

PiperOrigin-RevId: 319231420
2020-07-01 08:42:12 -07:00
Dean Deng 44071cc7fa Remove struct packing to fix compiler warning.
-Waddress-of-packed-member warns on inet_aton() being used with a packed struct
member. This was added in cl/291990716.

PiperOrigin-RevId: 319111253
2020-06-30 15:29:19 -07:00
Dean Deng dce2dfae04 Add build target for the provisional style guide.
This includes the provisional style guide in the website and fixes the broken
link from CONTRIBUTING.md. The style guide will be located under the "Community"
category as it's related to contributing to the project.

Also, add missing includes that were causing some presubmits to fail.

PiperOrigin-RevId: 319061410
2020-06-30 11:25:55 -07:00
Craig Chi 09b7791e89 Add missing ICRNL flag in master termios test
Closes #2768
2020-06-30 09:31:28 -07:00
Zach Koopmans 5b0d8ff691 Refactor udp_socket_test
Bring udp_socket_test into complianc by:
- Eliminating IsRunningOnGvisor() invocations.
- Wrapping sockets in RAII FileDescriptor objects.
- Creating a Bind() method so that the first bind happens on port 0.

PiperOrigin-RevId: 318909396
2020-06-29 15:46:19 -07:00
Dean Deng e8f1a5c1f6 Port GETOWN, SETOWN fcntls to vfs2.
Also make some fixes to vfs1's F_SETOWN. The fcntl test now entirely passes
on vfs2.

Fixes #2920.

PiperOrigin-RevId: 318669529
2020-06-27 21:33:37 -07:00
Dean Deng 02d552d07c Support sticky bit in vfs2.
Updates #2923.

PiperOrigin-RevId: 318648128
2020-06-27 14:39:41 -07:00
Dean Deng 85be13d9a3 Add tests for eventfd/timerfd/inotify operations that should return ESPIPE.
PiperOrigin-RevId: 318585377
2020-06-26 19:42:27 -07:00
Kevin Krakauer 66d1665441 IPv6 raw sockets. Needed for ip6tables.
IPv6 raw sockets never include the IPv6 header.

PiperOrigin-RevId: 318582989
2020-06-26 19:07:02 -07:00
gVisor bot 8dbeac53ce Implement SO_NO_CHECK socket option.
SO_NO_CHECK is used to skip the UDP checksum generation on a TX socket
(UDP checksum is optional on IPv4).

Test:
 - TestNoChecksum
 - SoNoCheckOffByDefault (UdpSocketTest)
 - SoNoCheck (UdpSocketTest)

Fixes #3055

PiperOrigin-RevId: 318575215
2020-06-26 17:51:04 -07:00
Kevin Krakauer 9cfc154975 Require CAP_SYS_ADMIN in the root user namespace for TTY theft
PiperOrigin-RevId: 318563543
2020-06-26 16:24:39 -07:00
Dean Deng 54a31e219c Support inotify IN_ONESHOT.
Also, while we're here, make sure that gofer inotify events are generated when
files are created in remote revalidating mode.

Updates #1479.

PiperOrigin-RevId: 318536354
2020-06-26 13:47:48 -07:00
Ridwan Sharif 2828806fb0 Test that the fuse device can be opened 2020-06-25 15:46:30 -04:00
Ridwan Sharif a63db7d903 Moved FUSE device under the fuse directory 2020-06-25 14:22:21 -04:00
Ridwan Sharif bd5f0e2dc4 Add FUSE character device
This change adds a FUSE character device backed by devtmpfs. This
device will be used to establish a connection between the FUSE
server daemon and fusefs. The FileDescriptionImpl methods will
be implemented as we flesh out fusefs some more. The tests assert
that the device can be opened and used.
2020-06-25 14:22:21 -04:00
Dean Deng b5e814445a Fix procfs bugs in vfs2.
- Support writing on proc/[pid]/{uid,gid}map
- Return EIO for writing to static files.

Updates #2923.

PiperOrigin-RevId: 318188503
2020-06-24 19:22:12 -07:00
gVisor bot ac6f7b600b Internal change.
PiperOrigin-RevId: 318180382
2020-06-24 18:14:07 -07:00
Nicolas Lacasse 58880bf551 Port /dev/net/tun device to VFS2.
Updates #2912 #1035

PiperOrigin-RevId: 318162565
2020-06-24 16:23:44 -07:00
Ian Gudger 2141013dce Add support for SO_REUSEADDR to TCP sockets/endpoints.
For TCP sockets, SO_REUSEADDR relaxes the rules for binding addresses.

gVisor/netstack already supported a behavior similar to SO_REUSEADDR, but did
not allow disabling it. This change brings the SO_REUSEADDR behavior closer to
the behavior implemented by Linux and adds a new SO_REUSEADDR disabled
behavior. Like Linux, SO_REUSEADDR is now disabled by default.

PiperOrigin-RevId: 317984380
2020-06-23 19:15:38 -07:00
Nicolas Lacasse 0f328beb0d Port /dev/tty device to VFS2.
Support is limited to the functionality that exists in VFS1.

Updates #2923 #1035

PiperOrigin-RevId: 317981417
2020-06-23 18:48:37 -07:00
Dean Deng 65a587dedf Complete inotify IN_EXCL_UNLINK implementation in VFS2.
Events were only skipped on parent directories after their children were
unlinked; events on the unlinked file itself need to be skipped as well.

As a result, all Watches.Notify() calls need to know whether the dentry where
the call came from was unlinked.

Updates #1479.

PiperOrigin-RevId: 317979476
2020-06-23 18:33:04 -07:00
Ting-Yu Wang acf519a77b Nit fix: Create and use a std::string object for `const char*`.
PiperOrigin-RevId: 317973144
2020-06-23 17:44:34 -07:00
Dean Deng 0c628c3152 Support inotify in vfs2 gofer fs.
Because there is no inode structure stored in the sandbox, inotify watches
must be held on the dentry. This would be an issue in the presence of hard
links, where multiple dentries would need to share the same set of watches,
but in VFS2, we do not support the internal creation of hard links on gofer
fs. As a result, we make the assumption that every dentry corresponds to a
unique inode.

Furthermore, dentries can be cached and then evicted, even if the underlying
file has not be deleted. We must prevent this from occurring if there are any
watches that would be lost. Note that if the dentry was deleted or invalidated
(d.vfsd.IsDead()), we should still destroy it along with its watches.

Additionally, when a dentry’s last watch is removed, we cache it if it also
has zero references. This way, the dentry can eventually be evicted from
memory if it is no longer needed. This is accomplished with a new dentry
method, OnZeroWatches(), which is called by Inotify.RmWatch and
Inotify.Release. Note that it must be called after all inotify locks are
released to avoid violating lock order. Stress tests are added to make sure
that inotify operations don't deadlock with gofer.OnZeroWatches.

Updates #1479.

PiperOrigin-RevId: 317958034
2020-06-23 16:14:56 -07:00
Ting-Yu Wang 793edf4cb4 Deflake proc test: Don't fail on DT_UNKNOWN.
Per manual page:
"All applications must properly handle a return of DT_UNKNOWN."

PiperOrigin-RevId: 317957013
2020-06-23 16:07:26 -07:00
Nicolas Lacasse edea9a8d02 Port readahead to VFS2.
It preserves the same functionality (almost none) as in VFS1.

Updates #2923 #1035

PiperOrigin-RevId: 317943522
2020-06-23 14:53:33 -07:00
Dean Deng 4573e7d863 Check for invalid trailing / when traversing path in gofer OpenAt.
Updates #2923.

PiperOrigin-RevId: 317700049
2020-06-22 11:39:41 -07:00
Nicolas Lacasse a480b4faf4 Allow readdir(/proc/[tid]/net) to return EINVAL on a zombie task.
Despite what the man page says, linux will return EINVAL when calling
getdents() an a /proc/[tid]/net file corresponding to a zombie task. This
causes readdir() to return a null pointer AND errno=EINVAL.

See fs/proc/proc_net.c:proc_tgid_net_readdir() for where this occurs.

We have tests that recursively read /proc, and are likely to hit this when
running natively, so we must catch and handle this case.

PiperOrigin-RevId: 317674168
2020-06-22 09:54:22 -07:00
Dean Deng f46f4a2af9 Enable passing vfs2 tests.
I forgot to update getdents earlier. Several thousand runs of the fsync and
proc_net_unix tests all passed as well.

Updates #2923.

PiperOrigin-RevId: 317415488
2020-06-19 18:27:29 -07:00
Dean Deng 7db196c4db Port fadvise64 to vfs2.
Like vfs1, we have a trivial implementation that ignores all valid advice.

Updates #2923.

PiperOrigin-RevId: 317349505
2020-06-19 11:50:09 -07:00
Dean Deng a609fff9d1 Fix vfs2 handling of preadv2/pwritev2 flags.
Check for unsupported flags, and silently support RWF_HIPRI by doing nothing.
From pkg/abi/linux/file.go: "gVisor does not implement the RWF_HIPRI feature,
but the flag is accepted as a valid flag argument for preadv2/pwritev2."

Updates #2923.

PiperOrigin-RevId: 317330631
2020-06-19 10:19:46 -07:00
Dean Deng f40d023ad6 Don't adjust parent link count if we replace a child dir with another.
Updates #2923.

PiperOrigin-RevId: 317314460
2020-06-19 08:45:40 -07:00
Dean Deng 46957ed24f Fix synthetic file bugs in gofer fs.
Always check if a synthetic file already exists at a location before creating a
file there, and do not try to delete synthetic gofer files from the remote fs.

This fixes runsc_ptrace socket tests that create/unlink synthetic, named socket
files.

Updates #2923.

PiperOrigin-RevId: 317293648
2020-06-19 05:57:15 -07:00
Dean Deng 408f3d2cd6 Fix vfs2 tmpfs link permission checks.
Updates #2923.

PiperOrigin-RevId: 317246916
2020-06-18 22:02:07 -07:00
Fabricio Voznika 878050b5cf Enable more VFS2 syscall tests
Updates #2923

PiperOrigin-RevId: 317185798
2020-06-18 14:52:54 -07:00
Michael Pratt 3970c12743 Remove various uses of 'whitelist'
Updates #2972

PiperOrigin-RevId: 317113059
2020-06-18 09:03:39 -07:00
Bhasker Hariharan 07ff909e76 Support setsockopt SO_SNDBUF/SO_RCVBUF for raw/udp sockets.
Updates #173,#6
Fixes #2888

PiperOrigin-RevId: 317087652
2020-06-18 06:07:20 -07:00
Ian Gudger 02072fd243 Add test for stat("/proc/net/snmp").
PiperOrigin-RevId: 316974863
2020-06-17 15:15:57 -07:00
Nicolas Lacasse 28a5c55bb6 Proc test: Allow root mount pathname to be non-root.
The test was expecting that the root mount pathname was "/", but it doesn't
need to be. Only the mount point actually should be "/" (otherwise it is not
the root).

PiperOrigin-RevId: 316968025
2020-06-17 14:42:41 -07:00
Bhasker Hariharan 505e8f4e3d Fix TtlDefault test on linux.
Different flavors of linux seem to use different defaults we accept 64
or 127 as the TtlDefault in the test.

PiperOrigin-RevId: 316961150
2020-06-17 14:08:48 -07:00
Fabricio Voznika 96519e2c9d Implement POSIX locks
- Change FileDescriptionImpl Lock/UnlockPOSIX signature to
  take {start,length,whence}, so the correct offset can be
  calculated in the implementations.
- Create PosixLocker interface to make it possible to share
  the same locking code from different implementations.

Closes #1480

PiperOrigin-RevId: 316910286
2020-06-17 10:04:26 -07:00
Martijn Vels eb6d3d7710 Internal change.
PiperOrigin-RevId: 316492839
2020-06-15 10:27:16 -07:00
Rahat Mahmood f23f62c2c2 Correctly set the test VFS environment variable.
Also fix test bugs uncovered now that they aren't silently skipped on
VFS2.

Updates #1487.

PiperOrigin-RevId: 316415807
2020-06-15 01:09:38 -07:00
Ian Gudger 3b5eaad3c8 Allow reading IP_MULTICAST_LOOP and IP_MULTICAST_TTL on TCP sockets.
I am not really sure what the point of this is, but someone filed a bug about
it, so I assume something relies on it.

PiperOrigin-RevId: 316225127
2020-06-12 20:49:02 -07:00
Andrei Vagin 6ec9d60403 vfs2: implement fcntl(fd, F_SETFL, flags)
PiperOrigin-RevId: 316148074
2020-06-12 11:58:15 -07:00
gVisor bot 11dc95e6c5 Merge pull request #2705 from lubinszARM:pr_sigfp_nested
PiperOrigin-RevId: 315979564
2020-06-11 14:35:46 -07:00
Ian Gudger a085e562d0 Add support for SO_REUSEADDR to UDP sockets/endpoints.
On UDP sockets, SO_REUSEADDR allows multiple sockets to bind to the same
address, but only delivers packets to the most recently bound socket. This
differs from the behavior of SO_REUSEADDR on TCP sockets. SO_REUSEADDR for TCP
sockets will likely need an almost completely independent implementation.

SO_REUSEADDR has some odd interactions with the similar SO_REUSEPORT. These
interactions are tested fairly extensively and all but one particularly odd
one (that honestly seems like a bug) behave the same on gVisor and Linux.

PiperOrigin-RevId: 315844832
2020-06-10 23:49:26 -07:00
Nayana Bidari 9338854ea3 Fix the error code for syscall test with null TOS.
The setsockopt with nullptr can fail with either EFAULT or zero.

PiperOrigin-RevId: 315777107
2020-06-10 15:06:45 -07:00
Nayana Bidari 4b9652d63b {S,G}etsockopt for TCP_KEEPCNT option.
TCP_KEEPCNT is used to set the maximum keepalive probes to be
sent before dropping the connection.

WANT_LGTM=jchacon
PiperOrigin-RevId: 315758094
2020-06-10 13:37:27 -07:00
Andrei Vagin a5a4f80487 socket/unix: handle sendto address argument for connected sockets
In case of SOCK_SEQPACKET, it has to be ignored.
In case of SOCK_STREAM, EISCONN or EOPNOTSUPP has to be returned.

PiperOrigin-RevId: 315755972
2020-06-10 13:26:54 -07:00
Fabricio Voznika 67565078bb Implement flock(2) in VFS2
LockFD is the generic implementation that can be embedded in
FileDescriptionImpl implementations. Unique lock ID is
maintained in vfs.FileDescription and is created on demand.

Updates #1480

PiperOrigin-RevId: 315604825
2020-06-09 18:46:42 -07:00
gVisor bot 4950ccde75 Fix write hang bug found by syzkaller.
After this change e.mu is only promoted to exclusively locked during
route.Resolve. It downgrades back to read-lock afterwards.
This prevents the second RLock() call gets stuck later in the stack.

https://syzkaller.appspot.com/bug?id=065b893bd8d1d04a4e0a1d53c578537cde1efe99

Syzkaller logs does not contain interesting stack traces.
The following stack trace is obtained by running repro locally.

goroutine 53 [semacquire, 3 minutes]:
runtime.gopark(0xfd4278, 0x1896320, 0xc000301912, 0x4)
        GOROOT/src/runtime/proc.go:304 +0xe0 fp=0xc0000e25f8 sp=0xc0000e25d8 pc=0x437170
runtime.goparkunlock(...)
        GOROOT/src/runtime/proc.go:310
runtime.semacquire1(0xc0001220b0, 0xc00000a300, 0x1, 0x0)
        GOROOT/src/runtime/sema.go:144 +0x1c0 fp=0xc0000e2660 sp=0xc0000e25f8 pc=0x4484e0
sync.runtime_Semacquire(0xc0001220b0)
        GOROOT/src/runtime/sema.go:56 +0x42 fp=0xc0000e2690 sp=0xc0000e2660 pc=0x448132
gvisor.dev/gvisor/pkg/sync.(*RWMutex).RLock(...)
        pkg/sync/rwmutex_unsafe.go:76
gvisor.dev/gvisor/pkg/tcpip/transport/udp.(*endpoint).HandleControlPacket(0xc000122000, 0x7ee5, 0xc00053c16c, 0x4, 0x5e21, 0xc00053c224, 0x4, 0x1, 0x0, 0xc00007ed00)
        pkg/tcpip/transport/udp/endpoint.go:1345 +0x169 fp=0xc0000e26d8 sp=0xc0000e2690 pc=0x9843f9
......
gvisor.dev/gvisor/pkg/tcpip/transport/udp.(*protocol).HandleUnknownDestinationPacket(0x18bb5a0, 0xc000556540, 0x5e21, 0xc00053c16c, 0x4, 0x7ee5, 0xc00053c1ec, 0x4, 0xc00007e680, 0x4)
        pkg/tcpip/transport/udp/protocol.go:143 +0xb9a fp=0xc0000e8260 sp=0xc0000e7510 pc=0x9859ba
......
gvisor.dev/gvisor/pkg/tcpip/transport/udp.sendUDP(0xc0001220d0, 0xc00053ece0, 0x1, 0x1, 0x883, 0x1405e217ee5, 0x11100a0, 0xc000592000, 0xf88780)
        pkg/tcpip/transport/udp/endpoint.go:924 +0x3b0 fp=0xc0000ed390 sp=0xc0000ec750 pc=0x981af0
gvisor.dev/gvisor/pkg/tcpip/transport/udp.(*endpoint).write(0xc000122000, 0x11104e0, 0xc00020a460, 0x0, 0x0, 0x0, 0x0, 0x0)
        pkg/tcpip/transport/udp/endpoint.go:510 +0x4ad fp=0xc0000ed658 sp=0xc0000ed390 pc=0x97f2dd

PiperOrigin-RevId: 315590041
2020-06-09 17:02:14 -07:00
gVisor bot 6260304179 Merge pull request #2788 from lubinszARM:pr_exec_2
PiperOrigin-RevId: 315166991
2020-06-07 09:56:53 -07:00
Andrei Vagin 8c1f5b5cd8 Unshare files on exec
The current task can share its fdtable with a few other tasks,
but after exec, this should be a completely separate process.

PiperOrigin-RevId: 314999565
2020-06-05 14:45:32 -07:00
Bhasker Hariharan 526df4f52a Fix error code returned due to Port exhaustion.
For TCP sockets gVisor incorrectly returns EAGAIN when no ephemeral ports are
available to bind during a connect. Linux returns EADDRNOTAVAIL. This change
fixes gVisor to return the correct code and adds a test for the same.

This change also fixes a minor bug for ping sockets where connect() would fail
with EINVAL unless the socket was bound first.

Also added tests for testing UDP Port exhaustion and Ping socket port
exhaustion.

PiperOrigin-RevId: 314988525
2020-06-05 13:43:01 -07:00
Zach Koopmans d8d86f0f3a Add test for O_TRUNC
b/36576592 calls out an edge case previously not supported
by HostFS. HostFS is currently being removed, meaning gVisor
supports this feature. Simply add the test to open_test.

PiperOrigin-RevId: 314610226
2020-06-03 14:56:04 -07:00
Andrei Vagin e6334e81ca Check that two sockets with different types can't be connected to each other
PiperOrigin-RevId: 314450191
2020-06-02 19:19:15 -07:00
Fabricio Voznika 4b5eae39f2 Enable VFS2 to runsc syscall tests
Updates #1487

PiperOrigin-RevId: 314271995
2020-06-01 23:03:20 -07:00
Dean Deng 050d8e6e33 Add inotify events for extended attributes and splice.
Splice, setxattr and removexattr should generate events. Note that VFS2 already
generates events for extended attributes.

Updates #1479.

PiperOrigin-RevId: 314244261
2020-06-01 18:31:59 -07:00
Nicolas Lacasse 6ef5924725 Deflake pty_test_linux.
PiperOrigin-RevId: 314208973
2020-06-01 14:55:42 -07:00
Dean Deng 35a3f462d9 Fix inotify test.
PiperOrigin-RevId: 314192441
2020-06-01 13:35:30 -07:00
Dean Deng 07c3b1dc55 Skip proc/pid/fd socket test for VFS1 only.
PiperOrigin-RevId: 314192359
2020-06-01 13:30:39 -07:00
Dean Deng ccf69bdd7e Implement IN_EXCL_UNLINK inotify option in vfs2.
Limited to tmpfs. Inotify support in other filesystem implementations to
follow.

Updates #1479

PiperOrigin-RevId: 313828648
2020-05-29 12:28:49 -07:00
Dean Deng fe464f44b7 Port inotify to vfs2, with support in tmpfs.
Support in other filesystem impls is still needed. Unlike in Linux and vfs1, we
need to plumb inotify down to each filesystem implementation in order to keep
track of links/inode structures properly.

IN_EXCL_UNLINK still needs to be implemented, as well as a few inotify hooks
that are not present in either vfs1 or vfs2. Those will be addressed in
subsequent changes.

Updates #1479.

PiperOrigin-RevId: 313781995
2020-05-29 08:09:14 -07:00
Bin Lu 744e8d6e43 minor changes in exec_binary test case for Arm64
Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-05-28 04:28:06 -04:00
Jamie Liu af3121a523 Implement splice(2) and tee(2) for VFS2.
Updates #138

PiperOrigin-RevId: 313326354
2020-05-26 21:43:26 -07:00
Dean Deng ba2bf9fc13 Skip socket tests only if running on vfs1.
PiperOrigin-RevId: 312763249
2020-05-21 16:32:48 -07:00
Jay Zhuang 8298c5bd4d Avoid all caps FIONREAD as test name.
PiperOrigin-RevId: 312596169
2020-05-20 18:40:16 -07:00
Jamie Liu 064347afdf Skip itimer "fairness" tests on ptrace.
With additional logging, the issue described by the new comment looks like:

D0518 21:28:08.416810    6777 task_signals.go:459] [   8] Notified of signal 27
D0518 21:28:08.416852    6777 task_block.go:223] [   8] Interrupt queued
D0518 21:28:08.417013    6777 task_run.go:250] [   8] Switching to sentry
D0518 21:28:08.417033    6777 task_signals.go:220] [   8] Signal 27: delivering to handler
D0518 21:28:08.417127    6777 task_run.go:248] [   8] Switching to app
D0518 21:28:08.443765    6777 task_signals.go:519] [   8] Refusing masked signal 27 // ED: note the ~26ms elapsed since TID 8 "switched to app"
D0518 21:28:08.443814    6777 task_signals.go:465] [   6] Notified of group signal 27
D0518 21:28:08.443832    6777 task_block.go:223] [   6] Interrupt queued
D0518 21:28:08.443914    6777 task_block.go:223] [   6] Interrupt queued
D0518 21:28:08.443859    6777 task_run.go:250] [   8] Switching to sentry
I0518 21:28:08.443936    6777 strace.go:576] [   8] exe E rt_sigreturn()

Slow context switches on ptrace are probably due to kernel scheduling delays.
Slow context switches on KVM are less clear, so leave that bug and TODO open.

PiperOrigin-RevId: 312322782
2020-05-19 11:53:03 -07:00
Dean Deng d06de1bede Fix flaky udp tests by polling before reading.
On native Linux, calling recv/read right after send/write sometimes returns
EWOULDBLOCK, if the data has not made it to the receiving socket (even though
the endpoints are on the same host). Poll before reading to avoid this.

Making this change also uncovered a hostinet bug (gvisor.dev/issue/2726),
which is noted in this CL.

PiperOrigin-RevId: 312320587
2020-05-19 11:41:52 -07:00
Bin Lu 0b26f9aa0f passed the syscall test case 'fpsig_nested' on Arm64 platform
Some functions were added for Arm64 platform:
a, get_fp/set_fp
b, inline_tgkill

Test step:
bazel test //test/syscalls:fpsig_nested_test_runsc_ptrace

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-05-15 02:52:36 -04:00
Jamie Liu fb7e5f1676 Make utimes_test pass on VFS2.
PiperOrigin-RevId: 311657502
2020-05-14 20:09:55 -07:00
gVisor bot bdf7bb71d2 Merge pull request #2663 from lubinszARM:pr_sigfp_fork
PiperOrigin-RevId: 311573552
2020-05-14 11:38:57 -07:00
Bhasker Hariharan 8b8774d715 Stub support for TCP_SYNCNT and TCP_WINDOW_CLAMP.
This change adds support for TCP_SYNCNT and TCP_WINDOW_CLAMP options
in GetSockOpt/SetSockOpt. This change does not really change any
behaviour in Netstack and only stores/returns the stored value.

Actual honoring of these options will be added as required.

Fixes #2626, #2625

PiperOrigin-RevId: 311453777
2020-05-13 19:49:09 -07:00
Nicolas Lacasse db655f020e Resolve remaining TODOs for tmpfs.
Closes #1197

PiperOrigin-RevId: 311438223
2020-05-13 17:36:37 -07:00
gVisor bot af2bc1c72a Internal change.
PiperOrigin-RevId: 310941717
2020-05-11 10:31:02 -07:00
Bin Lu 257a6bf883 passed the syscall test case 'fpsig_fork' on Arm64 platform
Some functions were added for Arm64 platform:
a, get_fp/set_fp
b, inline_tgkill

Test step:
bazel test //test/syscalls:fpsig_fork_test_runsc_ptrace

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-05-11 01:57:16 -04:00
Andrei Vagin 9509c0b388 gvisor/test: use RetryEINTR for connect()
connect() returns EINTR after S/R and usually we
use RetryEINTR to workaround this.

PiperOrigin-RevId: 310038525
2020-05-05 16:01:00 -07:00
Nicolas Lacasse da71dc7fdd Port eventfd to VFS2.
And move sys_timerfd.go to just timerfd.go for consistency.

Updates #1475.

PiperOrigin-RevId: 309835029
2020-05-04 16:02:07 -07:00
Andrei Vagin 006f978829 Deflake //third_party/gvisor/test/syscalls:proc_test_native
There is the known issue of the linux procfs, that two consequent calls of
readdir can return the same entry twice if between these calls one or more
entries have been removed from this directory.

PiperOrigin-RevId: 309803066
2020-05-04 12:58:24 -07:00
Dean Deng ce19497c1c Fix Unix socket permissions.
Enforce write permission checks in BoundEndpointAt, which corresponds to the
permission checks in Linux (net/unix/af_unix.c:unix_find_other).
Also, create bound socket files with the correct permissions in VFS2.

Fixes #2324.

PiperOrigin-RevId: 308949084
2020-04-28 20:13:01 -07:00
Jamie Liu 4282260355 Don't unlink named pipes in pipe test.
TempPath's destructor runs at the end of the named pipe creation functions,
deleting the named pipe. If the named pipe is backed by a "non-virtual"
filesystem (!fs.Inode.IsVirtual()), this causes the following save attempt to
fail because there are FDs holding the deleted named pipe open.

PiperOrigin-RevId: 308861999
2020-04-28 11:28:44 -07:00
Andrei Vagin 37f863f628 tcp: handle listen after shutdown properly
Right now, sentry panics in this case:
panic: close of nil channel

goroutine 67 [running]:
pkg/tcpip/transport/tcp/tcp.(*endpoint).listen(0xc0000ce000, 0x9, 0x0)
        pkg/tcpip/transport/tcp/endpoint.go:2208 +0x170
pkg/tcpip/transport/tcp/tcp.(*endpoint).Listen(0xc0000ce000, 0x9, 0xc0003a1ad0)
        pkg/tcpip/transport/tcp/endpoint.go:2179 +0x50

Fixes #2468

PiperOrigin-RevId: 307896725
2020-04-22 14:17:11 -07:00