Commit Graph

565 Commits

Author SHA1 Message Date
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
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
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
Tom Smeding
7655fe2f9d --size: Update completions and documentation
Signed-off-by: Tom Smeding <tom@tomsmeding.com>
2022-10-26 19:47:00 +02:00
Tom Smeding
906a7a75bd Tests for --size and --perms
Signed-off-by: Tom Smeding <tom@tomsmeding.com>
2022-10-26 19:46:59 +02:00
Tom Smeding
494b269a69 Add --size option to control size of a --tmpfs
Signed-off-by: Tom Smeding <tom@tomsmeding.com>
2022-10-26 19:46:59 +02:00
Simon McVittie
020a9eef6f Merge pull request #487 from smcv/better-enospc-message
Improve error message when clone() fails with ENOSPC
2022-10-03 11:28:20 +01:00
Simon McVittie
efbcdba68c Merge pull request #527 from a1346054/fixes
test-run: replace nonstandard `which`
2022-09-13 18:41:21 +01:00
a1346054
a29f535b74 test-run: replace nonstandard which
`command -v` is the standardized replacement for `which` and never
writes to stderr

Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com>
2022-09-12 22:09:11 +00: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
8af578d088 Merge pull request #510 from smcv/etc-shadow
Adjust tests related to /etc/shadow
2022-07-26 19:54:46 +01:00
Simon McVittie
7d54d050a2 meson: Add options to set a RPATH/RUNPATH on the bwrap executable
This is useful when building a self-contained, relocatable tree
containing a build of bubblewrap and all of its non-glibc dependencies
(in practice this means libcap and maybe libselinux), as is done in
the Steam container runtime. A RPATH/RUNPATH pointing to ${ORIGIN}/../lib
allows bwrap to find an adjacent, bundled copy of libcap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-16 10:19:24 +02:00
Tom Smeding
89d64eee9d Prepare for multiple different modifier options
Signed-off-by: Tom Smeding <tom@tomsmeding.com>
2022-05-14 13:45:41 +02:00
Simon McVittie
2b4c4a7899 test-run: Add another assertion that we cannot read /etc/shadow
The goal of this assertion was to demonstrate that a setuid bwrap does
not give us access to otherwise unreadable files, but if we want to
check that, we should probably be looking at the bind-mount destination
instead of the source file.

Leave the old assertion in too, just in case *that* fails.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-11 16:01:11 +01:00
Simon McVittie
a996acc892 test-run: Skip a test if we can read /etc/shadow
Ordinarily, we would not be able to read /etc/shadow if we're not uid 0;
but when building in a sysroot owned by the current user (for example
by setting it up using bwrap, as steam-runtime-tools does), we might
actually be able to read it. Skip the assertion that we cannot read it
in this case.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-11 15:55:10 +01:00
Simon McVittie
c54bbc6d7b Release v0.6.2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-11 15:05:37 +01:00
Simon McVittie
b9d0ac36e7 Merge pull request #486 from smcv/unused
Annotate some variables as sometimes-unused
2022-05-11 14:54:27 +01:00
Simon McVittie
5ba8fc31ca Merge pull request #492 from smcv/mips
try-syscall: Use compiler-predefined macros to detect mips ABI
2022-05-10 16:31:02 +01:00
Simon McVittie
ade6bb0ff7 Merge pull request #493 from smcv/bwrapdir
meson: Allow installation directory to be set explicitly
2022-05-10 16:30:17 +01:00
Simon McVittie
14d6a7f0df Merge pull request #496 from smcv/missing-def
Allow building on old glibc without PR_SET_CHILD_SUBREAPER defined
2022-05-10 16:23:02 +01:00
Simon McVittie
3faa4c1ff2 tests: Disable leak detection when joining user-specified pid namespace
If we don't do this, AddressSanitizer busy-loops with this backtrace:

    #0  in sched_yield
    #1  in __sanitizer::StopTheWorld
    #2  in __lsan::LockStuffAndStopTheWorldCallback
    #3  in __GI___dl_iterate_phdr
    #4  in __lsan::LockStuffAndStopTheWorld
    #5  in __lsan::CheckForLeaks
    #6  in __lsan::DoLeakCheck
    #7  __lsan::DoLeakCheck
    #8  in __cxa_finalize
    #9  in __do_global_dtors_aux
    #10 in ??
    #11 in _dl_fini

This fixes the hang described in commit 2e3d6e7d, so remove the
workarounds from that commit.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 14:02:03 +02:00
Simon McVittie
c991f2dd9a tests: Disable sanitizers for try-syscall
gcc's AddressSanitizer makes system calls that our filter doesn't
allow for, resulting in a fatal error when run under a restrictive
seccomp filter.

try-syscall is a helper for the test, rather than being code under test
itself, so we don't really need this instrumentation in it: all we want
it to do is make some specific syscalls.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 14:02:03 +02:00
Simon McVittie
e7c9b04f59 build: Auto-detect presence of Docbook XSL stylesheets
This follows the usual feature semantics: they're mandatory if the
feature is enabled, aren't checked if the feature is disabled, and are
optional if the feature is in the auto state (which is the default for
this particular feature).

The logic used here is similar to AX_CHECK_DOCBOOK_XSLT in
autoconf-archive.

Resolves: https://github.com/containers/bubblewrap/issues/500
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-03 14:00:30 +02:00
Simon McVittie
1d6a50f762 Merge pull request #501 from rusty-snake/fix-missing-options-in-manpage
Add --share-net & --json-status-fd to the manpage
2022-04-21 20:34:19 +01:00
rusty-snake
feef6071a9 Add --share-net & --json-status-fd to the manpage
Fixes #469
Fixes #499

Signed-off-by: rusty-snake <41237666+rusty-snake@users.noreply.github.com>
2022-04-21 21:21:03 +02:00
Simon McVittie
4bf2d4e9b0 Merge pull request #491 from ffontaine/main
meson: add tests option
2022-04-21 12:15:27 +01:00
Fabrice Fontaine
34ea0ad841 meson: add tests option
Allow the user to disable tests, for example to avoid the following
build failure on mips32:

FAILED: tests/try-syscall.p/try-syscall.c.o
/home/autobuild/autobuild/instance-11/output-1/host/bin/mipsel-buildroot-linux-musl-gcc -Itests/try-syscall.p -Itests -I../tests -fdiagnostics-color=always -Wall -Winvalid-pch -Wextra -O3 -D_GNU_SOURCE -Werror=shadow -Werror=empty-body -Werror=strict-prototypes -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=pointer-arith -Werror=init-self -Werror=missing-declarations -Werror=return-type -Werror=overflow -Werror=int-conversion -Werror=incompatible-pointer-types -Werror=misleading-indentation -Werror=missing-include-dirs -Werror=aggregate-return -Werror=switch-default -Wswitch-enum -Wno-sign-compare -Wno-error=sign-compare -Wno-missing-field-initializers -Wno-error=missing-field-initializers -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O1 -g0 -MD -MQ tests/try-syscall.p/try-syscall.c.o -MF tests/try-syscall.p/try-syscall.c.o.d -o tests/try-syscall.p/try-syscall.c.o -c ../tests/try-syscall.c
../tests/try-syscall.c:34:5: error: #error "Unknown MIPS ABI"
   34 | #   error "Unknown MIPS ABI"
      |     ^~~~~

Fixes:
 - http://autobuild.buildroot.org/results/cf0365354fc8c16e5871d561daae0fa5039d0bee

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-04-06 18:18:43 +02:00
Simon McVittie
77d1a77ea2 Merge pull request #489 from Newbytee/patch-1
Link to the last commit where xdg-app-helper.c existed
2022-04-06 16:53:46 +01:00
Simon McVittie
bda58e03a1 meson: Allow installation directory to be set explicitly
Overriding the libexecdir via default_options doesn't always work when
used as a subproject.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-05 14:57:04 +01:00
Simon McVittie
7e62e8dafe Allow building on old glibc without PR_SET_CHILD_SUBREAPER defined
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-05 14:48:23 +01:00
Simon McVittie
d4554fcf25 utils: Silence -Wunused-parameter with clang, Meson, and SELinux disabled
These parameters are unused if SELinux happens to be disabled.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-05 14:34:47 +01:00
Simon McVittie
8f5b370696 Silence -Wunused-but-set-variable with clang
This variable is only used for lifetime tracking (autocleanup), but
clang warns on that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-05 14:34:47 +01:00
Simon McVittie
bab52ef198 try-syscall: Use compiler-predefined macros to detect mips ABI
_MIPS_SIM_ABI32 etc. are defined by Linux <asm/sgidefs.h>, which is
included by glibc <sys/syscall.h> (which defers to Linux headers to
get syscall numbers), but not by musl <sys/syscall.h>.

_ABIO32 etc. are predefined by the compiler, so they are always
available, regardless of libc. References:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=27d54b2a6c18ef1ae50f1a5b432d590438445b90
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=0ea339ea4d9c3e04ae17da6bf389617eb0251e57

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-05 13:49:04 +01:00