Commit Graph

1421 Commits

Author SHA1 Message Date
Dean Deng ad9f469174 Fix bugs in vfs2 to make symlink tests pass.
- Return ENOENT if target path is empty.
- Make sure open(2) with O_CREAT|O_EXCL returns EEXIST when necessary.
- Correctly update atime in tmpfs using touchATime().

Updates #2923.

PiperOrigin-RevId: 317382655
2020-06-19 14:41:14 -07:00
Dean Deng 8655fb7248 Fix vfs2 proc/self/fd dirent iteration.
Make proc/self/fd iteration work properly. Also, the comment on
kernfs.Inode.IterDirents did not accurately reflect how parameters should be
used/were used in kernfs.Inode impls other than fdDir.

Updates #2923.

PiperOrigin-RevId: 317370325
2020-06-19 13:36:18 -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
gVisor bot d962f9f384 Implement UDP cheksum verification.
Test:
 - TestIncrementChecksumErrors

Fixes #2943

PiperOrigin-RevId: 317348158
2020-06-19 11:43:20 -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 6b69b955d7 Support all seek options in gofer specialFileFD.Seek.
Updates #2923.

PiperOrigin-RevId: 317298186
2020-06-19 06:39:09 -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
Andrei Vagin 70c45e09cf socket/unix: (*connectionedEndpoint).State() has to take the endpoint lock
It accesses e.receiver which is protected by the endpoint lock.

WARNING: DATA RACE
Write at 0x00c0006aa2b8 by goroutine 189:
  pkg/sentry/socket/unix/transport.(*connectionedEndpoint).Connect.func1()
      pkg/sentry/socket/unix/transport/connectioned.go:359 +0x50
  pkg/sentry/socket/unix/transport.(*connectionedEndpoint).BidirectionalConnect()
      pkg/sentry/socket/unix/transport/connectioned.go:327 +0xa3c
  pkg/sentry/socket/unix/transport.(*connectionedEndpoint).Connect()
      pkg/sentry/socket/unix/transport/connectioned.go:363 +0xca
  pkg/sentry/socket/unix.(*socketOpsCommon).Connect()
      pkg/sentry/socket/unix/unix.go:420 +0x13a
  pkg/sentry/socket/unix.(*SocketOperations).Connect()
      <autogenerated>:1 +0x78
  pkg/sentry/syscalls/linux.Connect()
      pkg/sentry/syscalls/linux/sys_socket.go:286 +0x251

Previous read at 0x00c0006aa2b8 by goroutine 270:
  pkg/sentry/socket/unix/transport.(*baseEndpoint).Connected()
      pkg/sentry/socket/unix/transport/unix.go:789 +0x42
  pkg/sentry/socket/unix/transport.(*connectionedEndpoint).State()
      pkg/sentry/socket/unix/transport/connectioned.go:479 +0x2f
  pkg/sentry/socket/unix.(*socketOpsCommon).State()
      pkg/sentry/socket/unix/unix.go:714 +0xc3e
  pkg/sentry/socket/unix.(*socketOpsCommon).SendMsg()
      pkg/sentry/socket/unix/unix.go:466 +0xc44
  pkg/sentry/socket/unix.(*SocketOperations).SendMsg()
      <autogenerated>:1 +0x173
  pkg/sentry/syscalls/linux.sendTo()
      pkg/sentry/syscalls/linux/sys_socket.go:1121 +0x4c5
  pkg/sentry/syscalls/linux.SendTo()
      pkg/sentry/syscalls/linux/sys_socket.go:1134 +0x87

Reported-by: syzbot+c2be37eedc672ed59a86@syzkaller.appspotmail.com
PiperOrigin-RevId: 317236996
2020-06-18 20:28:10 -07:00
Kevin Krakauer 28b8a5cc3a iptables: remove metadata struct
Metadata was useful for debugging and safety, but enough tests exist that we
should see failures when (de)serialization is broken. It made stack
initialization more cumbersome and it's also getting in the way of ip6tables.

PiperOrigin-RevId: 317210653
2020-06-18 17:02:16 -07:00
Ting-Yu Wang f97122f44c Acquire lock when accessing MultiDevice's cache in String().
PiperOrigin-RevId: 317180925
2020-06-18 14:29:42 -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
Fabricio Voznika 6e0c170522 Implement Sync() to directories
Updates #1035, #1199

PiperOrigin-RevId: 317028108
2020-06-17 21:22:16 -07:00
gVisor bot a5f4deeca7 Internal change.
PiperOrigin-RevId: 316973783
2020-06-17 15:10:40 -07:00
Michael Pratt 6d806ee719 Remove various uses of 'blacklist'
Updates #2972

PiperOrigin-RevId: 316942245
2020-06-17 12:34:33 -07:00
Dean Deng e5d97cbcc1 Refactor host.canMap.
Simplify the canMap check. We do not have plans to allow mmap for anything
beyond regular files, so we can just inline canMap() as a simple file mode
check.

Updates #1672.

PiperOrigin-RevId: 316929654
2020-06-17 11:34:06 -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
Jamie Liu e61acfb5ea Correctly handle multiple resizings in pgalloc.findAvailableRange().
PiperOrigin-RevId: 316778032
2020-06-16 16:16:14 -07:00
Nicolas Lacasse 810748f5c9 Port aio to VFS2.
In order to make sure all aio goroutines have stopped during S/R, a new
WaitGroup was added to TaskSet, analagous to runningGoroutines. This WaitGroup
is incremented with each aio goroutine, and waited on during kernel.Pause.

The old VFS1 aio code was changed to use this new WaitGroup, rather than
fs.Async. The only uses of fs.Async are now inode and mount Release operations,
which do not call fs.Async recursively. This fixes a lock-ordering violation
that can cause deadlocks.

Updates #1035.

PiperOrigin-RevId: 316689380
2020-06-16 08:49:06 -07:00
Jamie Liu 3b0b1f104d Miscellaneous VFS2 fixes.
PiperOrigin-RevId: 316627764
2020-06-16 00:15:20 -07:00
Andrei Vagin 6ec9d60403 vfs2: implement fcntl(fd, F_SETFL, flags)
PiperOrigin-RevId: 316148074
2020-06-12 11:58:15 -07:00
Jamie Liu 77c206e371 Add //pkg/sentry/fsimpl/overlay.
Major differences from existing overlay filesystems:

- Linux allows lower layers in an overlay to require revalidation, but not the
  upper layer. VFS1 allows the upper layer in an overlay to require
  revalidation, but not the lower layer. VFS2 does not allow any layers to
  require revalidation. (Now that vfs.MkdirOptions.ForSyntheticMountpoint
  exists, no uses of overlay in VFS1 are believed to require upper layer
  revalidation; in particular, the requirement that the upper layer support the
  creation of "trusted." extended attributes for whiteouts effectively required
  the upper filesystem to be tmpfs in most cases.)

- Like VFS1, but unlike Linux, VFS2 overlay does not attempt to make mutations
  of the upper layer atomic using a working directory and features like
  RENAME_WHITEOUT. (This may change in the future, since not having a working
  directory makes error recovery for some operations, e.g. rmdir, particularly
  painful.)

- Like Linux, but unlike VFS1, VFS2 represents whiteouts using character
  devices with rdev == 0; the equivalent of the whiteout attribute on
  directories is xattr trusted.overlay.opaque = "y"; and there is no equivalent
  to the whiteout attribute on non-directories since non-directories are never
  merged with lower layers.

- Device and inode numbers work as follows:

    - In Linux, modulo the xino feature and a special case for when all layers
      are the same filesystem:

        - Directories use the overlay filesystem's device number and an
          ephemeral inode number assigned by the overlay.

        - Non-directories that have been copied up use the device and inode
          number assigned by the upper filesystem.

        - Non-directories that have not been copied up use a per-(overlay,
          layer)-pair device number and the inode number assigned by the lower
          filesystem.

    - In VFS1, device and inode numbers always come from the lower layer unless
      "whited out"; this has the adverse effect of requiring interaction with
      the lower filesystem even for non-directory files that exist on the upper
      layer.

    - In VFS2, device and inode numbers are assigned as in Linux, except that
      xino and the samefs special case are not supported.

- Like Linux, but unlike VFS1, VFS2 does not attempt to maintain memory mapping
  coherence across copy-up. (This may have to change in the future, as users
  may be dependent on this property.)

- Like Linux, but unlike VFS1, VFS2 uses the overlayfs mounter's credentials
  when interacting with the overlay's layers, rather than the caller's.

- Like Linux, but unlike VFS1, VFS2 permits multiple lower layers in an
  overlay.

- Like Linux, but unlike VFS1, VFS2's overlay filesystem is
  application-mountable.

Updates #1199

PiperOrigin-RevId: 316019067
2020-06-11 18:34:53 -07:00
gVisor bot 4f111b6384 Merge pull request #2863 from lubinszARM:pr_sndbuf
PiperOrigin-RevId: 315991648
2020-06-11 15:36:43 -07:00
Fabricio Voznika d58d57606a Don't copy structs with sync.Mutex during initialization
During inititalization inode struct was copied around, but
it isn't great pratice to copy it around since it contains
ref count and sync.Mutex.

Updates #1480

PiperOrigin-RevId: 315983788
2020-06-11 14:56:19 -07:00
Nicolas Lacasse a87c74bc54 Remove duplicate colon from warning log.
doAction()->log.TracebackAll() will append a colon.

PiperOrigin-RevId: 315842611
2020-06-10 23:23:07 -07:00
Bin Lu cbfb537eef Deleting the maxSendBufferSize from fs/host
When I do high-performance networking,
the value of wmem_max is often set very high,
specially for 10/25/50 Gigabit NIC.

I think maybe this restriction is not suitable.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-06-10 21:53:46 -04:00
gVisor bot b436b9717e Merge pull request #2711 from lubinszARM:pr_mmio
PiperOrigin-RevId: 315812219
2020-06-10 18:51:41 -07:00
gVisor bot 508e7c3a79 Merge pull request #2763 from gaurav1086:sentry_kernel_timekeeper_use_buffered_channel
PiperOrigin-RevId: 315803553
2020-06-10 17:43:16 -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
gVisor bot 6d43ac9574 Merge pull request #2787 from lubinszARM:pr_race_time
PiperOrigin-RevId: 315734425
2020-06-10 11:45:16 -07:00
Fabricio Voznika 203dc121f6 Redirect TODOs to more specific issues
Closes #1623

PiperOrigin-RevId: 315681993
2020-06-10 06:51:32 -07:00
Gaurav Singh f1f85f475d sentry: use defer wg.Done() unconditionally
Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
2020-06-09 22:56:39 -04: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 52c922f7c0 Merge pull request #2712 from lubinszARM:pr_sigfp_init
PiperOrigin-RevId: 315599736
2020-06-09 18:05:01 -07:00
gVisor bot e3cbfbf349 Merge pull request #2907 from lubinszARM:pr_minor
PiperOrigin-RevId: 315595602
2020-06-09 17:34:41 -07:00
Fabricio Voznika 6722b1e56f Don't WriteOut to readonly mounts
When the file closes, it attempts to write dirty cached
attributes to the file. This should not be done when the
mount is readonly.

PiperOrigin-RevId: 315585058
2020-06-09 16:36:56 -07:00
Jamie Liu ecff24930c Ensure pgalloc.MemoryFile.fileSize is always chunk-aligned.
findAvailableLocked() may return a non-aligned FileRange.End after expansion
since it may round FileRange.Start down to a hugepage boundary.

PiperOrigin-RevId: 315520321
2020-06-09 11:16:05 -07:00
Bin Lu b792cc1ca9 minor change in kvm module for Arm64
Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-06-09 05:42:41 -04:00
Bin Lu 5ad1025d2d initialize an empty fp state area for sentry on Arm64
We need to initialize an empty fp state area for the sentry.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-06-09 05:01:03 -04:00
Fabricio Voznika 4e96b94915 Combine executable lookup code
Run vs. exec, VFS1 vs. VFS2 were executable lookup were
slightly different from each other. Combine them all
into the same logic.

PiperOrigin-RevId: 315426443
2020-06-08 23:08:23 -07:00
Jamie Liu dc029b4b96 Implement VFS2 tmpfs mount options.
As in VFS1, the mode, uid, and gid options are supported.

Updates #1197

PiperOrigin-RevId: 315340510
2020-06-08 13:28:18 -07:00
Kevin Krakauer 32b823fcdb netstack: parse incoming packet headers up-front
Netstack has traditionally parsed headers on-demand as a packet moves up the
stack. This is conceptually simple and convenient, but incompatible with
iptables, where headers can be inspected and mangled before even a routing
decision is made.

This changes header parsing to happen early in the incoming packet path, as soon
as the NIC gets the packet from a link endpoint. Even if an invalid packet is
found (e.g. a TCP header of insufficient length), the packet is passed up the
stack for proper stats bookkeeping.

PiperOrigin-RevId: 315179302
2020-06-07 13:38:43 -07:00
Rahat Mahmood 21b6bc7280 Implement mount(2) and umount2(2) for VFS2.
This is mostly syscall plumbing, VFS2 already implements the internals of
mounts. In addition to the syscall defintions, the following mount-related
mechanisms are updated:

- Implement MS_NOATIME for VFS2, but only for tmpfs and goferfs. The other VFS2
  filesystems don't implement node-level timestamps yet.

- Implement the 'mode', 'uid' and 'gid' mount options for VFS2's tmpfs.

- Plumb mount namespace ownership, which is necessary for checking appropriate
  capabilities during mount(2).

Updates #1035

PiperOrigin-RevId: 315035352
2020-06-05 19:12:03 -07:00
Adin Scannell 527d08f6af Add +checkescape annotations to kvm/ring0.
This analysis also catches a potential bug, which is a split on mapPhysical.
This would have led to potential guest-exit during Mapping (although this
would have been handled by the now-unecessary retryInGuest loop).

PiperOrigin-RevId: 315025106
2020-06-05 17:25:28 -07:00
Adin Scannell 9aaca5a6da Use top-down allocation for pgalloc.
This change has multiple small components.

First, the chunk size is bumped to 1GB in order to avoid creating excessive
VMAs in the Sentry, which can lead to VMA exhaustion (and hitting limits).

Second, gap-tracking is added to the usage set in order to efficiently scan
for available regions.

Third, reclaim is moved to a simple segment set. This is done to allow the
order of reclaim to align with the Allocate order (which becomes much more
complex when trying to track a "max page" as opposed to "min page", so we
just track explicit segments instead, which should make reclaim scanning
faster anyways).

Finally, the findAvailable function attempts to scan from the top-down, in
order to maximize opportunities for VMA merging in applications (hopefully
preventing the same VMA exhaustion that can affect the Sentry).

PiperOrigin-RevId: 315009249
2020-06-05 15:39:57 -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