1
0
mirror of https://github.com/projectatomic/bubblewrap.git synced 2026-02-06 09:46:09 +01:00

336 Commits

Author SHA1 Message Date
Jean-Baptiste BESNARD
bd3e8e6690 retcode: fix return code with syncfd and no event_fd
Closes: #325
Approved by: giuseppe
2020-01-28 09:57:18 +00:00
Alexander Larsson
320c0a442c Bump 0.4.0
Release 0.4.0
  - Add support for reusing existing namespaces with --userns and --pidns
  - Stores namespace info in status json
  - In setuid mode pid 1 is now marked dumpable
  - Now builds with musl libc
v0.4.0
2019-11-27 13:36:24 +01:00
Alexander Larsson
ff533b84d0 Merge pull request #338 from containers/reuse-namespaces
Support for reusing namespaces
2019-11-27 13:33:42 +01:00
Alexander Larsson
7a8e3de7e0 --userns --uid: Only swtich user if needed
We don't want to switch user unless we have to because we might
not be in a trivial mapping, such as the outer userns in a devpts workaround
hack.
2019-11-27 12:10:09 +01:00
Alexander Larsson
86e16d7aaa tests: Fix --userns tests
It seems the /proc file timestamp changes, so compare the namespaces
with readlink instead of ls -l as that doesn't contain a timestamp.
2019-11-27 09:49:55 +01:00
Alexander Larsson
e9980e36fc Allow --uid and --gid with --userns
This enables these options in this case and also ensures we set[ug]id
to the destination ids early in entering the namespace because
otherwise creating files during sandbox setup fails if the real user
id isn't mapped in the destination user namespace (and to make us
actually be that user/group).
2019-11-27 09:33:52 +01:00
Alexander Larsson
d3c1c74c97 Drop cap bounding set also in --userns case
This is the same as the --unshare-user case.
2019-11-27 09:25:25 +01:00
Alexander Larsson
3993653556 Fix typo in comment
s/intermidate/intermediate/
2019-11-26 13:41:42 +01:00
Alexander Larsson
3e5fe1bfba tests: Better error message if assert_files_equal fails 2019-11-26 09:28:51 +01:00
Alexander Larsson
1402b0c41b Add tests for --pidns 2019-11-26 09:28:51 +01:00
Alexander Larsson
46c7f1cca5 Add support for --pidns
This allows a sandbox to share a pid namespace with another sandbox.
For this to work the namespace passed in must be owned by the user
namespace that bwrap is using, which implies either that you pass in
--userns pointing, or run under that user namespace already. In the
former case you'd typically take the userns from a running bwrap
--unshare-user instance, whereas the second case happens when using
bwrap in the setuid mode without user namespaces.

If both --unshare-pid and --pidns are specified then we first
switch to the pid namespace, and then unshare from there. This is
useful if you want a pid-isolated sandob that is visible to another
sandbox.

The implementation is a bit tricky, as it needs to fork() in order
to activate the setns():ed pid namespaces, which means we have to
pass through the final pid via a socket to make the kernel translate
the pid to the initial pid namespace for us to waitpid() on it.
2019-11-26 09:28:51 +01:00
Alexander Larsson
4a7ecc630f utils: Add fork_intermediate_child() helper
This just forks and exits in the parent, continuing in the child.
2019-11-22 11:17:42 +01:00
Alexander Larsson
d068ec2bfa utils: Add some utility function to pass pids over a socket
This uses SCM_CREDENTIALS as a way to translate pids between the
sender and the destination namespaces.
2019-11-22 11:17:42 +01:00
Alexander Larsson
c5c999a750 tests: test --userns 2019-11-22 11:17:39 +01:00
Alexander Larsson
75c2d94de8 Add support for --userns and --userns2
This allows you to reuse an existing user namespace to set up all the
other namespaces, entering that instead of creating a new one.  The
reason you want to do this is that you can then also reuse other
namespaces that are owned by the user namespace. Typically you use
this to partially re-enter a previoulsy created bubblewrap sandbox.

This also adds --userns2 which is similar to --userns, but this is
switched into at the end instead of the start. Bubblewrap sometimes
creates nested such user namespaces[1], and to be able to reuse such a
setup we need to similarly reuse both namespaces via --userns2.

Technically using setns() is probably safe even in the privileged
case, because we got passed in a file descriptor to the namespace, and
that can only be gotten if you have ptrace permissions against the
target, and then you could do whatever to the namespace
anyway. However, for practical reasons this isn't useable for bwrap,
because (as described in a comment in acquire_privs()) setuid mode
causes root to own the namespaces that it creates. So as you will not
be able to access these namespaces for reuse anyway, its best to
disable it (in case of unexpected security issues).

[1] This is to work around an issue with mounting devpts without uid 0
mapped in the user namespace, where the outer namespace owns all the
other namespaces but the inner one has the right mappings.
2019-11-22 11:11:32 +01:00
Alexander Larsson
23d3b63924 Mark init process as dumpable so we can see stuff in its /proc
Now that we're properly getting rid of root in these we can mark it
dumpable, which enables use of some /proc files, like /proc/$pid/root that
was previously not accessible for pid1 in the sandbox.
2019-11-21 18:32:42 +01:00
Alexander Larsson
f9f6127474 setuid mode: Properly drop privs in monitor and pid1
It turns out we have this check in drop_privs():

 if (getuid () == 0 && setuid (opt_sandbox_uid) < 0)

Which is supposed to drop back to the regular uid in the case
we're in setuid mode and we're in the monitor_child() or do_init()
processes.

Unfortunately we're setuid, not plain root, so uid is not 0, but euid is zero.

This caused the monitoring processes to be running partially as root
which shows up weird in /proc.

Fix this by checking euid for 0 instead.
2019-11-21 18:32:42 +01:00
Alexander Larsson
2b01f06535 Tests: Fix test count
Seems we added a test without extending the count, breaking make check.
2019-11-21 18:32:42 +01:00
shawrkbait
300da62ab6 Add work-around for TEMP_FAILURE_RETRY to support musl
Closes: #295
Approved by: alexlarsson
2019-10-11 09:57:51 +00:00
Christian Kellner
93047df605 tests: check namespace info in json
Make sure the namespace information that is written to info.json
and json-status.json matches the namespace id inside the sandbox.

Closes: #323
Approved by: alexlarsson
2019-09-18 07:24:18 +00:00
Christian Kellner
cfe409efbf bwrap: include the pid namespace id in status/json
When writing the info-fd or the json-status-fd and a new pid name-
space is created, write the namespace id to the info/json. The
namespace id is encoded in the inode (and device) number of the
symbolic link in /proc/<pid>/ns/<namespace>, see namespaces(7)
for more information.
We obtain the information before we drop privileges, which is needed
when bwrap is run as setuid because then the namespace information
is not readable after having dropped the privileges.
Additionally we no retain the CAP_SYS_PTRACE capability because
that is needed to de-reference the links in /proc/<pid>/ns.
The user namespace information is omitted, because at the time when
we obtain the namespace id information, the user namespace is not yet
the new one, i.e. unshare (CLONE_NEWUSER), comes later.

Closes: #323
Approved by: alexlarsson
2019-09-18 07:24:18 +00:00
Christian Kellner
5a76f51dc6 bwrap: set opt_unshare_cgroup when _try succeeds
When optional cgroup unsharing was requested and the test for it
succeeds, set opt_unshare_cgroup to TRUE so it can be used later
to inspect if cgroup unsharing is enabled.

Closes: #323
Approved by: alexlarsson
2019-09-18 07:24:18 +00:00
Jonathan Lebon
c0d6b4b27d ci: Bump to fedora/29/atomic
Fedora 27 has been EOL for a while now... bump it to 29.

It'd be nice to test against FCOS, though it's not currently supported
by PAPR. It's in maintenance mode, but I might add support for it as a
stopgap. Medium-term though, I want to deprecate PAPR in favour of other
CI solutions.

Anyway, for now hopefully this should fix the CI on this repo.

Closes: #327
Approved by: alexlarsson
2019-09-09 06:35:10 +00:00
Colin Walters
5e932e4f5b Post-release version bump 2019-05-01 08:53:59 +00:00
Colin Walters
bc13e228d1 Bump to 0.3.3
I messed up 0.3.2 since I thought we'd done a post-release
bump but we hadn't.
v0.3.3
2019-05-01 08:51:47 +00:00
Simon McVittie
8f457ee286 tests: Ensure that tmpfs with oldroot/newroot doesn't appear in container
Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #305
Approved by: cgwalters
v0.3.2
2019-03-06 13:41:29 +00:00
Simon McVittie
efc89e3b93 Don't create our own temporary mount point for pivot_root
An attacker could pre-create /tmp/.bubblewrap-$UID and make it a
non-directory, non-symlink (in which case mounting our tmpfs would fail,
causing denial of service), or make it a symlink under their control
(potentially allowing bad things if the protected_symlinks sysctl is
not enabled).

Instead, temporarily mount the tmpfs on a directory that we are sure
exists and is not attacker-controlled. /tmp (the directory itself, not
a subdirectory) will do.

Fixes: #304
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=923557
Signed-off-by: Simon McVittie <smcv@debian.org>

Closes: #305
Approved by: cgwalters
2019-03-06 13:41:29 +00:00
Jakub Wilk
1622673a4d Print "Out of memory" on stderr, not stdout
Closes: #303
Approved by: smcv
2019-02-26 17:45:46 +00:00
Jakub Wilk
cc44544f8c Fix typos
Closes: #302
Approved by: smcv
2019-02-26 17:14:25 +00:00
Richard Maw
94147e233f bwrap: Report COMMAND exit code in json-status-fd
The exit code is only reported if it exited after a successful exec.

This is accomplished with a pipe, where the write end is closed on exec.

To distinguish between pipe-close pre-exec and at-exec,
data is written to the pipe immediately before calling exec
so if it is closed before exec the pipe is empty
and if it is closed during exec it contains a 1 byte value.

To further distinguish between a successful exec and a failed exec,
on exec failure a second value is written.

Signed-off-by: Richard Maw <richard.maw@codethink.co.uk>

Closes: #257

Closes: #293
Approved by: cgwalters
2018-11-05 16:18:37 +00:00
Richard Maw
f6acd3551e bwrap: add option json-status-fd to show child exit code
Signed-off-by: Richard Maw <richard.maw@codethink.co.uk>

Closes: #293
Approved by: cgwalters
2018-11-05 16:18:37 +00:00
Richard Maw
8fc5a96b3e Revert "README.md: Delete cat logo picture (not DFSG compliant)"
The source image is now public domain.

Closes: #294
Approved by: cgwalters
2018-10-04 13:02:52 +00:00
Timothy E Baldwin
5739fa370f Make lockdata long enough on 32-bit with 64-bit file pointers.
Closes: #288
Approved by: cgwalters
2018-10-01 15:36:24 +00:00
Simon McVittie
591b9dd90f man page: Describe --chdir, not nonexistent --cwd
Fixes: https://github.com/projectatomic/bubblewrap/issues/291
Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #292
Approved by: cgwalters
2018-10-01 12:52:30 +00:00
Iain Lane
0148dd34bb tests: Handle systems without merged-/usr
For the non-suid case, we were assuming that the host system would have
merged /usr (e.g. /bin -> /usr/bin). This isn't yet the case for all
distros, so let's handle both.

Closes: #290
Approved by: smcv
2018-09-28 15:43:16 +00:00
Alexander Larsson
e7b517f409 Post-release version bump to 0.3.1
This is useful because you can then test for new features.

Closes: #285
Approved by: cgwalters
v0.3.1
2018-08-09 13:34:51 +00:00
Patrick Griffis
d3515d80d4 Add --bind-try options
These ignore source files not existing which allows bwrap using
applications to avoid repeatedly checking if files exist.

Closes: #283
Approved by: alexlarsson
2018-08-09 13:01:15 +00:00
chocolateboy
62e42c971f Fix doc typo
Closes: #280
Approved by: cgwalters
2018-07-26 13:20:26 +00:00
Colin Walters
b3906bbf1a Use "tmpfs" instead of empty string for mount
The empty string provokes kernel bugs:
https://marc.info/?l=linux-fsdevel&m=153138504004854&w=2

And we were using "tmpfs" for the other tmpfs mount path.

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1599954

Closes: #278
Approved by: jlebon
2018-07-17 17:26:36 +00:00
Colin Walters
ace88fca7a Release 0.3.0
- Now with more recursion!
 - Add support for `--`
 - Minor memory leak fixes

Closes: #277
Approved by: giuseppe
v0.3.0
2018-07-11 15:32:00 +00:00
Olivier Blin
2105ff8ba4 Fix leak detected by LSan/ASan
Some variables like base_path ("/run/user/%d/.bubblewrap") are
declared with the cleanup attribute in main(), but this cleanup is not
run when in the parent process, since it calls exit() in monitor_child().

Use return statements instead of exit() so that cleanup attributes
will be run.

Closes: #271
Approved by: smcv
2018-06-14 18:26:27 +00:00
Colin Walters
5991dab74b ci: Update to FAH27
Just in time before FAH28 is out!

Closes: #262
Approved by: smcv
2018-06-06 18:30:14 +00:00
Giuseppe Scrivano
56609f8647 bwrap, pivot_root: do not require write access to the rootfs
Keep a reference to the previous working directory and use it for the
umount.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #256
Approved by: cgwalters
2018-04-30 16:50:19 +00:00
Giuseppe Scrivano
04a212062b bwrap: do not always make /proc/{sys,sysrq-trigger,irq} ro
Skip these mounts when the process will keep CAP_SYS_ADMIN as it will
anyway able to umount them.

This fix the case of running bwrap inside of a bwrap with a new pid
namespace and mount /proc.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #256
Approved by: cgwalters
2018-04-30 16:50:19 +00:00
Colin Walters
3ce7c8281f Use pivot_root() instead of chroot() for final root
This is preparatory work for supporting recursive bwrap. Without this, using
`mount()` on the second `/` won't work, since it won't be a mount point.

Closes: #256
Approved by: cgwalters
2018-04-30 16:50:19 +00:00
Simon McVittie
fbee75d551 Add "--" pseudo-argument to end option parsing
This shouldn't matter unless someone wants to run an inadvisably-named
executable, but it's best-practice for commands that pass on some
of their arguments to a subsequent command.

It allows an invocation like:

    bwrap --ro-bind /container / -- "$@"

to search PATH in the container for an executable named according to
"$1", even if $1 has a pathological value like
"--this-has-a-stupid-name--", or even a value that might be
deliberately trying to break bwrap's parsing like "--bind".

Fixes: #259
Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #261
Approved by: cgwalters
2018-04-23 21:06:05 +00:00
Alexander Larsson
5f27455af6 Release 0.2.1
Closes: #260
Approved by: alexlarsson
v0.2.1
2018-04-06 15:06:15 +00:00
Alexander Larsson
1e90a18a08 Don't rely on mkdir returning EEXISTS (fixing NFS)
For NFS mounts if we call mkdir() on a read-only mount (such as when
we've created a read-only bind mount) the kernel will nor return EEXIST
even when the directory exists, instead returning EROFS.

So, we add (and use) an ensure_dir() helper that stats before calling
mkdir.

Closes: #258
Approved by: giuseppe
2018-03-16 22:07:13 +00:00
Simon McVittie
3c488585bd userns-block-fd: Add support for Python 3
According to PEP 394, the python command is meant to be Python 2
until at least 2020, so in practice this script will be run with
Python 2 for now (except on Arch Linux); but it seems good to be
more future-proof.

In Python 3, os.write() takes a bytestring (bytes object), not a
text string (str/unicode object). In Python 2 ≥ 2.6, the b'' syntax
is supported and gives a str object, because that was a bytestring
in Python 2; either way, b'1' is an acceptable argument to os.write().

In Python ≥ 3.4, the result of os.pipe() is close-on-exec
(non-inheritable) by default, so undo that where needed.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #246
Approved by: giuseppe
2017-11-03 17:55:16 +00:00
Simon McVittie
b8fa270e89 userns-block-fd: Search the PATH for bwrap
This means we can use it with an installed bwrap, which seems a more
common use of a demo script than a just-compiled bwrap, and is
consistent with the shell scripts.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #246
Approved by: giuseppe
2017-11-03 17:55:16 +00:00