Commit Graph

3703 Commits

Author SHA1 Message Date
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
Jay Zhuang 68e1c870d3 Add test env variable "fuchsia"
... so that Fuchsia gets the same special cases applied to gVisor in tests when
this envrionment variable is set.

PiperOrigin-RevId: 319239064
2020-07-01 09:36:07 -07:00
Michael Pratt 068716ddf3 Fix FAQ URL
The existing gvisor.dev/faq link returns 404 because the full URL has
mistakenly been capitalized.

PiperOrigin-RevId: 319233173
2020-07-01 08:53: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
Bhasker Hariharan b8f165ab1c Fix HTTPD benchmarks to correctly serve files from /tmp.
Fixes #3113

PiperOrigin-RevId: 319216671
2020-07-01 06:58:56 -07:00
Bhasker Hariharan c9446f0534 Fix two bugs in TCP sender.
a) When GSO is in use we should not cap the segment to maxPayloadSize in
   sender.maybeSendSegment as the GSO logic will cap the segment to the correct
   size. Without this the host GSO is not used as we end up breaking up large
   segments into small MSS sized segments before writing the packets to the
   host.

b) The check to not split a segment due to it not fitting in the receiver window
   when there are pending segments is incorrect as segments in writeList can be
   really large as we just take the write call's buffer size and create a single
   large segment. So a write of say 128KB will just be 1 segment in the
   writeList.

   The linux code checks if 1 MSS sized segments fits in the receiver's window
   and if not then does not split the current segment. gVisor's check was
   incorrect that it was checking if the whole segment which could be >>> 1 MSS
   would fit in the receiver's window. This was causing us to prematurely stop
   sending and falling back to retransmit timer/probe from the other end to send
   data.

This was seen when running HTTPD benchmarks where @ HEAD when sending large
files the benchmark was taking forever to run.

The tcp_splitseg_mss_test.go is being deleted as the test as written doesn't
test what is intended correctly. This is because GSO is enabled by default and
the reason the MSS+1 sized segment is sent is because GSO is in use. A proper
test will require disabling GSO on linux and netstack which is going to take a
bit of work in packetimpact to do it correctly.

Separately a new test probably should be written that verifies that a segment >
availableWindow is not split if the availableWindow is < 1 MSS.

Fixes #3107

PiperOrigin-RevId: 319172089
2020-06-30 23:56:34 -07:00
Dean Deng 43f5dd95a1 Fix index calculation for /proc/[pid]/cmdline.
We were truncating buf using a index relative to the middle of the slice (i.e.
where envv begins), but we need to calculate the index relative to the entire
slice.

Updates #2923.

PiperOrigin-RevId: 319154950
2020-06-30 21:00:49 -07:00
Dean Deng 20d571b0c1 Allow O_DIRECT on vfs2 tmpfs files.
Updates #2923.

PiperOrigin-RevId: 319153792
2020-06-30 20:48:59 -07:00
Bhasker Hariharan c4bdd0118f Add missing newline in /sys/devices/systen/cpu/onine
PiperOrigin-RevId: 319143410
2020-06-30 19:01:55 -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
Tamir Duberstein 4784ed46ef Avoid multiple atomic loads
...by calling (*tcp.endpoint).EndpointState only once when possible.

Avoid wrapping (*sleep.Waker).Assert in a useless func while I'm here.

PiperOrigin-RevId: 319074149
2020-06-30 12:25:03 -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 691c04278e Add documentation for vfs2 inotify.
Updates #1479.

PiperOrigin-RevId: 318631247
2020-06-27 09:20:04 -07:00
Ian Gudger bab3c36efb Add style guide.
PiperOrigin-RevId: 318591900
2020-06-26 21:10:37 -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
Zeling Feng aed7183976 Packetimpact test for IPv6 unknown options action
The Option Type identifiers are internally encoded such that their
highest-order two bits specify the action that must be taken if the
processing IPv6 node does not recognize the Option Type:

  00 - skip over this option and continue processing the header.
  01 - discard the packet.
  10 - discard the packet and, regardless of whether or not the
       packet's Destination Address was a multicast address, send an
       ICMP Parameter Problem, Code 2, message to the packet's
       Source Address, pointing to the unrecognized Option Type.
  11 - discard the packet and, only if the packet's Destination
       Address was not a multicast address, send an ICMP Parameter
       Problem, Code 2, message to the packet's Source Address,
       pointing to the unrecognized Option Type.

PiperOrigin-RevId: 318566613
2020-06-26 16:43:53 -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
Zeling Feng e6a90baef1 Support IPv6 extension headers in packetimpact tests.
- IPv6 HopByHop Options Extension Header
- IPv6 Destination Options Extension Header

PiperOrigin-RevId: 318551425
2020-06-26 15:08:51 -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
gVisor bot cfd049da87 Merge pull request #2931 from ridwanmsharif:ridwanmsharif/fuse-char-device
PiperOrigin-RevId: 318511615
2020-06-26 11:37:23 -07:00
Kevin Krakauer 47ac142dc9 Enable docker IPv6 in kokoro
We need docker IPv6 for ip6tables tests. Docker has spotty IPv6 support, so just
enabling IPv6 in daemon.json breaks the Ruby image test (AFAICT it breaks
anything that tries to use IPv6 to reach the internet). An ip6tables NAT rule is
added to handle this.

We could make these changes as part of scripts/, but these would overwrite
global values and possibly break users' systems.

PiperOrigin-RevId: 318508209
2020-06-26 11:19:12 -07:00
Kevin Krakauer 7fb6cc286f conntrack refactor, no behavior changes
- Split connTrackForPacket into 2 functions instead of switching on flag
- Replace hash with struct keys.
- Remove prefixes where possible
- Remove unused connStatus, timeout
- Flatten ConnTrack struct a bit - some intermediate structs had no meaning
  outside of the context of their parent.
- Protect conn.tcb with a mutex
- Remove redundant error checking (e.g. when is pkt.NetworkHeader valid)
- Clarify that HandlePacket and CreateConnFor are the expected entrypoints for
  ConnTrack

PiperOrigin-RevId: 318407168
2020-06-25 21:21:57 -07:00
Tamir Duberstein 4069461877 Avoid an allocation in epoll
PiperOrigin-RevId: 318346153
2020-06-25 14:18:33 -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
Adin Scannell 00ee5abaa7 Drop unused markdown links.
PiperOrigin-RevId: 318284693
2020-06-25 09:18:30 -07: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
Tamir Duberstein 10930b0f8c Remove waiter.Entry.Context
This field is redundant since state can be stored in the callback.

PiperOrigin-RevId: 318134855
2020-06-24 13:56:38 -07:00
Bhasker Hariharan b070e218c6 Add support for Stack level options.
Linux controls socket send/receive buffers using a few sysctl variables
  - net.core.rmem_default
  - net.core.rmem_max
  - net.core.wmem_max
  - net.core.wmem_default
  - net.ipv4.tcp_rmem
  - net.ipv4.tcp_wmem

The first 4 control the default socket buffer sizes for all sockets
raw/packet/tcp/udp and also the maximum permitted socket buffer that can be
specified in setsockopt(SOL_SOCKET, SO_(RCV|SND)BUF,...).

The last two control the TCP auto-tuning limits and override the default
specified in rmem_default/wmem_default as well as the max limits.

Netstack today only implements tcp_rmem/tcp_wmem and incorrectly uses it
to limit the maximum size in setsockopt() as well as uses it for raw/udp
sockets.

This changelist introduces the other 4 and updates the udp/raw sockets to use
the newly introduced variables. The values for min/max match the current
tcp_rmem/wmem values and the default value buffers for UDP/RAW sockets is
updated to match the linux value of 212KiB up from the really low current value
of 32 KiB.

Updates #3043
Fixes #3043

PiperOrigin-RevId: 318089805
2020-06-24 10:24:20 -07:00
Adin Scannell 364ac92baf Support for saving pointers to fields in the state package.
Previously, it was not possible to encode/decode an object graph which
contained a pointer to a field within another type. This was because the
encoder was previously unable to disambiguate a pointer to an object and a
pointer within the object.

This CL remedies this by constructing an address map tracking the full memory
range object occupy. The encoded Refvalue message has been extended to allow
references to children objects within another object. Because the encoding
process may learn about object structure over time, we cannot encode any
objects under the entire graph has been generated.

This CL also updates the state package to use standard interfaces intead of
reflection-based dispatch in order to improve performance overall. This
includes a custom wire protocol to significantly reduce the number of
allocations and take advantage of structure packing.

As part of these changes, there are a small number of minor changes in other
places of the code base:

* The lists used during encoding are changed to use intrusive lists with the
  objectEncodeState directly, which required that the ilist Len() method is
  updated to work properly with the ElementMapper mechanism.

* A bug is fixed in the list code wherein Remove() called on an element that is
  already removed can corrupt the list (removing the element if there's only a
  single element). Now the behavior is correct.

* Standard error wrapping is introduced.

* Compressio was updated to implement the new wire.Reader and wire.Writer
  inteface methods directly. The lack of a ReadByte and WriteByte caused issues
  not due to interface dispatch, but because underlying slices for a Read or
  Write call through an interface would always escape to the heap!

* Statify has been updated to support the new APIs.

See README.md for a description of how the new mechanism works.

PiperOrigin-RevId: 318010298
2020-06-23 23:34:06 -07:00
Dean Deng 399c52888d Resolve remaining inotify TODOs.
Also refactor HandleDeletion().

Updates #1479.

PiperOrigin-RevId: 317989000
2020-06-23 20:05:28 -07:00
Dean Deng 2189e0a660 Clean up hostfs TODOs.
This CL does a handful of things:
- Support O_DSYNC, O_SYNC
- Support O_APPEND and document an unavoidable race condition
- Ignore O_DIRECT; we probably don't want to allow applications to set O_DIRECT
  on the host fd itself.
- Leave a TODO for supporting O_NONBLOCK, which is a simple fix once RWF_NOWAIT
  is supported.
- Get rid of caching TODO; force_page_cache is not configurable for host fs in
  vfs1 or vfs2 after whitelist fs was removed.
- For the remaining TODOs, link to more specific bugs.

Fixes #1672.

PiperOrigin-RevId: 317985269
2020-06-23 19:24:43 -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
gVisor bot ca1bc46f15 Internal change.
PiperOrigin-RevId: 317941748
2020-06-23 14:42:15 -07:00