Commit Graph
367 Commits
Author SHA1 Message Date
Dean DengandgVisor bot c317e94de6 Add missing error checks for FileDescription.Init.
Syzkaller discovered this bug in pipefs by doing something quite strange:
creat(&(0x7f0000002a00)='./file1\x00', 0x0)
mount(&(0x7f0000000440)=ANY=[], &(0x7f00000002c0)='./file1\x00', &(0x7f0000000300)='devtmpfs\x00', 0x20000d, 0x0)
creat(&(0x7f0000000000)='./file1/file0\x00', 0x0)

This can be reproduced with:
touch mymount
mkfifo /dev/mypipe
mount -o ro -t devtmpfs devtmpfs mymount
echo 123 > mymount/mypipe

PiperOrigin-RevId: 349687714
2020-12-31 09:51:01 -08:00
Jing ChenandgVisor bot 070e277b6e Implement command SEM_INFO and SEM_STAT for semctl.
PiperOrigin-RevId: 347711998
2020-12-15 16:06:06 -08:00
Dean DengandgVisor bot a2a83f840c Do not check for reference leaks after saving.
We should not assert that all resources are dropped after saving.

PiperOrigin-RevId: 347420131
2020-12-14 10:47:01 -08:00
Adin ScannellandgVisor bot 69f0412910 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Jing ChenandgVisor bot a0854b0b3a Make semctl IPC_INFO cmd return the index of highest used entry.
PiperOrigin-RevId: 346973338
2020-12-11 04:22:04 -08:00
Jing ChenandgVisor bot 9b1bf422a0 Implement command IPC_INFO for semctl.
PiperOrigin-RevId: 345589628
2020-12-03 19:57:51 -08:00
Etienne PerotandgVisor bot c4cee5ea31 Implement fcntl options F_GETSIG and F_SETSIG.
These options allow overriding the signal that gets sent to the process when
I/O operations are available on the file descriptor, rather than the default
`SIGIO` signal. Doing so also populates `siginfo` to contain extra information
about which file descriptor caused the event (`si_fd`) and what events happened
on it (`si_band`). The logic around which FD is populated within `si_fd`
matches Linux's, which means it has some weird edge cases where that value may
not actually refer to a file descriptor that is still valid.

This CL also ports extra S/R logic regarding async handler in VFS2.
Without this, async I/O handlers aren't properly re-registered after S/R.

PiperOrigin-RevId: 345436598
2020-12-03 06:20:29 -08:00
Jamie LiuandgVisor bot ed038bb8ef Do not unconditionally allocate in kernel.FDTable.setAll().
`slice := *(*[]unsafe.Pointer)(...)` makes a copy of the slice header, which
then escapes because of the conditional `atomic.StorePointer(&f.slice, &slice)`
from table expansion. This occurs even when the table doesn't expand, and when
it can't (e.g. `close()` => `f.setAll(nil)`). Fix this by avoiding the copy
until after table expansion.

Before this CL:
```
TEXT pkg/sentry/kernel/kernel.(*FDTable).setAll(SB) pkg/sentry/kernel/fd_table_unsafe.go
  fd_table_unsafe.go:119        0x7f00005f50e0          64488b0c25f8ffffff              MOVQ FS:0xfffffff8, CX
  fd_table_unsafe.go:119        0x7f00005f50e9          483b6110                        CMPQ 0x10(CX), SP
  fd_table_unsafe.go:119        0x7f00005f50ed          0f864d040000                    JBE 0x7f00005f5540
  fd_table_unsafe.go:119        0x7f00005f50f3          4883c480                        ADDQ $-0x80, SP
  fd_table_unsafe.go:119        0x7f00005f50f7          48896c2478                      MOVQ BP, 0x78(SP)
  fd_table_unsafe.go:119        0x7f00005f50fc          488d6c2478                      LEAQ 0x78(SP), BP
  fd_table_unsafe.go:120        0x7f00005f5101          488b8424a8000000                MOVQ 0xa8(SP), AX
  fd_table_unsafe.go:120        0x7f00005f5109          4885c0                          TESTQ AX, AX
  fd_table_unsafe.go:120        0x7f00005f510c          7411                            JE 0x7f00005f511f
  fd_table_unsafe.go:120        0x7f00005f510e          488b8c24b0000000                MOVQ 0xb0(SP), CX
  fd_table_unsafe.go:120        0x7f00005f5116          4885c9                          TESTQ CX, CX
  fd_table_unsafe.go:120        0x7f00005f5119          0f8500040000                    JNE 0x7f00005f551f
  fd_table_unsafe.go:124        0x7f00005f511f          488d05da115700                  LEAQ 0x5711da(IP), AX
  fd_table_unsafe.go:124        0x7f00005f5126          48890424                        MOVQ AX, 0(SP)
  fd_table_unsafe.go:124        0x7f00005f512a          e8d19fa1ff                      CALL runtime.newobject(SB)
  fd_table_unsafe.go:124        0x7f00005f512f          488b7c2408                      MOVQ 0x8(SP), DI
  fd_table_unsafe.go:124        0x7f00005f5134          488b842488000000                MOVQ 0x88(SP), AX
  fd_table_unsafe.go:124        0x7f00005f513c          488b4820                        MOVQ 0x20(AX), CX
  fd_table_unsafe.go:124        0x7f00005f5140          488b5108                        MOVQ 0x8(CX), DX
  fd_table_unsafe.go:124        0x7f00005f5144          488b19                          MOVQ 0(CX), BX
  fd_table_unsafe.go:124        0x7f00005f5147          488b4910                        MOVQ 0x10(CX), CX
  fd_table_unsafe.go:124        0x7f00005f514b          48895708                        MOVQ DX, 0x8(DI)
  fd_table_unsafe.go:124        0x7f00005f514f          48894f10                        MOVQ CX, 0x10(DI)
  fd_table_unsafe.go:124        0x7f00005f5153          833df6e1120100                  CMPL $0x0, runtime.writeBarrier(SB)
  fd_table_unsafe.go:124        0x7f00005f515a          660f1f440000                    NOPW 0(AX)(AX*1)
  fd_table_unsafe.go:124        0x7f00005f5160          0f8589030000                    JNE 0x7f00005f54ef
  fd_table_unsafe.go:124        0x7f00005f5166          48891f                          MOVQ BX, 0(DI)
  fd_table_unsafe.go:124        0x7f00005f5169          48897c2470                      MOVQ DI, 0x70(SP)
  fd_table_unsafe.go:127        0x7f00005f516e          8bb424a0000000                  MOVL 0xa0(SP), SI
  fd_table_unsafe.go:127        0x7f00005f5175          39d6                            CMPL DX, SI
  fd_table_unsafe.go:127        0x7f00005f5177          0f8c5f030000                    JL 0x7f00005f54dc
  ...
```

After this CL:
```
TEXT pkg/sentry/kernel/kernel.(*FDTable).setAll(SB) pkg/sentry/kernel/fd_table_unsafe.go
  fd_table_unsafe.go:119        0x7f00005f50e0          64488b0c25f8ffffff              MOVQ FS:0xfffffff8, CX
  fd_table_unsafe.go:119        0x7f00005f50e9          488d4424e8                      LEAQ -0x18(SP), AX
  fd_table_unsafe.go:119        0x7f00005f50ee          483b4110                        CMPQ 0x10(CX), AX
  fd_table_unsafe.go:119        0x7f00005f50f2          0f868e040000                    JBE 0x7f00005f5586
  fd_table_unsafe.go:119        0x7f00005f50f8          4881ec98000000                  SUBQ $0x98, SP
  fd_table_unsafe.go:119        0x7f00005f50ff          4889ac2490000000                MOVQ BP, 0x90(SP)
  fd_table_unsafe.go:119        0x7f00005f5107          488dac2490000000                LEAQ 0x90(SP), BP
  fd_table_unsafe.go:120        0x7f00005f510f          488b9424c0000000                MOVQ 0xc0(SP), DX
  fd_table_unsafe.go:120        0x7f00005f5117          660f1f840000000000              NOPW 0(AX)(AX*1)
  fd_table_unsafe.go:120        0x7f00005f5120          4885d2                          TESTQ DX, DX
  fd_table_unsafe.go:120        0x7f00005f5123          0f8406040000                    JE 0x7f00005f552f
  fd_table_unsafe.go:120        0x7f00005f5129          488b9c24c8000000                MOVQ 0xc8(SP), BX
  fd_table_unsafe.go:120        0x7f00005f5131          4885db                          TESTQ BX, BX
  fd_table_unsafe.go:120        0x7f00005f5134          0f852b040000                    JNE 0x7f00005f5565
  fd_table_unsafe.go:124        0x7f00005f513a          488bb424a0000000                MOVQ 0xa0(SP), SI
  fd_table_unsafe.go:124        0x7f00005f5142          488b7e20                        MOVQ 0x20(SI), DI
  fd_table_unsafe.go:127        0x7f00005f5146          4c8b4708                        MOVQ 0x8(DI), R8
  fd_table_unsafe.go:127        0x7f00005f514a          448b8c24b8000000                MOVL 0xb8(SP), R9
  fd_table_unsafe.go:127        0x7f00005f5152          4539c1                          CMPL R8, R9
  fd_table_unsafe.go:127        0x7f00005f5155          0f8d4a020000                    JGE 0x7f00005f53a5
  ...
```

PiperOrigin-RevId: 345363242
2020-12-02 19:40:43 -08:00
Jing ChenandgVisor bot b82778c4f6 Add /proc/sys/kernel/sem.
PiperOrigin-RevId: 345178956
2020-12-02 00:13:24 -08:00
Etienne PerotandgVisor bot d55758ca7b Add a few syslog messages.
PiperOrigin-RevId: 343123278
2020-11-18 11:46:23 -08:00
Jamie LiuandgVisor bot 9da6db2a5f Reset watchdog timer between sendfile() iterations.
As part of this, change Task.interrupted() to not drain Task.interruptChan, and
do so explicitly using new function Task.unsetInterrupted() instead.

PiperOrigin-RevId: 342768365
2020-11-16 18:55:24 -08:00
Jamie LiuandgVisor bot a80a6e7377 Log task goroutine IDs in the sentry watchdog.
PiperOrigin-RevId: 342373580
2020-11-13 18:10:55 -08:00
Jamie LiuandgVisor bot dd10c5f8d4 Check for misuse of kernel.Task as context.Context.
Checks in Task.block() and Task.Value() are conditional on race detection being
enabled, since these functions are relatively hot. Checks in Task.SleepStart()
and Task.UninterruptibleSleepStart() are enabled unconditionally, since these
functions are not thought to lie on any critical paths, and misuse of these
functions is required for b/168241471 to manifest.

PiperOrigin-RevId: 342342175
2020-11-13 14:47:47 -08:00
Jamie LiuandgVisor bot 1e4a0f830a Fix misuses of kernel.Task as context.Context.
kernel.Task can only be used as context.Context by that Task's task goroutine.
This is violated in at least two places:

- In any case where one thread accesses the /proc/[tid] of any other thread,
  passing the kernel.Task for [tid] as the context.Context is incorrect.

- Task.rebuildTraceContext() may be called by Kernel.RebuildTraceContexts()
  outside the scope of any task goroutine.

Fix these (as well as a data race on Task.traceContext discovered during the
course of finding the latter).

PiperOrigin-RevId: 342174404
2020-11-12 18:22:40 -08:00
Jamie LiuandgVisor bot 0dede4687f Rename kernel.TaskContext to kernel.TaskImage.
This reduces confusion with context.Context (which is also relevant to
kernel.Tasks) and is consistent with existing function kernel.LoadTaskImage().

PiperOrigin-RevId: 342167298
2020-11-12 17:39:19 -08:00
Dean DengandgVisor bot b2a3d29eac Initialize references with a value of 1.
This lets us avoid treating a value of 0 as one reference. All references
using the refsvfs2 template must call InitRefs() before the reference is
incremented/decremented, or else a panic will occur. Therefore, it should be
pretty easy to identify missing InitRef calls during testing.

Updates #1486.

PiperOrigin-RevId: 341411151
2020-11-09 08:33:17 -08:00
Jing ChenandgVisor bot 56ccd9aad9 Implement command GETNCNT for semctl.
PiperOrigin-RevId: 341154192
2020-11-06 18:38:13 -08:00
Ting-Yu WangandgVisor bot ec5fb69513 Fix more nogo tests
PiperOrigin-RevId: 340536306
2020-11-03 15:23:32 -08:00
Nicolas LacasseandgVisor bot 90c5aab225 Make pipe min/max sizes match linux.
The default pipe size already matched linux, and is unchanged.

Furthermore `atomicIOBytes` is made a proper constant (as it is in Linux). We
were plumbing usermem.PageSize everywhere, so this is no functional change.

PiperOrigin-RevId: 340497006
2020-11-03 12:12:06 -08:00
Jing ChenandgVisor bot 3e67015622 Implement command GETZCNT for semctl.
PiperOrigin-RevId: 340389884
2020-11-02 23:58:45 -08:00
Jamie LiuandgVisor bot 4f9be2d6d4 Separate kernel.Task.AsCopyContext() into CopyContext() and OwnCopyContext().
kernel.copyContext{t} cannot be used outside of t's task goroutine, for three
reasons:

- t.CopyScratchBuffer() is task-goroutine-local.

- Calling t.MemoryManager() without running on t's task goroutine or locking
  t.mu violates t.MemoryManager()'s preconditions.

- kernel.copyContext passes t as context.Context to MM IO methods, which is
  illegal outside of t's task goroutine (cf. kernel.Task.Value()).

Fix this by splitting AsCopyContext() into CopyContext() (which takes an
explicit context.Context and is usable outside of the task goroutine) and
OwnCopyContext() (which uses t as context.Context, but is only usable by t's
task goroutine).

PiperOrigin-RevId: 339933809
2020-10-30 13:54:47 -07:00
Jing ChenandgVisor bot faa7abcddb Implement command IPC_STAT for semctl.
PiperOrigin-RevId: 339166854
2020-10-26 19:26:42 -07:00
Jamie LiuandgVisor bot 114d68adb8 Support VFS2 save/restore.
Inode number consistency checks are now skipped in save/restore tests for
reasons described in greatest detail in StatTest.StateDoesntChangeAfterRename.
They pass in VFS1 due to the bug described in new test case
SimpleStatTest.DifferentFilesHaveDifferentDeviceInodeNumberPairs.

Fixes #1663

PiperOrigin-RevId: 338776148
2020-10-23 17:48:33 -07:00
Dean DengandgVisor bot f6aa673ece Rewrite reference leak checker without finalizers.
Our current reference leak checker uses finalizers to verify whether an object
has reached zero references before it is garbage collected. There are multiple
problems with this mechanism, so a rewrite is in order.

With finalizers, there is no way to guarantee that a finalizer will run before
the program exits. When an unreachable object with a finalizer is garbage
collected, its finalizer will be added to a queue and run asynchronously. The
best we can do is run garbage collection upon sandbox exit to make sure that
all finalizers are enqueued.

Furthermore, if there is a chain of finalized objects, e.g. A points to B
points to C, garbage collection needs to run multiple times before all of the
finalizers are enqueued. The first GC run will register the finalizer for A but
not free it. It takes another GC run to free A, at which point B's finalizer
can be registered. As a result, we need to run GC as many times as the length
of the longest such chain to have a somewhat reliable leak checker.

Finally, a cyclical chain of structs pointing to one another will never be
garbage collected if a finalizer is set. This is a well-known issue with Go
finalizers (https://github.com/golang/go/issues/7358). Using leak checking on
filesystem objects that produce cycles will not work and even result in memory
leaks.

The new leak checker stores reference counted objects in a global map when
leak check is enabled and removes them once they are destroyed. At sandbox
exit, any remaining objects in the map are considered as leaked. This provides
a deterministic way of detecting leaks without relying on the complexities of
finalizers and garbage collection.

This approach has several benefits over the former, including:
- Always detects leaks of objects that should be destroyed very close to
  sandbox exit. The old checker very rarely detected these leaks, because it
  relied on garbage collection to be run in a short window of time.
- Panics if we forgot to enable leak check on a ref-counted object (we will try
  to remove it from the map when it is destroyed, but it will never have been
  added).
- Can store extra logging information in the map values without adding to the
  size of the ref count struct itself. With the size of just an int64, the ref
  count object remains compact, meaning frequent operations like IncRef/DecRef
  are more cache-efficient.
- Can aggregate leak results in a single report after the sandbox exits.
  Instead of having warnings littered in the log, which were
  non-deterministically triggered by garbage collection, we can print all
  warning messages at once. Note that this could also be a limitation--the
  sandbox must exit properly for leaks to be detected.

Some basic benchmarking indicates that this change does not significantly
affect performance when leak checking is enabled, which is understandable
since registering/unregistering is only done once for each filesystem object.

Updates #1486.

PiperOrigin-RevId: 338685972
2020-10-23 09:17:02 -07:00
Dean DengandgVisor bot c6c07be595 Check for nil in kernel.FSContext functions.
Reported-by: [email protected]
PiperOrigin-RevId: 338386575
2020-10-21 19:16:56 -07:00
Dean DengandgVisor bot 85b9dce06e Fix reference counting on kcov mappings.
Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 337973519
2020-10-19 18:09:39 -07:00
Jamie LiuandgVisor bot c9711f5275 Fix runsc tests on VFS2 overlay.
- Check the sticky bit in overlay.filesystem.UnlinkAt(). Fixes
  StickyTest.StickyBitPermDenied.

- When configuring a VFS2 overlay in runsc, copy the lower layer's root
  owner/group/mode to the upper layer's root (as in the VFS1 equivalent,
  boot.addOverlay()). This makes the overlay root owned by UID/GID 65534 with
  mode 0755 rather than owned by UID/GID 0 with mode 01777. Fixes
  CreateTest.CreateFailsOnUnpermittedDir, which assumes that the test cannot
  create files in /.

- MknodTest.UnimplementedTypesReturnError assumes that the creation of device
  special files is not supported. However, while the VFS2 gofer client still
  doesn't support device special files, VFS2 tmpfs does, and in the overlay
  test dimension mknod() targets a tmpfs upper layer. The test initially has
  all capabilities, including CAP_MKNOD, so its creation of these files
  succeeds. Constrain these tests to VFS1.

- Rename overlay.nonDirectoryFD to overlay.regularFileFD and only use it for
  regular files, using the original FD for pipes and device special files. This
  is more consistent with Linux (which gets the original inode_operations, and
  therefore file_operations, for these file types from ovl_fill_inode() =>
  init_special_inode()) and fixes remaining mknod and pipe tests.

- Read/write 1KB at a time in PipeTest.Streaming, rather than 4 bytes. This
  isn't strictly necessary, but it makes the test less obnoxiously slow on
  ptrace.

Fixes #4407

PiperOrigin-RevId: 337971042
2020-10-19 17:48:02 -07:00
Dean DengandgVisor bot b2ee1accb2 [vfs2] Fix fork reference leaks.
PiperOrigin-RevId: 337919424
2020-10-19 13:20:13 -07:00
Dean DengandgVisor bot 61a20003c0 Fix shm reference leak.
All shm segments in an IPC namespace should be released once that namespace is
destroyed. Add reference counting to IPCNamespace so that once the last task
with a reference on it exits, we can trigger a destructor that will clean up
all shm segments that have not been explicitly freed by the application.

PiperOrigin-RevId: 337032977
2020-10-14 00:13:21 -07:00
Dean DengandgVisor bot 5fd9ec997d [vfs2] Don't take reference in Task.MountNamespaceVFS2 and MountNamespace.Root.
This fixes reference leaks related to accidentally forgetting to DecRef()
after calling one or the other.

PiperOrigin-RevId: 336918922
2020-10-13 11:31:22 -07:00
Dean DengandgVisor bot a5d610ce8a Don't leak VDSO mappings.
PiperOrigin-RevId: 336822021
2020-10-13 00:14:15 -07:00
Dean DengandgVisor bot 790bdc8815 [vfs2] Don't leak disconnected mounts.
PiperOrigin-RevId: 336694658
2020-10-12 10:41:04 -07:00
Jamie LiuandgVisor bot 534c7f16e8 Reduce the cost of sysinfo(2).
- sysinfo(2) does not actually require a fine-grained breakdown of memory
  usage. Accordingly, instead of calling pgalloc.MemoryFile.UpdateUsage() to
  update the sentry's fine-grained memory accounting snapshot, just use
  pgalloc.MemoryFile.TotalUsage() (which is a single fstat(), and therefore far
  cheaper).

- Use the number of threads in the root PID namespace (i.e. globally) rather
  than in the task's PID namespace for consistency with Linux (which just reads
  global variable nr_threads), and add a new method to kernel.PIDNamespace to
  allow this to be read directly from an underlying map rather than requiring
  the allocation and population of an intermediate slice.

PiperOrigin-RevId: 336353100
2020-10-09 13:23:30 -07:00
Dean DengandgVisor bot a235ffe079 Simplify nil assignment in kcov.
PiperOrigin-RevId: 335548610
2020-10-05 19:05:26 -07:00
Dean DengandgVisor bot ff099e9178 Fix kcov enabling and disabling procedures.
- When the KCOV_ENABLE_TRACE ioctl is called with the trace kind KCOV_TRACE_PC,
  the kcov mode should be set to KCOV_*MODE*_TRACE_PC.
- When the owning task of kcov exits, the memory mapping should not be cleared
  so it can be used by other tasks.
- Add more tests (also tested on native Linux kcov).

PiperOrigin-RevId: 335202585
2020-10-03 09:26:25 -07:00
Rahat MahmoodandgVisor bot d4686df511 Convert uses of the binary package in kernel to go-marshal.
PiperOrigin-RevId: 335077195
2020-10-02 12:24:24 -07:00
Rahat MahmoodandgVisor bot 468f31e66f Replace remaining uses of reflection-based marshalling.
- Rewrite arch.Stack.{Push,Pop}. For the most part, stack now
  implements marshal.CopyContext and can be used as the target of
  marshal operations. Stack.Push had some extra logic for
  automatically null-terminating slices. This was only used for two
  specific types of slices, and is now handled explicitly.

- Delete usermem.CopyObject{In,Out}.

- Replace most remaining uses of the encoding/binary package with
  go-marshal. Most of these were using the binary package to compute
  the size of a struct, which go-marshal can directly replace. ~3 uses
  of the binary package remain. These aren't reasonably replaceable by
  go-marshal: for example one use is to construct the syscall
  trampoline for systrap.

- Fill out remaining convenience wrappers in the primitive package.

PiperOrigin-RevId: 334502375
2020-09-29 18:08:07 -07:00
gVisor bot bfade2b4ff Merge pull request #3875 from btw616:fix/issue-3874
PiperOrigin-RevId: 334428344
2020-09-29 11:51:10 -07:00
Dean DengandgVisor bot 9a1f29276a Clean up kcov.
Previously, we did not check the kcov mode when performing task work. As a
result, disabling kcov did not do anything.

Also avoid expensive atomic RMW when consuming coverage data. We don't need the
swap if the value is already zero (which is most of the time), and it is ok if
there are slight inconsistencies due to a race between coverage data generation
(incrementing the value) and consumption (reading a nonzero value and writing
zero).

PiperOrigin-RevId: 334049207
2020-09-27 15:33:51 -07:00
Adin ScannellandgVisor bot 75df87e081 Add basic stateify annotations.
Updates #1663

PiperOrigin-RevId: 333539293
2020-09-24 10:13:04 -07:00
Tiwei Bie 3fb942e23f Fix socket record leak in VFS2
VFS2 socket record is not removed from the system-wide
socket table when the socket is released, which will lead
to a memory leak. This patch fixes this issue.

Fixes: #3874

Signed-off-by: Tiwei Bie <[email protected]>
2020-09-24 14:16:12 +08:00
Tiwei Bie 43676012fa Rename kernel.SocketEntry to kernel.SocketRecord
SocketEntry can be confusing with the template types as the 'Entry'
is usually used as a suffix for list element types, e.g. socketEntry
in the same package. Suggested by Dean (@dean-deng).

Signed-off-by: Tiwei Bie <[email protected]>
2020-09-24 14:16:12 +08:00
Dean DengandgVisor bot fde5ec2a51 Handle EOF properly in splice/sendfile.
Use HandleIOErrorVFS2 instead of custom error handling.

PiperOrigin-RevId: 333227581
2020-09-22 22:31:24 -07:00
Dean DengandgVisor bot 9aeee34ccf Complete vfs2 implementation of fallocate.
This change includes overlay, special regular gofer files, and hostfs.

Fixes #3589.

PiperOrigin-RevId: 332330860
2020-09-17 15:38:44 -07:00
Rahat MahmoodandgVisor bot 18dc1d2ebe Rename marshal.Task to marshal.CopyContext.
CopyContext is a better name for the interface because from
go-marshal's perspective, the interface has nothing to do with a
task. A kernel.Task happens to implement the interface, but so can
other things like MemoryManager and IO sequences.

PiperOrigin-RevId: 331959678
2020-09-16 02:10:12 -07:00
Rahat MahmoodandgVisor bot c25d44649f Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Ian LewisandgVisor bot 3a8953921e Add support for OCI seccomp filters in the sandbox.
OCI configuration includes support for specifying seccomp filters. In runc,
these filter configurations are converted into seccomp BPF programs and loaded
into the kernel via libseccomp. runsc needs to be a static binary so, for
runsc, we cannot rely on a C library and need to implement the functionality
in Go.

The generator added here implements basic support for taking OCI seccomp
configuration and converting it into a seccomp BPF program with the same
behavior as a program generated by libseccomp.

- New conditional operations were added to pkg/seccomp to support operations
  available in OCI.
- AllowAny and AllowValue were renamed to MatchAny and EqualTo to better reflect
  that syscalls matching the conditionals result in the provided action not
  simply SCMP_RET_ALLOW.
- BuildProgram in pkg/seccomp no longer panics if provided an empty list of
  rules. It now builds a program with the architecture sanity check only.
- ProgramBuilder now allows adding labels that are unused. However, backwards
  jumps are still not permitted.

Fixes #510

PiperOrigin-RevId: 331938697
2020-09-15 23:19:17 -07:00
Nayana BidariandgVisor bot 187395c6e8 Release FDTable lock before dropping the fds.
This is needed for SO_LINGER, where close() is blocked for linger timeout and
we are holding the FDTable lock for the entire timeout which will not allow
us to create/delete other fds. We have to release the locks and then drop the
fds.

PiperOrigin-RevId: 331844185
2020-09-15 13:43:50 -07:00
Jamie LiuandgVisor bot a6156e40d0 Correct FDSize in /proc/[pid]/status.
In Linux, FDSize is fs/proc/array.c:task_state() => struct fdtable::max_fds,
which is set to the underlying array's length in fs/file.c:alloc_fdtable().

Follow-up changes:

- Remove FDTable.GetRefs() and FDTable.GetRefsVFS2(), which are unused.

- Reset FDTable.used to 0 during restore, since the subsequent calls to
  FDTable.setAll() increment it again, causing its value to be doubled. (After
  this CL, FDTable.used is only used to avoid reallocation in FDTable.GetFDs(),
  so this fix is not very visible.)

PiperOrigin-RevId: 331588190
2020-09-14 11:34:50 -07:00
Rahat MahmoodandgVisor bot 172800eed9 Move the 'marshal' and 'primitive' packages to the 'pkg' directory.
PiperOrigin-RevId: 331256608
2020-09-11 17:42:49 -07:00