Commit Graph
35 Commits
Author SHA1 Message Date
Lucas ManningandgVisor bot cec42923e3 Clean up mount tests.
This change makes it simpler to write mount tests that examine the optional
field of mountinfo. It also cleans up the mounts in existing tests so they
don't pollute mountinfo after exit.

PiperOrigin-RevId: 561439839
2023-08-30 13:56:03 -07:00
Jing ChenandgVisor bot e3f7443b9b Support MS_STRICTATIME flag for the syscall mount.
PiperOrigin-RevId: 560207305
2023-08-25 15:17:23 -07:00
Lucas ManningandgVisor bot 94441a6e26 Fix small mount propagation bug.
The MS_PRIVATE flag was not being cleared in addPeer.

Reported-by: [email protected]
PiperOrigin-RevId: 557949154
2023-08-17 15:14:15 -07:00
Andrei VaginandgVisor bot 4af420d420 Implement setns for mount namespaces
PiperOrigin-RevId: 552859231
2023-08-01 11:12:29 -07:00
Andrei VaginandgVisor bot 4d39b66860 Implement mount namespaces
This change implements only the basic functions of mount namespaces.
All features that depends on user namespaces will be implemented separately.

PiperOrigin-RevId: 552673896
2023-07-31 21:12:21 -07:00
Lucas ManningandgVisor bot a2c16ae70b Fix logic bug in attaching mounts.
Before this fix, the vd provided to connectMountAt wouldn't be consumed if
we ran into a dead mount, the caller was responsible. This dead mount
could be rooted at a different vd than the one provided, which meant that we
were DecRef'ing the wrong vd if the method returned an error. The method now
always consumes the vd to simplify its use.

Reported-by: [email protected]
PiperOrigin-RevId: 532636615
2023-05-16 18:53:33 -07:00
Andrei Vagin 3445db339d Fix all c++ compile time warnings 2023-03-09 19:01:00 -08:00
Lucas ManningandgVisor bot 253bafa83c Display the proper root path in mountinfo.
PiperOrigin-RevId: 492323370
2022-12-01 16:05:00 -08:00
Lucas ManningandgVisor bot ebabd3a536 Add a maximum to the total number of mounts allowed in a namespace.
The limit is the same as a the default for /proc/sys/fs/mount-max.

Reported-by: [email protected]
PiperOrigin-RevId: 491748452
2022-11-29 15:12:26 -08:00
Lucas ManningandgVisor bot b7a7b9c054 Allow for creation of shared mounts.
This is the first in a series of changes that will enabled shared mount
subtrees. This will emulate the Linux kernel implementation described here:
https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt

Mounts can now a be part of a mount groups. These groups are
identified by ids assigned by the VFS. Group IDs can be reused after all
mounts that are a member of that group are destroyed.

Newly created mounts inherit the propagation type of their parent mount. A
mount created on a shared mount will also be a shared mount, though it will
be part of a different group. A shared mount 'A' bound to a shared mount 'B'
will replicate that bind to all of 'B's peers. These new mounts will all be
part of a new shared peer group.

Unmounting a mount 'A' that is a direct child of a shared mount 'B' mounted
at dentry 'b' will propagate that event to all its peers. So peers B1, B2,
B3, etc will all unmount the mounts (A1, A2...) located at 'b'. However, if
any of peers of A have children, they are skipped. If the original mount A
has children, the mount is failed entirely.

The initial root mount has propagation type MS_PRIVATE.

This change only implements a basic version of mount groups. Notably it does
not implement MS_SLAVE, MS_UNBINDABLE, or MS_REC.

PiperOrigin-RevId: 483792757
2022-10-25 15:35:10 -07:00
Lucas ManningandgVisor bot 4fd1477fe0 Add support for bind mounting.
This change adds limited support for the MS_BIND flag. MS_REC is not yet
implemented.

PiperOrigin-RevId: 478030021
2022-09-30 10:52:34 -07:00
Shambhavi SrivastavaandgVisor bot 41afc326a7 Accounting against tmpfs size only when page is allocated.
Implementing memory allocation taking into consideration the fact
that the page allocation does not changes whenever the size of a
file changes. For instance, ftruncate may increase the size of a
file without actually allocating that size. So it changes when the
pages are actually allocated.

Also making amends to allow for partial allocations. For instance,
a write, mmap can allocate pages as long as the size option
is not exhausted.

Fixes #7827

PiperOrigin-RevId: 470426017
2022-08-27 02:42:05 -07:00
Shambhavi SrivastavaandgVisor bot bdede951be Tmpfs with size option enabled bug fix.
Adding test case to check empty size parsing in Linux.
If a value is not passed with size the mount(2) should return EINVAL.
Handling empty size parsing in gVisor.

PiperOrigin-RevId: 448132149
2022-05-11 18:36:17 -07:00
Shambhavi SrivastavaandgVisor bot ed18dd3052 Fixing memory allocations for tmpfs size.
Fixing partial write memory allocation.
Accounting for memory allocation in hard links.
Adding test cases to check for hard link memory allocation for the same.

PiperOrigin-RevId: 443742013
2022-04-22 13:19:14 -07:00
Shambhavi SrivastavaandgVisor bot 1fce5624fd Enable tmpfs size mount option.
When tmpfs is mounted with `size` option it imposes a limit for
the tmpfs mount. The total size of all files in that mount must not exceed this
limit. See tmpfs(5) for more details. When this option was not supported and
specifying it caused mount(2) to return EINVAL instead of ENOSPC.

In Linux, tmpfs charges symlinks, regular files and directories against this
`size` limit. All accounting is done on the granularity of page size. The `size`
limit and all individual file sizes are rounded up to number of pages while
performing calculations. gVisor has aimed to replicate the same behavior.

One difference from Linux is that if the `size` option is not specified, then
Linux uses 50% of physical RAM as the `size`. We don't replicate this behavior
in gVisor as the actual size of host physical RAM should not be exposed to
application. In gVisor, if `size` option is not specified, then no limit is
imposed. This is consistent with the behavior before this change.

Added syscall tests for regular files and symlink.

PiperOrigin-RevId: 442686814
2022-04-18 18:50:24 -07:00
Jamie LiuandgVisor bot 6f83b4957a Check mount writability in VFS2 [f]access[at][2] implementations.
Linux exempts special files (sockets, named pipes, and character/block device
special files) from mount writability checks in both open
(fs/open.c:do_dentry_open()) and access (fs/open.c:do_faccessat()) paths. We
don't currently do so in open (in VFS1 or VFS2) or access (in VFS1), so we
don't do so in VFS2 access either.

PiperOrigin-RevId: 439398002
2022-04-04 13:33:02 -07:00
Shambhavi SrivastavaandgVisor bot 7146743791 Created tests for mounting tmpfs with size option enabled.
Tests include:
Allocating memory below and above range for single file.
Allocating memory above range for multiple file.

PiperOrigin-RevId: 438918539
2022-04-01 15:01:53 -07:00
Ayush RanjanandgVisor bot f6263c38df Remove VFS1 special handling in tests.
Also clean up usage of GVISOR_VFS environment variable.
Updates #1624

PiperOrigin-RevId: 429100450
2022-02-16 11:41:51 -08:00
Lucas ManningandgVisor bot b057172b3e Resolve to the last mount in the stack during umount.
This is done in linux with the LOOKUP_MOUNTPOINT flag. We emulate this behavior
in gVisor with getMountAt().

PiperOrigin-RevId: 415642095
2021-12-10 17:10:42 -08:00
Ayush RanjanandgVisor bot 9f66025506 Handle UMOUNT_NOFOLLOW in VFS2 umount(2).
Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 406951359
2021-11-01 16:51:12 -07:00
Adin ScannellandgVisor bot 0904d746e3 Handle tmpfs with 5 fields in /proc/mounts parsing.
PiperOrigin-RevId: 370565903
2021-04-26 16:27:45 -07:00
Fabricio VoznikaandgVisor bot 60e4f7f582 Remove side effect from mount tests
Dropping CAP_SYS_ADMIN and not restoring it causes
other tests to be skipped.

PiperOrigin-RevId: 370002644
2021-04-22 20:06:37 -07:00
Rahat MahmoodandgVisor bot 5d7079da00 Also report mount options through /proc/<pid>/mounts.
PiperOrigin-RevId: 369967629
2021-04-22 15:52:24 -07:00
Andrei VaginandgVisor bot 2bc899e81e fs/fuse: check that a task has a specified file descriptor
Reported-by: [email protected]
PiperOrigin-RevId: 350159452
2021-01-05 09:47:30 -08: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
Ayush RanjanandgVisor bot 94a7e48685 [vfs] Disable inode number equality check for overlayfs.
Overlayfs does not persist a directory's inode number even while it is mounted.
See fs/overlayfs/inode.c:ovl_map_dev_ino(). VFS2 generates a new inode number
for directories everytime in lookup.

PiperOrigin-RevId: 331045037
2020-09-10 16:50:18 -07:00
Craig Chi b3fdce2862 Fix MountFuseFilesystem tests failing
Before kernel version 4.16-rc6, fuse mount is protected by
capable(CAP_SYS_ADMIN). After this version, it uses
ns_capable(CAP_SYS_ADMIN) to protect. Before the 4.16 kernel,
it was not allowed to mount fuse file systems without the
global CAP_SYS_ADMIN.

Fixes #3360
2020-07-31 16:18:40 -07:00
Rahat MahmoodandgVisor bot ee774b2cea Fix when FUSE tests need to be skipped due to sentry configuration.
PiperOrigin-RevId: 323426851
2020-07-27 13:26:23 -07:00
Ridwan Sharif 352f656ff3 Added stub FUSE filesystem
Allow FUSE filesystems to be mounted using libfuse.
The appropriate flags and mount options are parsed and
understood by fusefs.
2020-07-23 17:13:24 -04:00
Adin ScannellandgVisor bot 3b8d99f217 Import and structure cleanup.
PiperOrigin-RevId: 281795269
2019-11-21 11:41:30 -08:00
Nicolas LacasseandgVisor bot 9781128d5a Deflake mount_test.
Inode ids are only stable across Save/Restore if we have an open FD on the
inode. All tests that compare inode ids must therefor hold an FD open.

PiperOrigin-RevId: 254086603
2019-06-19 15:46:11 -07:00
Michael PrattandShentubot 4d52a55201 Change copyright notice to "The gVisor Authors"
Based on the guidelines at
https://opensource.google.com/docs/releasing/authors/.

1. $ rg -l "Google LLC" | xargs sed -i 's/Google LLC.*/The gVisor Authors./'
2. Manual fixup of "Google Inc" references.
3. Add AUTHORS file. Authors may request to be added to this file.
4. Point netstack AUTHORS to gVisor AUTHORS. Drop CONTRIBUTORS.

Fixes #209

PiperOrigin-RevId: 245823212
Change-Id: I64530b24ad021a7d683137459cafc510f5ee1de9
2019-04-29 14:26:23 -07:00
Andrei VaginandShentubot 88409e983c gvisor: Add support for the MS_NOEXEC mount option
https://github.com/google/gvisor/issues/145

PiperOrigin-RevId: 242044115
Change-Id: I8f140fe05e32ecd438b6be218e224e4b7fe05878
2019-04-04 17:43:53 -07:00
Nicolas LacasseandShentubot 0d683c9961 Make tmpfs respect MountNoATime now that fs.Handle is gone.
PiperOrigin-RevId: 236752802
Change-Id: I9e50600b2ae25d5f2ac632c4405a7a185bdc3c92
2019-03-04 16:57:14 -08:00
Brian GeffonandShentubot d3bc79bc84 Open source system call tests.
PiperOrigin-RevId: 224886231
Change-Id: I0fccb4d994601739d8b16b1d4e6b31f40297fb22
2018-12-10 14:42:34 -08:00