Commit Graph

1018 Commits

Author SHA1 Message Date
Michael Pratt 9679f9891f Fix comment typo
PiperOrigin-RevId: 265731735
2019-08-27 11:44:06 -07:00
Fabricio Voznika 8fd89fd7a2 Fix sendfile(2) error code
When output file is in append mode, sendfile(2) should fail
with EINVAL and not EBADF.

Closes #721

PiperOrigin-RevId: 265718958
2019-08-27 10:52:46 -07:00
Fabricio Voznika c39564332b Mount volumes as super user
This used to be the case, but regressed after a recent change.
Also made a few fixes around it and clean up the code a bit.

Closes #720

PiperOrigin-RevId: 265717496
2019-08-27 10:47:16 -07:00
Rahat Mahmood 1fdefd41c5 netstack/tcp: Add LastAck transition.
Add missing state transition to LastAck, which should happen when the
endpoint has already recieved a FIN from the remote side, and is
sending its own FIN.

PiperOrigin-RevId: 265568314
2019-08-26 16:39:13 -07:00
Michael Pratt 904b156962 Add support for Intel cache CPUID leafs
This exposes L1, L2, etc. cache sizes, cache line size, etc.

Across S/R, everything except cache line size can differ from the host. This is
because cache line size is critical for correct use of CLFLUSH / CLFLUSHOPT,
but as far as I know, the other cache parameters can only affect performance,
not correctness.

AMD uses different leafs for cache information, which are not yet supported.

fail. There are no known cases of cache line size other than 64 in the fleet.

PiperOrigin-RevId: 265544786
2019-08-26 14:47:05 -07:00
gVisor bot 7206202bb9 Merge pull request #696 from xiaobo55x:tcpip_link
PiperOrigin-RevId: 265534854
2019-08-26 14:03:30 -07:00
Chris Kuiper ac2200b8a9 Prevent a network endpoint to send/rcv if its address was removed
This addresses the problem where an endpoint has its address removed but still
has outstanding references held by routes used in connected TCP/UDP sockets
which prevent the removal of the endpoint.

The fix adds a new "expired" flag to the referenced network endpoint, which is
set when an endpoint has its address removed. Incoming packets are not
delivered to an expired endpoint (unless in promiscuous mode), while sending
outgoing packets triggers an error to the caller (unless in spoofing mode).

In addition, a few helper functions were added to stack_test.go to reduce
code duplications.

PiperOrigin-RevId: 265514326
2019-08-26 12:29:47 -07:00
Tamir Duberstein e75a12e89d Implement fmt.Stringer on Route by value
This is more convenient, since it implements the interface for both
value and pointer.

PiperOrigin-RevId: 265086510
2019-08-23 10:44:11 -07:00
Adin Scannell 761e4bf2fe Ensure yield-equivalent with an already-expired timeout.
PiperOrigin-RevId: 264920977
2019-08-22 14:34:33 -07:00
Chris Kuiper 8d9276ed56 Support binding to multicast and broadcast addresses
This fixes the issue of not being able to bind to either a multicast or
broadcast address as well as to send and receive data from it. The way to solve
this is to treat these addresses similar to the ANY address and register their
transport endpoint ID with the global stack's demuxer rather than the NIC's.
That way there is no need to require an endpoint with that multicast or
broadcast address. The stack's demuxer is in fact the only correct one to use,
because neither broadcast- nor multicast-bound sockets care which NIC a
packet was received on (for multicast a join is still needed to receive packets
on a NIC).

I also took the liberty of refactoring udp_test.go to consolidate a lot of
duplicate code and make it easier to create repetitive tests that test the same
feature for a variety of packet and socket types. For this purpose I created a
"flowType" that represents two things: 1) the type of packet being sent or
received and 2) the type of socket used for the test. E.g., a "multicastV4in6"
flow represents a V4-mapped multicast packet run through a V6-dual socket.

This allows writing significantly simpler tests. A nice example is testTTL().

PiperOrigin-RevId: 264766909
2019-08-21 22:54:25 -07:00
Tamir Duberstein 573e6e4bba Use tcpip.Subnet in tcpip.Route
This is the first step in replacing some of the redundant types with the
standard library equivalents.

PiperOrigin-RevId: 264706552
2019-08-21 15:31:18 -07:00
Chris Kuiper 7e79ca0225 Add tcpip.Route.String and tcpip.AddressMask.Prefix
PiperOrigin-RevId: 264544163
2019-08-20 23:28:52 -07:00
Zach Koopmans 67d7864f83 Document RWF_HIPRI not implemented for preadv2/pwritev2.
Document limitation of no reasonable implementation for RWF_HIPRI
flag (High Priority Read/Write for block-based file systems).

PiperOrigin-RevId: 264237589
2019-08-19 14:07:44 -07:00
gVisor bot 3ffbdffd7e Internal change.
PiperOrigin-RevId: 264218306
2019-08-19 12:43:22 -07:00
Jianfeng Tan a63f88855f hostinet: fix parsing route netlink message
We wrongly parses output interface as gateway address.
The fix is straightforward.

Fixes #638

Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com>
Change-Id: Ia4bab31f3c238b0278ea57ab22590fad00eaf061
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/684 from tanjianfeng:fix-638 b940e810367ad1273519bfa594f4371bdd293e83
PiperOrigin-RevId: 264211336
2019-08-19 12:10:21 -07:00
Kevin Krakauer bd826092fe Read iptables via sockopts.
PiperOrigin-RevId: 264180125
2019-08-19 10:05:59 -07:00
Andrei Vagin 3e4102b2ea netstack: disconnect an unix socket only if the address family is AF_UNSPEC
Linux allows to call connect for ANY and the zero port.

PiperOrigin-RevId: 263892534
2019-08-16 19:32:14 -07:00
Ayush Ranjan 661b2b9f69 procfs: Migrate seqfile implementations.
Migrates all (except 3) seqfile implementations to the vfs.DynamicBytesSource
interface. There should not be any change in functionality due to this migration
itself.

Please note that the following seqfile implementations have not been migrated:
- /proc/filesystems in proc/filesystems.go
- /proc/[pid]/mountinfo in proc/mounts.go
- /proc/[pid]/mounts in proc/mounts.go
This is because these depend on pending changes in /pkg/senty/vfs.

PiperOrigin-RevId: 263880719
2019-08-16 17:36:42 -07:00
Andrei Vagin 2a1303357c ptrace: detect if a stub process exited unexpectedly
PiperOrigin-RevId: 263880577
2019-08-16 17:33:28 -07:00
Chris Kuiper f7114e0a27 Add subnet checking to NIC.findEndpoint and consolidate with NIC.getRef
This adds the same logic to NIC.findEndpoint that is already done in
NIC.getRef. Since this makes the two functions very similar they were combined
into one with the originals being wrappers.

PiperOrigin-RevId: 263864708
2019-08-16 15:58:58 -07:00
Ayush Ranjan 4bab7d7f08 vfs: Remove vfs.DefaultDirectoryFD from embedding vfs.DefaultFD.
This fixes the implementation ambiguity issues when a filesystem
implementation embeds vfs.DefaultDirectoryFD to its directory FD along
with an internal common fileDescription utility.

For similar reasons also removes FileDescriptionDefaultImpl from
DynamicBytesFileDescriptionImpl.

PiperOrigin-RevId: 263795513
2019-08-16 10:20:11 -07:00
Rahat Mahmood 6cfc76798b Document source and versioning of the TCPInfo struct.
PiperOrigin-RevId: 263637194
2019-08-15 14:05:59 -07:00
Tamir Duberstein fe74bba2bd Don't dereference errors passed to panic()
These errors are always pointers; there's no sense in dereferencing them
in the panic call. Changed one false positive for clarity.

PiperOrigin-RevId: 263611579
2019-08-15 11:58:16 -07:00
Tamir Duberstein 816a9211e9 netstack: move resumption logic into *_state.go
13a98df rearranged some of this code in a way that broke compilation of
the netstack-only export at github.com/google/netstack because
*_state.go files are not included in that export.

This commit moves resumption logic back into *_state.go, fixing the
compilation breakage.

PiperOrigin-RevId: 263601629
2019-08-15 11:13:46 -07:00
Haibo Xu 1b1e39d7a1 Enabling pkg/tcpip/link support on arm64.
Signed-off-by: Haibo Xu haibo.xu@arm.com
Change-Id: Ib6b4aa2db19032e58bf0395f714e6883caee460a
2019-08-15 03:19:30 +00:00
Haibo Xu 52843719ca Rename fdbased/mmap.go to fdbased/mmap_stub.go.
Signed-off-by: Haibo Xu haibo.xu@arm.com
Change-Id: Id4489554b9caa332695df8793d361f8332f6a13b
2019-08-15 03:19:22 +00:00
Haibo Xu 0624858593 Rename rawfile/blockingpoll_unsafe.go to rawfile/blockingpoll_stub_unsafe.go.
Signed-off-by: Haibo Xu haibo.xu@arm.com
Change-Id: I2376e502c1a860d5e624c8a8e3afab5da4c53022
2019-08-15 03:19:14 +00:00
Tamir Duberstein d81d94ac4c Replace uinptr with int64 when returning lengths
This is in accordance with newer parts of the standard library.

PiperOrigin-RevId: 263449916
2019-08-14 16:05:56 -07:00
Tamir Duberstein 69d1414a32 Add tcpip.AddressWithPrefix.String
PiperOrigin-RevId: 263436592
2019-08-14 15:02:14 -07:00
Bhasker Hariharan 570fb1db6b Improve SendMsg performance.
SendMsg before this change would copy all the data over into a
new slice even if the underlying socket could only accept a
small amount of data. This is really inefficient with non-blocking
sockets and under high throughput where large writes could get
ErrWouldBlock or if there was say a timeout associated with the sendmsg()
syscall.

With this change we delay copying bytes in till they are needed and only
copy what can be potentially sent/held in the socket buffer. Reducing
the need to repeatedly copy data over.

Also a minor fix to change state FIN-WAIT-1 when shutdown(..., SHUT_WR) is called
instead of when we transmit the actual FIN. Otherwise the socket could remain in
CONNECTED state even though the user has called shutdown() on the socket.

Updates #627

PiperOrigin-RevId: 263430505
2019-08-14 14:34:27 -07:00
Jamie Liu cee044c2ab Add vfs.DynamicBytesFileDescriptionImpl.
This replaces fs/proc/seqfile for vfs2-based filesystems.

PiperOrigin-RevId: 263254647
2019-08-13 17:54:24 -07:00
Fabricio Voznika 0e907c4298 Fix file mode check in pipeOperations
PiperOrigin-RevId: 263203441
2019-08-13 13:33:33 -07:00
Ian Gudger 072d941e32 Add note to name logging mentioning trace logging should be enabled to debug.
PiperOrigin-RevId: 263194584
2019-08-13 12:49:18 -07:00
Ian Gudger 99bf75a6dc gonet: Replace NewPacketConn with DialUDP.
This better matches the standard library and allows creating connected
PacketConns.

PiperOrigin-RevId: 263187462
2019-08-13 12:11:09 -07:00
Nicolas Lacasse 9769a8eaa4 Handle ENOSPC with a partial write.
Similar to the EPIPE case, we can return the number of bytes written before
ENOSPC was encountered. If the app tries to write more, we can return ENOSPC on
the next write.

PiperOrigin-RevId: 263041648
2019-08-12 17:41:33 -07:00
Rahat Mahmood 691c2f8173 Compute size of struct tcp_info instead of hardcoding it.
PiperOrigin-RevId: 263040624
2019-08-12 17:34:38 -07:00
Ian Gudger eac690e358 Fix netstack build error on non-AMD64.
This stub had the wrong function signature.

PiperOrigin-RevId: 262992682
2019-08-12 13:31:16 -07:00
Andrei Vagin af90e68623 netlink: return an error in nlmsgerr
Now if a process sends an unsupported netlink requests,
an error is returned from the send system call.

The linux kernel works differently in this case. It returns errors in the
nlmsgerr netlink message.

Reported-by: syzbot+571d99510c6f935202da@syzkaller.appspotmail.com
PiperOrigin-RevId: 262690453
2019-08-09 22:34:54 -07:00
Bhasker Hariharan 5a38eb120a Add congestion control states to sender.
This change just introduces different congestion control states and
ensures the sender.state is updated to reflect the current state
of the connection.

It is not used for any decisions yet but this is required before
algorithms like Eiffel/PRR can be implemented.

Fixes #394

PiperOrigin-RevId: 262638292
2019-08-09 14:50:30 -07:00
Haibo Xu 1c9da886e7 Add initial ptrace stub and syscall support for arm64.
Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I1dbd23bb240cca71d0cc30fc75ca5be28cb4c37c
PiperOrigin-RevId: 262619519
2019-08-09 13:18:11 -07:00
Ayush Ranjan c8961a6cbd ext: Move to pkg/sentry/fsimpl.
fsimpl is the keeper of all filesystem implementations in VFS2.

PiperOrigin-RevId: 262617869
2019-08-09 13:08:28 -07:00
Ayush Ranjan 690308111c ext: Benchmark tests.
Added benchmark tests which emulate memfs benchmarks.

Stat benchmarks
BenchmarkVFS2Ext4fsStat/1-12      	10000000	       145 ns/op
BenchmarkVFS2Ext4fsStat/2-12      	10000000	       170 ns/op
BenchmarkVFS2Ext4fsStat/3-12      	10000000	       202 ns/op
BenchmarkVFS2Ext4fsStat/8-12      	 3000000	       374 ns/op
BenchmarkVFS2Ext4fsStat/64-12     	  500000	      2159 ns/op
BenchmarkVFS2Ext4fsStat/100-12    	  300000	      3459 ns/op

BenchmarkVFS1TmpfsStat/1-12       	 5000000	       348 ns/op
BenchmarkVFS1TmpfsStat/2-12       	 3000000	       487 ns/op
BenchmarkVFS1TmpfsStat/3-12       	 2000000	       655 ns/op
BenchmarkVFS1TmpfsStat/8-12       	 1000000	      1365 ns/op
BenchmarkVFS1TmpfsStat/64-12      	  200000	      9565 ns/op
BenchmarkVFS1TmpfsStat/100-12     	  100000	     15158 ns/op

BenchmarkVFS2MemfsStat/1-12       	10000000	       133 ns/op
BenchmarkVFS2MemfsStat/2-12       	10000000	       155 ns/op
BenchmarkVFS2MemfsStat/3-12       	10000000	       182 ns/op
BenchmarkVFS2MemfsStat/8-12       	 5000000	       310 ns/op
BenchmarkVFS2MemfsStat/64-12      	 1000000	      1659 ns/op
BenchmarkVFS2MemfsStat/100-12     	  500000	      2787 ns/op

Mount Stat benchmarks
BenchmarkVFS2ExtfsMountStat/1-12  	 5000000	       245 ns/op
BenchmarkVFS2ExtfsMountStat/2-12  	 5000000	       266 ns/op
BenchmarkVFS2ExtfsMountStat/3-12  	 5000000	       304 ns/op
BenchmarkVFS2ExtfsMountStat/8-12  	 3000000	       456 ns/op
BenchmarkVFS2ExtfsMountStat/64-12 	  500000	      2308 ns/op
BenchmarkVFS2ExtfsMountStat/100-12   300000	      3482 ns/op

BenchmarkVFS1TmpfsMountStat/1-12  	 3000000	       488 ns/op
BenchmarkVFS1TmpfsMountStat/2-12  	 2000000	       658 ns/op
BenchmarkVFS1TmpfsMountStat/3-12  	 2000000	       806 ns/op
BenchmarkVFS1TmpfsMountStat/8-12  	 1000000	      1514 ns/op
BenchmarkVFS1TmpfsMountStat/64-12 	  100000	     10037 ns/op
BenchmarkVFS1TmpfsMountStat/100-12        100000	     15280 ns/op

BenchmarkVFS2MemfsMountStat/1-12           	10000000	       212 ns/op
BenchmarkVFS2MemfsMountStat/2-12           	 5000000	       232 ns/op
BenchmarkVFS2MemfsMountStat/3-12           	 5000000	       264 ns/op
BenchmarkVFS2MemfsMountStat/8-12           	 3000000	       390 ns/op
BenchmarkVFS2MemfsMountStat/64-12          	 1000000	      1813 ns/op
BenchmarkVFS2MemfsMountStat/100-12         	  500000	      2812 ns/op

PiperOrigin-RevId: 262477158
2019-08-08 18:45:37 -07:00
Rahat Mahmood 7bfad8ebb6 Return a well-defined socket address type from socket funtions.
Previously we were representing socket addresses as an interface{},
which allowed any type which could be binary.Marshal()ed to be used as
a socket address. This is fine when the address is passed to userspace
via the linux ABI, but is problematic when used from within the sentry
such as by networking procfs files.

PiperOrigin-RevId: 262460640
2019-08-08 16:50:33 -07:00
Rahat Mahmood 13a98df49e netstack: Don't start endpoint goroutines too soon on restore.
Endpoint protocol goroutines were previously started as part of
loading the endpoint. This is potentially too soon, as resources used
by these goroutine may not have been loaded. Protocol goroutines may
perform meaningful work as soon as they're started (ex: incoming
connect) which can cause them to indirectly access resources that
haven't been loaded yet.

This CL defers resuming all protocol goroutines until the end of
restore.

PiperOrigin-RevId: 262409429
2019-08-08 12:33:11 -07:00
gVisor bot 2e45d1696e Merge pull request #653 from xiaobo55x:dev
PiperOrigin-RevId: 262402929
2019-08-08 11:58:14 -07:00
Jamie Liu 06102af65a memfs fixes.
- Unexport Filesystem/Dentry/Inode.

- Support SEEK_CUR in directoryFD.Seek().

- Hold Filesystem.mu before touching directoryFD.off in
directoryFD.Seek().

- Remove deleted Dentries from their parent directory.childLists.

- Remove invalid FIXMEs.

PiperOrigin-RevId: 262400633
2019-08-08 11:46:38 -07:00
Ayush Ranjan 08cd5e1d36 ext: Seek unit tests.
PiperOrigin-RevId: 262264674
2019-08-07 19:13:41 -07:00
Ayush Ranjan 40d6d8c15b ext: StatAt unit tests.
PiperOrigin-RevId: 262249166
2019-08-07 17:21:00 -07:00
Ayush Ranjan 3b368cabf9 ext: Read unit tests.
PiperOrigin-RevId: 262242410
2019-08-07 16:44:10 -07:00
Ayush Ranjan ad67e5a7a0 ext: IterDirent unit tests.
PiperOrigin-RevId: 262226761
2019-08-07 15:24:33 -07:00