Commit Graph

18 Commits

Author SHA1 Message Date
Simon McVittie
6ceba45306 bind-mount: Factor out bind_mount_result_to_string()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-23 19:01:57 +01:00
Simon McVittie
7f38ab6cf1 bind_mount: Return an error code, and provide a way to display it
This gives us better diagnostic messages on failure, particularly for
BIND_MOUNT_ERROR_FIND_DEST_MOUNT where we previously said "Invalid
argument".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-23 19:01:57 +01:00
Ludovico de Nittis
04c0ca17ad Add support for bind-mount on case-insensitive filesystems
If we are using a case-insensitive filesystem the bind-mount operation
might fail when `/proc/self/mountinfo` is checked.

In a case-insensitive filesystem, if we ask to mount a certain
directory, e.g. '/CI_fs/foo', the kernel might add its entry in
`mountinfo` as '/CI_fs/FOO'. This happens because the kernel populates
`mountinfo` with whatever case combination first appeared in the dcache.

With this patch we open the requested path and look at its
`/proc/self/fd`, using readlink(), to get the path case combination that
the kernel is also expected to be using.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-16 13:46:10 +01:00
Colin Walters
765dd0e94f Add MS_SILENT to most mount() invocations
There's an effort to migrate Linux filesystems to handle the y2038
problem, which is great.  However, recently a kernel change landed
that emits a warning when mounting a filesystem that doesn't
handle it, and this notably shows up even when *remounting* e.g.
for a read-only bind mount:

Using e.g. `rpm-ostree install cowsay` there's a spam of:

```
[  189.529594] xfs filesystem being remounted at /sysroot supports timestamps until 2038 (0x7fffffff)
```

Now particularly when creating a our bind mounts, let's
ask the kernel to be quiet about it.  This is not a major event
worthy of a kernel log.
2020-05-18 21:20:43 +00:00
Marcos Paulo de Souza
4766393268 bubblewrap: Remove not needed MS_MGC_VAL mount flag
As specified by mount(2):

	Specifying MS_MGC_VAL was required in kernel versions prior to 2.4, but
	since Linux 2.4 is no longer required and is ignored if specified.

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>

Closes: #220
Approved by: cgwalters
2017-09-26 13:48:06 +00:00
Alexander Larsson
166e76e736 bind-mount: Check for errors in realpath()
Closes: #129
Approved by: cgwalters
2016-12-13 13:42:53 +00:00
Alexander Larsson
4a1418d336 bind-mount: Fix issue when destination of mount is in a symlink
The mount operation always fully resolves any symlinks before mounting
so we need to do the same when we're looking for the new mount
in the mount tables.

Without this something like
 --symlink /dst /link --bind-mount /src /link
 would fail because it would look for mount flags in /link, but the
 mount would be on /dst.

Closes: #119
Approved by: alexlarsson
2016-11-22 11:32:09 +00:00
Alexander Larsson
fce7a336cc bind-mounts: Fix handling of covered mountpoints
Its not uncommon for mountpoints to cover other mountpoints, for instance
if /a/b is mounted first, then /a/b or /a can be mounted again effectively
making the old /a/b unreachable. This happens sometimes on the host
system, but it happens also often in the context of bubblewrap
where you migth do something like:

  bwrap --bind / / --bind /my/foo /foo

In this case, we're covering whatever is on /foo on the host with
different content, and if /foo had submount under it these will be
covered.

There is a problem with bind mounts and covered mountpoints though.
Bubblewrap always does recursive bind-mounts (because a non-recursive
bind-mount could expose content that was otherwise covered), and the
linux recursive bind mount doesn't let you modify flags (such as
adding readonly). So we have to first bind-mount, and then change the
flags for the destination and all the submounts under it.

The existing naive implementation of submount enumeration in
bubblewrap also returns the covered mount points, and when we try
to change the flags on these we run into issues, because mount()
can't find the pathnames.

This implementation does a more thorough parsing of the mountinfo
file, looking at the "mount id" and "parent mount id" to reconstruct
exactly which mountpoints that are accessible.

This fixes https://github.com/projectatomic/bubblewrap/issues/14

Closes: #118
Approved by: alexlarsson
2016-11-15 13:57:43 +00:00
Giuseppe Scrivano
e4188b1d24 Add --remount-ro DEST
This allows to remount a mount point as read only.

It will allow us, by remounting / after other mount points are created,
to handle a readonly rootfs as specified in the OCI specs:

https://github.com/opencontainers/runtime-spec/blob/master/config.md#root-configuration

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2016-08-12 12:26:46 +02:00
Alexander Larsson
d69ab9202b Ran uncruftify.sh
Closes: #67
Approved by: cgwalters
2016-05-13 12:21:08 +00:00
Alexander Larsson
456211b189 Remove unused BIND_PRIVATE 2016-03-07 20:03:54 +01:00
Alexander Larsson
0c0e81e8d7 When getting mount flags, pick the *last* match
There can be multiple matches for a mountpoint, but the last one
is the visible one.
2016-03-07 19:52:56 +01:00
Alexander Larsson
df8447e1a2 Handle recursive remount failures where we we're not allowed access 2016-03-07 19:26:05 +01:00
Alexander Larsson
4bd57685ab Don't remount mounts when the mount flags didn't change. 2016-03-07 19:14:30 +01:00
Alexander Larsson
bc7228412b Fix up submount matching
We're not mounting things on CWD, but on /oldroot, so we need
to update this code.
2016-03-07 10:21:27 +01:00
Alexander Larsson
92712d8cd5 Rename to bubblewrap 2016-02-17 11:54:21 +01:00
Alexander Larsson
fc34e6b8d5 Fix bind mounts 2016-02-16 11:08:01 +01:00
Alexander Larsson
5d5f8e9614 Break out bind_mount() to separate file 2016-02-16 10:03:46 +01:00