Commit Graph

1708 Commits

Author SHA1 Message Date
gVisor bot ae59e52979 Merge pull request #3934 from avagin:feature/fuse
PiperOrigin-RevId: 332122081
2020-09-16 17:12:57 -07:00
Chong Cai 2868308555 Implement OpenAt() for verity fs
OpenAt() for verity fs is implemented by opening both the target file or
directory and the corresponding Merkle tree file in the underlying file
system. Generally they are only open for read. In allowRuntimeEnable
mode, the Merkle tree file is also open for write.

PiperOrigin-RevId: 332116423
2020-09-16 16:43:34 -07:00
Nayana Bidari b6d165fe98 Automated rollback of changelist 329526153
PiperOrigin-RevId: 332097286
2020-09-16 15:06:55 -07:00
Chong Cai 3749e70a69 Implement PRead for verity fs
PRead is implemented by read from the underlying file in blocks, and
verify each block. The verified contents are saved into the output
buffer.

PiperOrigin-RevId: 332092267
2020-09-16 14:45:39 -07:00
gVisor bot 49857849f9 Merge pull request #3893 from lubinszARM:pr_n1_03
PiperOrigin-RevId: 332069743
2020-09-16 13:03:01 -07:00
Jinmou Li c4c302a27e fuse: fix data race in fusefs Release()
fix #3956
2020-09-16 12:22:17 -07:00
Jinmou Li 70cf503b4c fuse: fix FUSE_RELEASE reply handling
fix #3963
2020-09-16 12:22:17 -07:00
Jinmou Li 5c080f07de Update fuse.md design doc with design details 2020-09-16 12:22:17 -07:00
Jinmou Li 96fb1e60c3 Fix FUSE connection control lock ordering and race in unit test 2020-09-16 12:22:17 -07:00
Andrei Vagin 3ea925a423 fuse: don't pass lock by value
copylocks: directory.go:34:7: Allocate passes lock by value:
fuse/fuse.directoryFD contains fuse/fuse.fileDescription contains
pkg/sentry/vfs/vfs.FileDescription contains pkg/sync/sync.Mutex
2020-09-16 12:22:17 -07:00
Andrei Vagin 92a020c798 fuse: fix a compile time error
readdir_test.cc:134:24: error: variable length arrays are a C99 feature [-Werror,-Wvla-extension]
  char readdir_payload[readdir_payload_size];
2020-09-16 12:22:17 -07:00
Andrei Vagin f148242aba Revert "fuse: add benchmarking support for FUSE"
test/fuse/benchmark/read_benchmark.cc:34: Failure
Expected: (fuse_prefix) != (nullptr), actual: NULL vs (nullptr)
external/com_google_benchmark/src/benchmark_runner.cc:120: RunInThread:
Check `st.iterations() >= st.max_iterations' failed. Benchmark returned
before State::KeepRunning() returned false!
--- FAIL: Benchmarks_BM_Read/262144/real_time (0.29s)
    runner.go:502: test "Benchmarks.BM_Read/262144/real_time" failed
    with error exit status 134, want nil
FAIL
2020-09-16 12:22:17 -07:00
Jinmou Li 113928754c Fix FUSE unit test after vfs interface change 2020-09-16 12:22:17 -07:00
Jinmou Li 093b0ab6c5 Fix FUSE go unit test merge conflict mistake 2020-09-16 12:22:14 -07:00
Andrei Vagin c6e749fb32 fs/fuse: Move the 'marshal' and 'primitive' packages to the 'pkg' directory. 2020-09-16 12:19:30 -07:00
Craig Chi dd10352729 Unexport fusefs.inode.nodeID 2020-09-16 12:19:30 -07:00
Boyuan He 2051260e82 Implement FUSE_UNLINK
Fixes #3696
2020-09-16 12:19:30 -07:00
Craig Chi 70cfea2377 Fix comments of TODO issues. 2020-09-16 12:19:30 -07:00
Jinmou Li d459bb3372 Add FUSE umount support
This change implements Release for the FUSE filesystem
and expected behaviors of the FUSE devices.
It includes several checks for aborted connection
in the path for making a request and a function
to abort all the ongoing FUSE requests in order.
2020-09-16 12:19:30 -07:00
Jinmou Li 4edc56d3e9 Fix FUSE_RELEASE protocol reply processing
This commit fixes the potential unexpected errors
of original handling of FUSE_RELEASE responses while
keep the same behavior (ignoring any reply).
2020-09-16 12:19:30 -07:00
Jinmou Li 826a685a95 Improve FUSE async/noreply call logic
This change adds bookkeeping variables for the
FUSE request. With them, old insecure confusing
code we used to process async requests is replaced
by new clear compiling ones. Future code can take
advantage of them to have better control of each
requests.
2020-09-16 12:19:30 -07:00
Jinmou Li f1219ec5f1 Refactor FUSE connection for readability and structure
This change decouples the code that is weakly
tied to the connection struct from connection.go,
rename variables and files with more meaningful choices,
adds detailed comments, explains lock orders,
and adds other minor improvement to make
the existing FUSE code more readable and
more organized.

Purpose is to avoid too much code in one file
and provide better structure for the
future commits.
2020-09-16 12:19:30 -07:00
Craig Chi bf8efe8cdf Implement FUSE_SETATTR
This commit implements FUSE_SETATTR command. When a system call modifies
the metadata of a regular file or a folder by chown(2), chmod(2),
truncate(2), utime(2), or utimes(2), they should be translated to
corresponding FUSE_SETATTR command and sent to the FUSE server.

Fixes #3332
2020-09-16 12:19:30 -07:00
Craig Chi 4181e8c974 Add fh support for revise attr and fstat(2) test
According to Linux 4.4's FUSE behavior, the flags and fh attributes in
FUSE_GETATTR are only used in read, write, and lseek. fstat(2) doesn't
use them either. Add tests to ensure the requests sent from FUSE module
are consistent with Linux's.

Updates #3655
2020-09-16 12:19:30 -07:00
Jinmou Li 98faed55e6 Implement FUSE_WRITE
This commit adds basic write(2) support for FUSE.
2020-09-16 12:19:30 -07:00
Craig Chi 18f1e1c91b Implement FUSE_CREATE
FUSE_CREATE is called when issuing creat(2) or open(2) with O_CREAT. It
creates a new file on the FUSE filesystem.

Fixes #3825
2020-09-16 12:19:30 -07:00
Jinmou Li 7ed4e46a71 FUSE device: clean up readLocked
This change removes the unnecessary loop and avoids
the recursive call. It also fixes minor bugs in this
function.
2020-09-16 12:19:30 -07:00
Jinmou Li e91c026672 Downgrade FUSE minor version support and clarify comments 2020-09-16 12:19:30 -07:00
Craig Chi 1d8029022e fuse: remove unused marshalling functions
This commit removes unused marshalling functions in linux abi package
and moves self-defined FUSEInitRes wrapper to fuse package.

Updates #3707
2020-09-16 12:19:30 -07:00
Boyuan He & Ridwan Sharif cb9a2a1ad4 fuse: add benchmarking support for FUSE
This change adds the following:
-  Add support for containerizing syscall tests for FUSE
-  Mount tmpfs in the container so we can run benchmarks against it
-  Run the server in a background process
-  benchmarks for fuse syscall

Co-authored-by: Ridwan Sharif <ridwanmsharif@google.com>
2020-09-16 12:19:30 -07:00
Craig Chi 449986264f Support multiple FUSE kernel versions of FUSE_INIT response struct
The fuse_init_out struct changes in different FUSE kernel versions. A
FUSE server may implement older versions of fuse_init_out, but they
share common attributes from the beginning. Implement variable-length
marshallable interface to support older versions of ABI.

Fixes #3707
2020-09-16 12:19:30 -07:00
Craig Chi 983e30c016 Implementing inode.Getlink
kernfs uses inode.Getlink to resolve symlink when look up paths.

Updates #3452
2020-09-16 12:19:30 -07:00
Craig Chi 21cac9dd04 Fix FUSE_READDIR offset issue
According to readdir(3), the offset attribute in struct dirent is the
offset to the next dirent instead of the offset of itself. Send the
successive FUSE_READDIR requests with the offset retrieved from the last
entry.

Updates #3255
2020-09-16 12:19:30 -07:00
Ridwan Sharif d51ddcefdc fuse: use safe go_marshal API for FUSE
Until #3698 is resolved, this change is needed to ensure we're not
corrupting memory anywhere.
2020-09-16 12:19:30 -07:00
Ridwan Sharif 4a5857d644 fuse: Implement IterDirents for directory file description
Fixes #3255.

This change adds support for IterDirents. You can now use `ls` in
the FUSE sandbox.

Co-authored-by: Craig Chi <craigchi@google.com>
2020-09-16 12:19:30 -07:00
Ridwan Sharif bc07df8887 Implement FUSE_RMDIR
Fixes #3587

Co-authored-by: Craig Chi <craigchi@google.com>
2020-09-16 12:19:30 -07:00
Jinmou Li 713400d6b0 Implement FUSE_READ
Fixes #3206
2020-09-16 12:19:30 -07:00
Boyuan He 4d26c9929d Implement FUSE_MKDIR
Fixes #3392
2020-09-16 12:19:30 -07:00
Boyuan He 733d013f97 Implement FUSE_READLINK
Fixes #3316
2020-09-16 12:19:30 -07:00
Boyuan He b50c03b571 Implement FUSE_SYMLINK
Fixes #3452
2020-09-16 12:19:30 -07:00
Boyuan He b53e10f391 Implement FUSE_MKNOD
Fixes #3492
2020-09-16 12:19:30 -07:00
Boyuan He 947088e10a Implement FUSE_RELEASE/RELEASEDIR
Fixes #3314
2020-09-16 12:19:30 -07:00
Boyuan He 32044f94e9 Implement FUSE_OPEN/OPENDIR
Fixes #3174
2020-09-16 12:19:30 -07:00
Andrei Vagin d6ee3ae6d7 Implement FUSE_LOOKUP
Fixes #3231

Co-authored-by: Boyuan He <heboyuan@google.com>
2020-09-16 12:19:30 -07:00
Craig Chi 15ff2893d9 Extend integration test to test sequence of FUSE operation
Original FUSE integration test has limited capabilities. To test more
situations, the new integration test framework introduces a protocol
to communicate between testing thread and the FUSE server. In summary,
this change includes:

1. Remove CompareResult() and break SetExpected() into
   SetServerResponse() and GetServerActualRequest(). We no longer set
   up an expected request because we want to retrieve the actual FUSE
   request made to the FUSE server and check in the testing thread.

2. Declare a serial buffer data structure to save the received requests
   and expected responses sequentially. The data structure contains a
   cursor to indicate the progress of accessing. This change makes
   sequential SetServerResponse() and GetServerActualRequest() possible.

3. Replace 2 single directional pipes with 1 bi-directional socketpair.
   A protocol which starts with FuseTestCmd is used between the testing
   thread and the FUSE server to provide various functionality.

Fixes #3405
2020-09-16 12:19:30 -07:00
Rahat Mahmood 9ef1c79922 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 Mahmood d201feb8c5 Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Ian Lewis dcd532e2e4 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
Chong Cai cb2e3c946a Implement gvisor verity fs ioctl with GETFLAGS
PiperOrigin-RevId: 331905347
2020-09-15 19:01:59 -07:00
Dean Deng a004f0d082 Support setting STATX_SIZE for kernfs.InodeAttrs.
Make setting STATX_SIZE a no-op, if it is valid for the given permissions and
file type.

Also update proc tests, which were overfitted before.

Fixes #3842.
Updates #1193.

PiperOrigin-RevId: 331861087
2020-09-15 14:55:28 -07:00