Commit Graph

595 Commits

Author SHA1 Message Date
Colin 9843f9b2b5 enable debug logging and add a bunch more tracing 2024-01-26 04:24:54 +00:00
Simon McVittie 5e43e8b1d2
Merge pull request #610 from WhyNotHugo/drop-py34
Drop support for Python<3.4 in demo code
2023-11-02 19:53:46 +00:00
Hugo Osvaldo Barrera d165751294 Drop support for Python<3.4 in demo code
This version of python reached its EOL in March 2019.

Signed-off-by: Hugo Osvaldo Barrera <hugo@whynothugo.nl>
2023-11-02 19:23:05 +01:00
Simon McVittie 7816e01298
Merge pull request #603 from quag/nixos-recursive-test-fix
Make test "can pivot to new rootfs recursively" work on NixOS
2023-10-02 10:08:35 +01:00
Simon McVittie ebfc8ef87f
Merge pull request #604 from quag/readme-test-add
Add testing instructions to README.md
2023-10-02 10:07:16 +01:00
Simon McVittie 9cdc26e2d7
Merge pull request #602 from quag/ok_done_testing
Implement change proposed in "All MRs that add unit tests conflict with each other"
2023-10-02 10:06:08 +01:00
Jonathan Wright 5e2b6a3079 Make test "can pivot to new rootfs recursively" work on NixOS
Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-10-01 11:11:28 -07:00
Jonathan Wright 05ce287fba Add testing instructions to README.md
Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-10-01 11:10:12 -07:00
Jonathan Wright 0ff3430dff Replace last /bin/bash with bash in test-run.sh
The other three references to bash already use "bash" instead of
"/bin/bash". Similarly, "#!/bin/bash" has already been replaced with
"#!/usr/bin/env bash".

Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-10-01 10:26:28 -07:00
Jonathan Wright 70699505e2 Fix typo in test case name (prefxing instead of prefixing)
Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-10-01 10:26:28 -07:00
Jonathan Wright 1cba87136e Fix MRs conflicting when they add unit tests
Fixes containers/bubblewrap#420

Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-10-01 10:26:23 -07:00
Simon McVittie 4a7bb29257
Merge pull request #599 from swick/wip/mnt-symlink-test
tests: Skip test when host /mnt is a symlink
2023-10-01 13:01:46 +01:00
Simon McVittie 97468426be
Merge pull request #600 from swick/wip/get-newroot-path
utils: Move get_newroot_path to utils
2023-10-01 13:01:38 +01:00
Simon McVittie 71aa850bf6
Merge pull request #598 from quag/argv0
Add --argv0 option
2023-10-01 12:58:06 +01:00
Jonathan Wright 4303430642 Add --argv0 option
Fixes containers/bubblewrap#91

Add the ability to overwrite argv[0] when starting a process in a
container. Using --argv0 to be consistent with ld.so --argv0.

Overwriting argv[0] is useful as some tools change their behavior based
on the value of argv[0]. For example, when bash is symlinked to sh it
behaves as sh. Similarly, unxz is a symlink to xz and changes the
default from compressing to decompressing. An extreme example is on many
systems, date, df, cat and so on are all symlinks to the coreutils
binary.

Example usage: bwrap --bind / / --argv0 sh bash

Signed-off-by: Jonathan Wright <quaggy@gmail.com>
2023-09-30 14:23:18 -07:00
Sebastian Wick b367272d59 utils: Move get_newroot_path to utils
We already have `get_oldroot_path` in utils, so let's be consistent
about this.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2023-09-28 18:25:37 +02:00
Sebastian Wick ad09be9443 tests: Skip test when host /mnt is a symlink
The test wants to mount /tmp on /mnt but /mnt comes from the host and
can be a symlink in which case the test fails. Skip the test in this
situation.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2023-09-28 18:16:20 +02:00
Simon McVittie ad76c2d6ba
Merge pull request #554 from smcv/disable-userns-tests-root
Fix test failure since #488 when running as uid 0
2023-05-04 19:30:18 +01:00
Simon McVittie d73a78f7ef
Merge pull request #559 from cgzones/compiler
Fix various compiler warnings
2023-05-04 19:27:22 +01:00
Sebastian Pipping 928638969e bwrap.xml: Get umbrella project back in sync
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 16:01:03 +02:00
Sebastian Pipping 35e6b2a698 bwrap.xml: Mention CVE-2017-5226 with --new-session
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 16:01:03 +02:00
Sebastian Pipping 9b246d4297 bwrap.xml: Get product intro back in sync
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 16:01:03 +02:00
Sebastian Pipping 2f9ce900d4 README.md: Mention --new-session in section "Sandboxing"
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 09:52:37 +02:00
Sebastian Pipping 9a1d8b7217 README.md: Add --new-session to usage example
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 09:52:37 +02:00
Sebastian Pipping 29f92713ce README.md: Improve readability of usage example
Signed-off-by: Sebastian Pipping <sebastian@pipping.org>
2023-04-03 09:52:37 +02:00
Simon McVittie 795eeee77e README, SECURITY: Clarify that bubblewrap does not define a security model
bubblewrap can provide a robust security boundary that severely limits
functionality, or it can provide full functionality without any attempt
at being a security boundary, or anything in between those extremes.
If a caller of bubblewrap chooses inappropriate command-line arguments
for their desired security model, then bubblewrap will not provide the
security model they are aiming for, but this is not a bubblewrap
vulnerability.

Apparently this isn't clear to everyone, so try to clarify.

The one place where bubblewrap *does* define some sort of security
policy for itself is when it's setuid root, in which case it's
responsible for preventing users from carrying out privilege escalation
attacks like CVE-2020-5291.

Resolves: https://github.com/containers/bubblewrap/issues/555
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-03-30 14:34:17 +02:00
Simon McVittie da63f2bddb
Merge pull request #558 from cgzones/close
load_file_data: do not close fd on error to avoid double-close
2023-03-02 21:49:36 +00:00
Simon McVittie 1a70cbe8e8
Merge pull request #562 from cgzones/cap_example
bwrap.1: mention example format of capability
2023-03-02 21:49:17 +00:00
Christian Göttsche 5634e3f89b bwrap.1: mention example format of capability
Mention how to format capabilities for --add-cap, e.g.
CAP_DAC_READ_SEARCH instead of DAC_READ_SEARCH.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-03-02 16:56:02 +01:00
Christian Göttsche 7ef02842eb load_file_data: do not close fd on error to avoid double-close
load_file_data() closes the passed file descriptor in case of an read(2)
failure.  The file descriptor is however owned by the caller and should
not be closed to avoid a double-close.
Since in this error branch NULL is always returned the only affected
caller is load_file_data(), as all other callers immediately abort via
die_with_error().  As bubblewrap is single-threaded the second close(2)
in load_file_data() will be well-defined and fail with EBADF, leading to
no unrelated file descriptor to be closed

Found by GCC analyzer:

    ./utils.c: In function ‘load_file_at’:
    ./utils.c:630:3: warning: double ‘close’ of file descriptor ‘fd’ [CWE-1341] [-Wanalyzer-fd-double-close]
    630 |   close (fd);
        |   ^~~~~~~~~~
    ...
            |  596 |           close (fd);
            |      |           ~~~~~~~~~~
            |      |           |
            |      |           (15) first ‘close’ here
    ...
        |  630 |   close (fd);
        |      |   ~~~~~~~~~~
        |      |   |
        |      |   (20) second ‘close’ here; first ‘close’ was at (15)

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-03-01 20:35:38 +01:00
Christian Göttsche ab5eb5c3f5 Declare file local variables static
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-02-28 21:53:52 +01:00
Christian Göttsche fe0da5d368 Use mode_t as parameter type in mkdir_with_parents
The parameter mode only usage is it being passed to ensure_dir(), which
takes it as mode_t.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-02-28 21:53:49 +01:00
Christian Göttsche 88004f880a Drop unnecessary cast to same type
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-02-28 21:53:48 +01:00
Christian Göttsche 15ef38c4e3 Avoid implicit conversions
Found by running under pedantic UBSAN:

    ../bubblewrap.c:968:21: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uid_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned)
    ../bubblewrap.c:1210:28: runtime error: implicit conversion from type 'int' of value -41 (32-bit, signed) to type 'unsigned int' changed the value to 4294967255 (32-bit, unsigned)
    ../bubblewrap.c:1215:28: runtime error: implicit conversion from type 'int' of value -41 (32-bit, signed) to type 'unsigned int' changed the value to 4294967255 (32-bit, unsigned)

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-02-28 21:53:45 +01: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 4ab175fe6d Prepare v0.8.0
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-27 12:21:03 +00:00
Simon McVittie 2ba9a9af91 tests: Try harder to evade --disable-userns
The worst-case scenario in terms of enforcing --disable-userns is that
we're retaining all capabilities, so test that too, to make sure that
the option is genuinely restricting even a privileged user.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-23 12:19:38 +00:00
Simon McVittie 140936fd73 tests: Explicitly unshare userns when testing --disable-userns
If we're running the tests as uid 0 with capabilities, then bwrap will
not create a new user namespace by default, which means the limit won't
be exceeded and the test will fail. Make sure we always try to create
the new user namespace.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-02-23 12:17:59 +00:00
Simon McVittie a319fd5dc3
Merge pull request #550 from smcv/seccomp-einval-hint
Attempt to clarify error message for missing CONFIG_SECCOMP_FILTER
2023-02-17 09:30:19 +00:00
Simon McVittie 2f873fa8ae Attempt to clarify error message for missing CONFIG_SECCOMP_FILTER
General-purpose desktop distributions are compiled with CONFIG_SECCOMP
and CONFIG_SECCOMP_FILTER, but vendor kernels for phones and other
assorted embedded devices don't necessarily enable these options. These
kernels are unsuitable for running Flatpak, or anything else that relies
on `bwrap --seccomp` or `bwrap --add-seccomp-fd`.

Missing CONFIG_SECCOMP or CONFIG_SECCOMP_FILTER is not the *only* reason
why we could get EINVAL here: I think we'd also get EINVAL if the seccomp
program is syntatically invalid. However, it's a relatively likely reason,
so it seems worth providing a hint.

Helps: flatpak/flatpak#3069
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-23 11:29:13 +00:00
Simon McVittie 41fd02ad14 test-run: Filter out no-new-privs in capsh output
Older versions of capsh would only show the capabilities, which we
expect not to change when we don't drop capabilities; but newer
versions also display whether the NO_NEW_PRIVS bit is set, and we *do*
expect to change that.

Resolves: https://github.com/containers/bubblewrap/issues/544
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-04 09:47:04 +01:00
Simon McVittie b5f672355b Add --assert-userns-disabled option
We can't combine --disable-userns with entering an existing user
namespace via --userns if the existing user namespace was created with
--disable-userns, because its ability to create nested user namespaces
has already been disabled. However, the next best thing is to verify
that we are already in the desired state.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-03 11:04:09 +01:00
Simon McVittie b33c333bcb Add an option to disable nested user namespaces by setting limit to 1
Some use-cases of bubblewrap want to ensure that the subprocess can't
further re-arrange the filesystem namespace, or do other more complex
namespace modification. For example, Flatpak wants to prevent sandboxed
processes from altering their /proc/$pid/root/.flatpak-info, so that
/.flatpak-info can safely be used as an indicator that a process is part
of a Flatpak app.

This approach was suggested by lukts30 on containers/bubblewrap#452.
The sysctl-controlled maximum numbers of namespaces are themselves
namespaced, so we can disable nested user namespaces by setting the
limit to 1 and then entering a new, nested user namespace. The resulting
process loses its privileges in the namespace where the limit was set
to 1, so it is unable to move the limit back up.

Co-authored-by: Alexander Larsson <alexl@redhat.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-03 11:04:09 +01:00
Simon McVittie bb7ac1348f
Merge pull request #539 from smcv/test-size
Fix test failures in 0.7.0 on unusual platforms
2022-11-21 13:41:13 +00:00
Simon McVittie 5080b233fa test-run: Don't rely on df supporting the --output=size option
df --output was new in coreutils 8.21 (2013), and non-GNU
implementations like busybox df don't have it.

This avoids a test failure in Steam Runtime 1 'scout', which is based
on Ubuntu 12.04 (2012). It'll also be helpful for anyone maintaining
an OS with non-GNU shell utilities.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-07 18:30:21 +00:00
Simon McVittie cfc15df5f1 test-run: If bubblewrap is setuid, assert that --size is not allowed
Previously, this test would have failed for a setuid bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-07 18:26:21 +00:00
Simon McVittie aa0fb696ab Prepare v0.7.0
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-07 17:40:33 +00:00
Simon McVittie 73911524a4 Fix copy/paste error in help for --pidns
--pidns acts on a pid namespace, not a user namespace.

Resolves: https://github.com/containers/bubblewrap/issues/531
Thanks: hadess
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-27 18:15:48 +01:00
Simon McVittie ddc431a88e
Merge pull request #441 from smcv/as-if
build: Consistently use AS_IF instead of if/then/fi
2022-10-27 17:42:57 +01:00
Simon McVittie d41edb969a
Merge pull request #509 from tomsmeding/tmpfs-size
Add --size option to control size of a --tmpfs
2022-10-26 21:43:25 +01:00