Commit Graph

8199 Commits

Author SHA1 Message Date
Hervé Beraud
c70de0eabb apparmor: catch config file opening error
Improve config file error opening management
and improve main code block.

Execute this python script during CI to avoid
regressions

Signed-off-by: Hervé Beraud <hberaud@redhat.com>
2019-02-12 23:09:04 +01:00
Stéphane Graber
b091c341d5
Merge pull request #2846 from brauner/2019-02-12/CVE-2019-5736
rexec: make rexecution opt-in for library callers
2019-02-12 12:14:19 -05:00
Christian Brauner
d3a9befc86
rexec: make rexecution opt-in for library callers
We cannot rexecute the liblxc shared library unconditionally as this would
break most of our downstreams. Here are some scenarios:
- anyone performing a dlopen() on the shared library (e.g. users of the LXC
  Python bindings)
- LXD as it needs to know the absolute path to its own executable based on
  /proc/self/exe etc.

This commit makes the rexecution of liblxc conditional on whether the
LXC_MEMFD_REXEC environment variable is set or not. If it is then liblxc is
unconditionally rexecuted.

The only relevant attack vector exists for lxc-attach which we simply reexecute
unconditionally.

Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-12 17:58:34 +01:00
Stéphane Graber
b88ccedc1e
Merge pull request #2844 from brauner/2019-02-11/licensing+
string_utils.h: fix wrong licensing
2019-02-11 17:31:14 -05:00
Christian Brauner
84fa5acacc
string_utils.h: fix wrong licensing
liblxc has always been meant to be LGPLv2.1+ as reflected by the many
downstreams projects and bindings which are themselves under LGPLv2.1+ or other
licenses which would be incompatible with linking against a GPLv2+ library.

It's pretty normal for a library to be LGPL while binaries are GPL as a GPL
library would only ever be usable by other GPL-only projects, which isn't the
case for very many of the liblxc downstreams.

The issue here is really carelessness. None of those GPL headers were put there
intentionally, instead being wrongly copy/pasted from other parts of the
codebase which is indeed intended to be GPLv2+. This is also made clear in our
CONTRIBUTING file in this repository:

Licensing for new files:
------------------------

LXC is made of files shipped under a few different licenses.

Anything that ends up being part of the LXC library needs to be released
under LGPLv2.1+ or a license compatible with it (though the latter will
only be accepted for cases where the code originated elsewhere and was
imported into LXC).

Language bindings for the libraries need to be released under LGPLv2.1+.

Anything else (non-libraries) needs to be Free Software and needs to be
allowed to link with LGPLv2.1+ code (if needed). LXC upstream prefers
LGPLv2.1+ or GPLv2 for those.

When introducing a new file into the project, please make sure it has a
copyright header making clear under which license it's being released
and if it doesn't match the criteria described above, please explain
your decision on the lxc-devel mailing-list when submitting your patch.

This is intended to switch over files to LGPLv2.1+ to which end we have
collected ACKs from relevant people.
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>
Fabrice Fontaine <fontaine.fabrice@gmail.com>
Josh Soref <jsoref@gmail.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Acked-by: Josh Soref <jsoref@gmail.com>
2019-02-11 23:10:32 +01:00
Stéphane Graber
9581e69761
Merge pull request #2843 from brauner/2019-02-11/fix_licensing_brauner
fix licensing headers
2019-02-11 11:58:23 -05:00
Christian Brauner
7043a15df3
syscall_wrappers: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>
Aleksa Sarai <cyphar@cyphar.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:35:08 +01:00
Christian Brauner
c423a0a7d8
ringbuf.h: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:35:08 +01:00
Christian Brauner
cd4a865dd6
memory_utils: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:35:08 +01:00
Christian Brauner
2b3153a882
rexec: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>
Aleksa Sarai <asarai@suse.de>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: Aleksa Sarai <cyphar@cyphar.com>
2019-02-11 17:35:07 +01:00
Christian Brauner
3877934c7a
api_extensions: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:35:07 +01:00
Christian Brauner
6aae19f7c8
file_utils.h: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:33:18 +01:00
Christian Brauner
b80e01bda3
compiler: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:23:52 +01:00
Christian Brauner
7fd02ed74d
api_extensions: fix wrong licensing
/* Affected People */
Christian Brauner <christian.brauner@ubuntu.com>

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 17:23:22 +01:00
Stéphane Graber
9c63d38cec
Merge pull request #2841 from brauner/2019-02-11/fix_android
include: add fexecve() for Android's Bionic
2019-02-11 10:27:57 -05:00
Christian Brauner
9d361e0fd4
include: add fexecve() for Android's Bionic
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 16:16:10 +01:00
Christian Brauner
6400238d08
CVE-2019-5736 (runC): rexec callers as memfd
Adam Iwaniuk and Borys Popławski discovered that an attacker can compromise the
runC host binary from inside a privileged runC container. As a result, this
could be exploited to gain root access on the host. runC is used as the default
runtime for containers with Docker, containerd, Podman, and CRI-O.

The attack can be made when attaching to a running container or when starting a
container running a specially crafted image.  For example, when runC attaches
to a container the attacker can trick it into executing itself. This could be
done by replacing the target binary inside the container with a custom binary
pointing back at the runC binary itself. As an example, if the target binary
was /bin/bash, this could be replaced with an executable script specifying the
interpreter path #!/proc/self/exe (/proc/self/exec is a symbolic link created
by the kernel for every process which points to the binary that was executed
for that process). As such when /bin/bash is executed inside the container,
instead the target of /proc/self/exe will be executed - which will point to the
runc binary on the host. The attacker can then proceed to write to the target
of /proc/self/exe to try and overwrite the runC binary on the host. However in
general, this will not succeed as the kernel will not permit it to be
overwritten whilst runC is executing. To overcome this, the attacker can
instead open a file descriptor to /proc/self/exe using the O_PATH flag and then
proceed to reopen the binary as O_WRONLY through /proc/self/fd/<nr> and try to
write to it in a busy loop from a separate process. Ultimately it will succeed
when the runC binary exits. After this the runC binary is compromised and can
be used to attack other containers or the host itself.

This attack is only possible with privileged containers since it requires root
privilege on the host to overwrite the runC binary. Unprivileged containers
with a non-identity ID mapping do not have the permission to write to the host
binary and therefore are unaffected by this attack.

LXC is also impacted in a similar manner by this vulnerability, however as the
LXC project considers privileged containers to be unsafe no CVE has been
assigned for this issue for LXC. Quoting from the
https://linuxcontainers.org/lxc/security/ project's Security information page:

"As privileged containers are considered unsafe, we typically will not consider
new container escape exploits to be security issues worthy of a CVE and quick
fix. We will however try to mitigate those issues so that accidental damage to
the host is prevented."

To prevent this attack, LXC has been patched to create a temporary copy of the
calling binary itself when it starts or attaches to containers. To do this LXC
creates an anonymous, in-memory file using the memfd_create() system call and
copies itself into the temporary in-memory file, which is then sealed to
prevent further modifications. LXC then executes this sealed, in-memory file
instead of the original on-disk binary. Any compromising write operations from
a privileged container to the host LXC binary will then write to the temporary
in-memory binary and not to the host binary on-disk, preserving the integrity
of the host LXC binary. Also as the temporary, in-memory LXC binary is sealed,
writes to this will also fail.

Note: memfd_create() was added to the Linux kernel in the 3.17 release.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Co-Developed-by: Alesa Sarai <asarai@suse.de>
Acked-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-11 13:59:21 +01:00
Stéphane Graber
9913ac1b42
Merge pull request #2839 from brauner/2019-02-10/handle_carriage_return
parse: handle \r
2019-02-10 18:21:49 -05:00
Christian Brauner
8336d7be29
parse: handle \r
Closes #2838.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-10 23:55:17 +01:00
Wolfgang Bumiller
b49c4e2de4
Merge pull request #2836 from brauner/2019-02-10/fix_cgfsng_driver
cgroup: bugfixes
2019-02-10 11:34:41 +01:00
Christian Brauner
c74da4abd2
cgfsng: fix cgroup creation
When cgroup creation failed we reset container_cgroup to NULL to avoid
issues with __cleanup__. Fix that logic:
- add steal_ptr() based on take_ptr()
- move stealing the pointer out of the loop

lxc ctImport 20190210050705.858 DEBUG    network - network.c:instantiate_veth:202 - Instantiated veth "vethGQMH7I/vethSPXNL3", index is "272"
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:mkdir_eexist_on_last:1262 - File exists - Failed to create directory "/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:container_create_path_for_hierarchy:1302 - Failed to create cgroup "/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:cgfsng_payload_create:1431 - Failed to create cgroup "/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 INFO     cgfsng - cgroups/cgfsng.c:cgfsng_payload_create:1441 - The container uses "lxc.payload/ctImport-0" as cgroup
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:mkdir_eexist_on_last:1262 - File exists - Failed to create directory "/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:container_create_path_for_hierarchy:1302 - Failed to create cgroup "/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 ERROR    cgfsng - cgroups/cgfsng.c:cgfsng_payload_create:1431 - Failed to create cgroup "/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 INFO     cgfsng - cgroups/cgfsng.c:cgfsng_payload_create:1441 - The container uses "(null)" as cgroup

Fixes: d97919abf2 ("cgroups: partially switch to cleanup macros")
Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-10 10:58:04 +01:00
Christian Brauner
d99d5c935a
cgfsng: coding style for cgfsng_payload_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-10 10:57:53 +01:00
Christian Brauner
f2668eea50
cgfsng: coding style for cgfsng_monitor_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-10 10:57:41 +01:00
Stéphane Graber
41f808b29a
Merge pull request #2832 from brauner/2019-02-08/add_coccinelle
coccinelle support
2019-02-09 16:58:36 -05:00
Stéphane Graber
3e0aac16db
Merge pull request #2829 from brauner/2019-02-08/capabilities
caps: check uid and euid
2019-02-09 16:57:01 -05:00
Christian Brauner
5701771461
coccinelle: use standard exit identifiers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 11:23:54 +01:00
Christian Brauner
51a8a74c07
coccinelle: s/while({1,true})/for(;;)/
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 11:05:12 +01:00
Christian Brauner
99dc3a338d
coccinelle: add coccinelle support
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 11:05:10 +01:00
Christian Brauner
f57860aca9
Merge pull request #2833 from brauner/2019-02-09/bugfixes
bugfixes
2019-02-09 11:03:42 +01:00
Christian Brauner
6425271d04
lxc-init: exit with error on wait failure
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 01:35:44 +01:00
Christian Brauner
f7a0c6ee2a
start: prevent signed-issues
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 01:33:18 +01:00
Christian Brauner
0dbdb99e3b
cgfsng: remove unnecessary check
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 01:31:52 +01:00
Christian Brauner
6403a6671c
commands: remove unnecessary check
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-09 01:28:52 +01:00
Serge Hallyn
884b37d091
Merge pull request #2827 from brauner/2019-02-07/auto_cleanup
cgroups: partially switch to cleanup macros
2019-02-08 15:57:37 -06:00
Christian Brauner
df9bf8ca39
caps: check uid and euid
When we are running inside of a user namespace getuid() will return a
non-zero uid. So let's check euid as well to make sure we correctly drop
capabilities

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-08 15:11:46 +01:00
Christian Brauner
d97919abf2
cgroups: partially switch to cleanup macros
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-08 13:40:17 +01:00
Christian Brauner
42bd57bdbd
Merge pull request #2825 from brauner/lxc/master
README: add LGTM
2019-02-06 12:24:48 +01:00
Christian Brauner
a62cf72a8b
README: add LGTM
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 12:23:17 +01:00
Wolfgang Bumiller
d6a4505542
Merge pull request #2821 from brauner/2019-02-05/remove_stack_allocation
tree-wide: wipe alloca() from the codebase
2019-02-06 12:10:48 +01:00
Christian Brauner
57e2af15ed
lxc-unshare: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
e2c6671d17
overlay: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
3206805085
rbd: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
9371d3f2b6
nbd: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
007bb915d5
lvm: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
6b4e204c7b
loop: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
2530ba9597
terminal: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:58 +01:00
Christian Brauner
97f35ce6f8
string_utils: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:57 +01:00
Christian Brauner
643c9ec994
storage: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:57 +01:00
Christian Brauner
4ffeaf2766
start: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:57 +01:00
Christian Brauner
6421783a26
pam_cgfs: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:57 +01:00