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

366 Commits

Author SHA1 Message Date
Harald Kubota
bdeb727221 Copy _bwrap zsh completion on install 2021-04-25 12:51:54 +09:00
Harald Kubota
6db33cdcb2 Fix --cap-add and --cap-drop completions 2021-03-12 21:23:04 +09:00
Harald Kubota
741f371e22 Add zsh completion 2021-03-12 21:10:06 +09:00
Colin Walters
e1b11e6592 Merge pull request #408 from giuseppe/fix-man-page
bwrap.xml: clarify BPF variant
2021-02-22 12:54:31 -05:00
Giuseppe Scrivano
4af205a7f1 bwrap.xml: clarify BPF variant
seccomp uses cBPF, not eBPF.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-02-22 17:02:01 +01:00
Alexander Larsson
bae85baf72 Merge pull request #389 from mwleeds/fix-op-shadow
Fix shadow of previous local
2020-09-14 10:34:16 +02:00
Phaedrus Leeds
a6f02a3043 Fix shadow of previous local
Fix the build failure in https://github.com/flatpak/flatpak/pull/3853
2020-09-11 21:07:19 -07:00
Colin Walters
4e310cadf6 Merge pull request #386 from juergbi/proc-erofs
Accept EROFS for access() check of /proc entries
2020-08-25 11:48:33 -04:00
Colin Walters
4f76b9e421 Merge pull request #383 from TimothyEBaldwin/fixtest
Fix broken test
2020-08-25 11:28:55 -04:00
Jürg Billeter
4c35d7a5f9 Accept EROFS for access() check of /proc entries
This is required to work in a Docker container.
2020-08-18 17:59:35 +02:00
Timothy E Baldwin
598e586c91 Fix Test - $BWRAP is inaccessable when run sudo root
Ironically, if running sudo root the path to test-bwrap may
be unreachable in the user namespace as root does not have
permission, and CAP_DAC_OVERRIDE only works for mapped uids.

Fix by using /proc/self/exe for nested bwrap.
2020-07-30 21:48:39 +01:00
Timothy E Baldwin
2564824e10 Fix Test - /proc mismatches pid namespace
`--bind /proc /proc` and `--unshare-all` results in `/proc` being
for the wrong pid namespace causing `namespace_ids_read` to fail,
either reading the wrong process dying with an error.

For example try: unshare -rpfm --mount-proc make check
2020-07-30 21:48:39 +01:00
Colin Walters
af30473596 Merge pull request #379 from smcv/no-new-typos
Correct name of PR_SET_NO_NEW_PRIVS in error message
2020-05-23 11:08:33 -04:00
Simon McVittie
e8f67bc6c9 Correct name of PR_SET_NO_NEW_PRIVS in error message
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-05-23 15:33:20 +01:00
Colin Walters
a9700fa13c Merge pull request #374 from TomSweeneyRedHat/sec
Add Security Policy
2020-05-19 14:42:14 -04:00
Colin Walters
04ad0edef0 Merge branch 'master' into sec 2020-05-19 14:42:02 -04:00
Colin Walters
4e9e6f7ee4 Merge pull request #377 from cgwalters/silence-is-golden
Add MS_SILENT to most mount() invocations
2020-05-19 08:21:05 -04: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
TomSweeneyRedHat
fade5ba881 Add Security Policy
As the title says

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2020-05-09 14:06:38 -04:00
Alexander Larsson
5feb64dc60 Bump version to 0.4.1 v0.4.1 2020-03-30 15:10:44 +02:00
Alexander Larsson
1f7e2ad948 Merge pull request from GHSA-j2qp-rvxj-43vj
Fix setuid vulnerability
2020-03-30 15:08:41 +02:00
Alexander Larsson
38dd7e4bb8 Merge pull request #354 from ckastner/master
tests: Update output patterns for libcap >= 2.29
2020-03-30 12:46:53 +02:00
Alexander Larsson
6f815ceead drop_privs: More explicit argument name
changed_uid => already_changed_uid
2020-03-30 12:31:36 +02:00
Alexander Larsson
61955e933d Don't support --userns2 in setuid mode
We already don't support --userns, so supporting --userns2 seems
like asking for problems with no upside.
2020-03-27 08:28:26 +01:00
Alexander Larsson
5404a15d34 Don't rely on geteuid() to know when to switch back from setuid root
As pointed out by Stephen Röttger <sroettger@google.com>, in
drop_privs() we only drop root in the setuid case if geteuid() is
0. Typically geteuid() == 0 means we were setuid root and have not yet
switched away from it.

However, it is possible to make the geteuid call fail by passing a
--userns2 namespace which doesn't have 0 mapped (i.e. where geteuid()
will return the owerflow uid instead).

If you do this, the pid 1 process in the sandbox will continue running
as host uid 0, while dropping the dumpable flag, and at this point the
user can ptrace attach the process and have root permissions.

We fix this by not relying on the geteuid() call to know when we need
to drop root uid, but rather keep track of whether we already switched
from it.
2020-03-26 15:36:44 +01:00
Alexander Larsson
3ace81ca07 Merge pull request #351 from containers/drop-cap-bounding-set-2
Ensure we're always clearing the cap bounding set
2020-03-16 14:18:07 +01:00
Christian Kastner
8b170a9a91 tests: Update output patterns for libcap >= 2.29 2020-02-19 10:07:10 +01:00
Alexander Larsson
a9556223de Ensure we're always clearing the cap bounding set
In the non-setuid case if we're not running as uid 0 in the final
namespace but we need devpts (e.g. use --dev) we mount the devpts as
uid and then change to the actual numberical uid at the end. This
final unshare(CLONE_NEWPID) will reset tha cap bounding set we
previously cleared.

This change clears the cap bounding set again after the unshare call.

This is not really a security problem because we always set
NO_NEW_PRIVS which is essentially a superset of capability bounds, so
there is no way the container can use the bounding set to gain
caps. However its nice to be consistent and not display setting
which look like potential problems.

Fixes https://github.com/containers/bubblewrap/issues/350

See 6b3dd4f10c for the original change
the drops the cap bounding set in the first location.
2020-02-17 09:17:28 +01:00
Alexander Larsson
8e27bbbde7 Merge pull request #347 from TomSweeneyRedHat/coc
Add Code of Conduct
2020-02-10 20:26:48 +01:00
TomSweeneyRedHat
515a1b120b Add Code of Conduct
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2020-02-08 15:40:04 -05:00
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