1
0
mirror of https://github.com/projectatomic/bubblewrap.git synced 2026-02-05 15:45:22 +01:00

27 Commits

Author SHA1 Message Date
Simon McVittie
47ff41eb90 Use stdbool.h for booleans
We don't need to reinvent these, especially in a confusing form
(bool type like stdbool.h, but TRUE and FALSE constants like GLib).
stdbool.h was available in the gcc 4.6 that is the default compiler in
Ubuntu 12.04, more than a decade ago, so it seems sufficiently
ubiquitous.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-10-08 13:35:20 +01:00
Simon McVittie
0c9646573f Handle EINTR when doing I/O on files or sockets
If a blocking operation is interrupted by a signal, including SIGCHLD,
various things can fail with EINTR. This is not a "real" error and can
result in spurious failures.

Resolves: https://github.com/containers/bubblewrap/issues/657
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-10-03 17:55:37 +01:00
Simon McVittie
89ae6b10a4 Add new --level-prefix option
This prepends a severity level such as <3> to each line of diagnostic
output, with numeric severity levels taken from matching syslog(3)
(such as LOG_ERR = 3), so that the diagnostic output can be parsed by
tools like `logger --prio-prefix` and `systemd-cat --level-prefix=1`
that support that encoding.

The facility (LOG_USER, etc.) is not included, since it makes little
sense to vary on a per-message basis. logger(1) supports prefixes
with or without a facility, and systemd-cat(1) only supports prefixes
without a facility, so this is compatible with both.

A future version of Steam's pressure-vessel is likely to use this to
make warnings and fatal errors from bubblewrap more visible.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-08-15 15:01:35 +01:00
Christian Göttsche
9aa1b3636b Rework xcalloc
Pass the first parameter to calloc(3) to perform the overflow check.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2024-02-02 19:53:08 +01:00
Simon McVittie
68a0330ce4 utils: Add a specialized function to print errno for mount(2)
mount(2) uses ENOSPC to represent an arbitrary anti-denial-of-service
limit being exceeded, which is outside the usual meaning of
"No space left on device". We can make this clearer by catching that
particular failure mode and giving users a hint.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=218336
Resolves: https://github.com/ValveSoftware/steam-runtime/issues/637
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-03 15:31:51 +00:00
Christian Göttsche
2ae2ec3542 Enable and resolve sign comparisson warnings
Comparisson of different signedness can result in unexpected results due
to implicit conversions.

    ../network.c:81:34: warning: comparison of integer expressions of different signedness: ‘__u32’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
       81 |           if (rheader->nlmsg_seq != seq_nr)
          |                                  ^~
    ../network.c:83:34: warning: comparison of integer expressions of different signedness: ‘__u32’ {aka ‘unsigned int’} and ‘__pid_t’ {aka ‘int’} [-Wsign-compare]
      83 |           if (rheader->nlmsg_pid != getpid ())
          |                                  ^~

    ../bind-mount.c:268:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
      268 |       assert (i < n_lines);
          |                 ^
    ../bind-mount.c:309:13: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
      309 |   assert (i == n_lines);
          |             ^~
    ../bind-mount.c:318:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
      318 |   for (i = 0; i < n_lines; i++)
          |                 ^
    ../bind-mount.c:321:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
      321 |   for (i = 0; i < n_lines; i++)
          |                 ^

    ../utils.c:818:19: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘ssize_t’ {aka ‘long int’} [-Wsign-compare]
      818 |   while (size - 2 < n);
          |                   ^

    ../bubblewrap.c:489:13: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
      489 |   assert (j < sizeof(dont_close)/sizeof(*dont_close));
          |             ^
    ../bubblewrap.c:994:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uid_t’ {aka ‘unsigned int’} [-Wsign-compare]
      994 |       if (setfsuid (-1) != real_uid)
          |                         ^~
    ../bubblewrap.c:1042:61: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
     1042 |       if (write (privileged_op_socket, buffer, buffer_size) != buffer_size)
          |                                                             ^~
    ../bubblewrap.c:1232:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
     1232 |           for (i = 0; i < N_ELEMENTS (cover_proc_dirs); i++)
          |                         ^
    ../bubblewrap.c:1260:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
     1260 |           for (i = 0; i < N_ELEMENTS (devnodes); i++)
          |                         ^
    ../bubblewrap.c:1272:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
     1272 |           for (i = 0; i < N_ELEMENTS (stdionodes); i++)
          |                         ^
    ../bubblewrap.c: In function ‘read_priv_sec_op’:
    ../bubblewrap.c:1556:15: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘long unsigned int’ [-Wsign-compare]
     1556 |   if (rec_len < sizeof (PrivSepOp))
          |               ^
    ../bubblewrap.c:1626:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
     1626 |   if (*total_parsed_argc_p > MAX_ARGS)
          |                            ^
    ../bubblewrap.c:1681:40: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
     1681 |               if (*total_parsed_argc_p > MAX_ARGS)
          |                                        ^
    ../bubblewrap.c:2265:31: warning: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
     2265 |           if (opt_sandbox_uid != -1)
          |                               ^~
    ../bubblewrap.c:2285:31: warning: comparison of integer expressions of different signedness: ‘gid_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
     2285 |           if (opt_sandbox_gid != -1)
          |                               ^~
    ../bubblewrap.c:2678:23: warning: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
     2678 |   if (opt_sandbox_uid == -1)
          |                       ^~
    ../bubblewrap.c:2680:23: warning: comparison of integer expressions of different signedness: ‘gid_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
     2680 |   if (opt_sandbox_gid == -1)
          |                       ^~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-02-28 21:53:19 +01:00
Simon McVittie
010bde7f37 bind-mount: Include failing path in error message
Prompted by flatpak/flatpak#4731, in which a misconfigured SMB automount
was failing to be remounted with ENODEV. This would have been easier to
debug if we knew which path could not be remounted.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 11:39:58 +02:00
Simon McVittie
55b91e2a67 bind-mount: Be more const-correct
When compiled with -Wwrite-strings as part of a larger project, gcc and
clang both warn that we're assigning a string constant to a mutable
struct member. There's actually no reason why it should be mutable, so
make it const.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-10-11 09:58:23 +02:00
Simon McVittie
a6c90c516b Add SPDX-License-Identifier for files that already specify license
This is a step towards REUSE compliance. Third-party files that we do
not otherwise edit (git.mk, m4/attributes.m4) are excluded here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-08-31 12:32:40 +01:00
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