Commit Graph

5283 Commits

Author SHA1 Message Date
Stéphane Graber
1fbb7fae52 Merge pull request #1329 from brauner/2016-11-27/log_signal_error_on_container_stop
lxccontainer: log failure to send sig to init pid
2016-11-27 01:00:55 -05:00
Stéphane Graber
d0f03fd752 Merge pull request #1328 from brauner/2016-11-27/make_running_hooks_async_signal_safe
conf: remove thread-unsafe strsignal + improve log
2016-11-27 00:10:53 -05:00
Christian Brauner
591614a762
lxccontainer: log failure to send sig to init pid
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-27 06:01:36 +01:00
Stéphane Graber
1e0a00460a Merge pull request #1327 from brauner/2016-11-26/make_lxc_monitord_async_signal_safe
lxc_monitord: make lxc-monitord async signal safe
2016-11-26 22:56:58 -05:00
Christian Brauner
062b72c6b9
conf: remove thread-unsafe strsignal + improve log
The thread-unsafe functions strsignal() is called in run_buffer() which in turn
is called in run_buffer_argv() which is responsible for running __all__ lxc
hooks. This is pretty dangerous for multi-threaded users like LXD.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-27 04:44:06 +01:00
Christian Brauner
d0dacf05a6
lxc_monitord: make lxc-monitord async signal safe
Before lxc_monitord called lxc_monitord_cleanup() from a signal handler.  This
function calls a bunch of async signal unsafe functions and basically begs for
deadlocks. This commit switches lxc-monitord to using sigsetjmp() and
siglongjmp() in the signal handler to jump to a cleanup label that call
lxc_monitord_cleanup(). In this way, we avoid using async signal unsafe
functions.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-27 04:28:01 +01:00
Stéphane Graber
8d58eea994 Merge pull request #1326 from brauner/2016-11-26/improve_logging_for_monitord
lxc_monitord: improve log + set log level to DEBUG
2016-11-26 15:13:41 -05:00
Christian Brauner
60e4f6fa4d
lxc_monitord: improve log + set log level to DEBUG
Setting loglevel to DEBUG will allow us to retrieve more useful information in
case something goes wrong. The total size of the log will not increase
significantly.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 19:49:27 +01:00
Stéphane Graber
888ccbf1d1 Merge pull request #1325 from brauner/2016-11-26/improve_command_logging
commands: improve logging
2016-11-26 12:57:40 -05:00
Stéphane Graber
6ade052281 Merge pull request #1324 from brauner/2016-11-26/more_logging_for_monitor
monitor: add more logging
2016-11-26 12:57:16 -05:00
Stéphane Graber
d44a6abde4 Merge pull request #1322 from brauner/2016-11-26/remove_werror_vla
configure: remove -Werror=vla
2016-11-26 12:56:54 -05:00
Christian Brauner
08aa08fe57
commands: improve logging
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 09:28:51 +01:00
Christian Brauner
aec1ea6261
monitor: add more logging
Execing lxc-monitord is quite a crucial step so let's be very obsessive about
logging possible errors to guide us in debugging.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 07:40:59 +01:00
Christian Brauner
1154e59065 Merge pull request #1323 from hallyn/2016-11-25/droplock
lvm: supress warnings about leaked files
2016-11-26 01:31:22 -05:00
Christian Brauner
ce44bee117
configure: remove -Werror=vla
Because we include a header that uses a vla (/me scoffs at header).

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 07:07:25 +01:00
Serge Hallyn
79816ab3f4 lvm: supress warnings about leaked files
Closes #1283

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2016-11-26 00:07:15 -06:00
Stéphane Graber
e7e49f6003 Merge pull request #1321 from brauner/2016-11-25/cleanup_monitor
cleanup monitor + improve log
2016-11-26 00:22:19 -05:00
Stéphane Graber
d53d0a01a9 Merge pull request #1315 from brauner/2016-11-23/memfd_create
conf, criu: add make_anonymous_mount_file()
2016-11-25 23:50:28 -05:00
Christian Brauner
487b14b6ae
monitor: log which pipe fd is currently used
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 05:30:36 +01:00
Christian Brauner
292b1d177a
monitor: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 05:30:34 +01:00
Stéphane Graber
3f37ede22a Merge pull request #1320 from brauner/2016-11-25/remove_vlas
tree-wide: remove any variable length arrays
2016-11-25 23:04:21 -05:00
Christian Brauner
5ef5c9a344
conf, criu: add make_anonymous_mount_file()
Before we used tmpfile() to write out mount entries for the container. This
requires a writeable /tmp file system which can be a problem for systems where
this filesystem is not present. This commit switches from tmpfile() to using
the memfd_create() syscall. It allows us to create an anonymous tmpfs file (And
is somewhat similar to mmap().) which is automatically deleted as soon as any
references to it are dropped. In case we detect that syscall is not
implemented, we fallback to using tmpfile().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 04:28:03 +01:00
Christian Brauner
413c294f75 configure: check for memfd_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 04:17:14 +01:00
Christian Brauner
8f3e280e77 conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 04:15:40 +01:00
Christian Brauner
de3c491bff
tree-wide: remove any variable length arrays
They are pointless and marked optional since C11.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-26 03:56:06 +01:00
Stéphane Graber
1145b82876 Merge pull request #1319 from brauner/2016-11-25/fix_logging_race
log: fix race
2016-11-25 18:20:25 -05:00
Christian Brauner
d8f2dda5a5
configure: do not allow variable length arrays
There pointless and marked as optional since C11.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-25 22:02:28 +01:00
Christian Brauner
450b6d3d68
log: use N/A if getpid() != gettid() when threaded
Sample log output:

    lxc 20161125201943.819 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 54.
--> lxc N/A                INFO     lxc_monitor - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc
    lxc 20161125201943.958 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
--> lxc N/A                DEBUG    lxc_commands - commands.c:lxc_cmd_get_state:579 - 'lxc-test-concurrent-0' is in 'RUNNING' state
    lxc 20161125201943.960 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
    lxc 20161125201944.009 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 3.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-25 20:24:26 +01:00
Christian Brauner
0dcdbf8a67
log: fix race
localtime_r() can lead to deadlocks because it calls __tzset() and
__tzconvert() internally. The deadlock stems from an interaction between these
functions and the functions in monitor.c and commands.{c,h}. The latter
functions will write to the log independent of the container thread that is
currently running. Since the monitor fork()ed it seems to duplicate the mutex
states of the time functions mentioned above causing the deadlock.
As a short termm fix, I suggest to simply disable receiving the time when
monitor.c or command.{c,h} functions are called. This should be ok, since the
[lxc monitor] will only emit a few messages and thread-safety is currently more
important than beautiful logs. The rest of the log stays the same as it was
before.

Here is an example output from logs where I printed the pid and tid of the
process that is currently writing to the log:

            lxc 20161125170200.619 INFO     lxc_start:   18695-18695: - start.c:lxc_check_inherited:243 - Closed inherited fd: 23.
            lxc 20161125170200.640 DEBUG    lxc_start:   18677-18677: - start.c:__lxc_start:1334 - Not dropping CAP_SYS_BOOT or watching utmp.
            lxc 20161125170200.640 INFO     lxc_cgroup:  18677-18677: - cgroups/cgroup.c:cgroup_init:68 - cgroup driver cgroupfs-ng initing for lxc-test-concurrent-0

----------> lxc 20150427012246.000 INFO     lxc_monitor: 13017-18622: - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc

            lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:filter_and_set_cpus:478 - No isolated cpus detected.
            lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:handle_cpuset_hierarchy:648 - "cgroup.clone_children" was already set to "1".

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-25 20:04:23 +01:00
Christian Brauner
6a22e86258
configure: check whether gettid() is declared
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-25 20:03:50 +01:00
Stéphane Graber
8d3786cb75 Merge pull request #1317 from brauner/2016-11-24/cleanup_attach
cleanup attach
2016-11-25 12:46:03 -05:00
Stéphane Graber
b5e3950161 Merge pull request #1318 from brauner/2016-11-25/fix_logging_race
log: use thread-safe localtime_r()
2016-11-24 21:22:04 -05:00
Christian Brauner
b4c424743a
log: use thread-safe localtime_r()
This fixes a race in liblxc logging which can lead to deadlocks. The reproducer
for this issue before this is to simply compile with --enable-tests and then
run:

    lxc-test-concurrent -j 20 -m create,start,stop,destroy -D

which should deadlock.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-25 02:42:51 +01:00
Christian Brauner
8ce83369ef
attach: non-functional changes
- improve logging
- simplify functions

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-24 08:34:10 +01:00
Christian Brauner
82b1f317c8
attach: simplify lsm_openat()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-24 07:58:01 +01:00
Christian Brauner
81f466d05f attach: do not send procfd to attached process
So far, we opened a file descriptor refering to proc on the host inside the
host namespace and handed that fd to the attached process in
attach_child_main(). This was done to ensure that LSM labels were correctly
setup. However, by exploiting a potential kernel bug, ptrace could be used to
prevent the file descriptor from being closed which in turn could be used by an
unprivileged container to gain access to the host namespace. Aside from this
needing an upstream kernel fix, we should make sure that we don't pass the fd
for proc itself to the attached process. However, we cannot completely prevent
this, as the attached process needs to be able to change its apparmor profile
by writing to /proc/self/attr/exec or /proc/self/attr/current. To minimize the
attack surface, we only send the fd for /proc/self/attr/exec or
/proc/self/attr/current to the attached process. To do this we introduce a
little more IPC between the child and parent:

	 * IPC mechanism: (X is receiver)
	 *   initial process        intermediate          attached
	 *        X           <---  send pid of
	 *                          attached proc,
	 *                          then exit
	 *    send 0 ------------------------------------>    X
	 *                                              [do initialization]
	 *        X  <------------------------------------  send 1
	 *   [add to cgroup, ...]
	 *    send 2 ------------------------------------>    X
	 *						[set LXC_ATTACH_NO_NEW_PRIVS]
	 *        X  <------------------------------------  send 3
	 *   [open LSM label fd]
	 *    send 4 ------------------------------------>    X
	 *   						[set LSM label]
	 *   close socket                                 close socket
	 *                                                run program

The attached child tells the parent when it is ready to have its LSM labels set
up. The parent then opens an approriate fd for the child PID to
/proc/<pid>/attr/exec or /proc/<pid>/attr/current and sends it via SCM_RIGHTS
to the child. The child can then set its LSM laben. Both sides then close the
socket fds and the child execs the requested process.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-23 11:13:49 -05:00
Christian Brauner
8f227cdcb8 Merge pull request #1314 from ccope/static-mac
Configure a static MAC address on the LXC bridge
2016-11-22 23:04:45 -05:00
Cam Cope
84432621ed
Configure a static MAC address on the LXC bridge
Signed-off-by: Cam Cope <cam@dropbox.com>
2016-11-22 15:16:32 -08:00
Stéphane Graber
dea1cfbd16 Merge pull request #1312 from brauner/2016-11-22/fix_lxc_unshare_parsing
tools: replace non-standard namespace identifiers
2016-11-22 12:12:21 -05:00
Stéphane Graber
70c9390ea6 Merge pull request #1313 from brauner/2016-11-22/fix_lxc_tests
tests: remove overflow tests
2016-11-22 12:10:41 -05:00
Christian Brauner
777eb3ba25
tests: remove overflow tests
They do not behave correctly on some architectures, so let's remove them for
now and come up with better ones later.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-22 17:38:18 +01:00
Christian Brauner
9420e0c278
tools: replace non-standard namespace identifiers
The identifiers for namespaces used with lxc-unshare and lxc-attach as given on
the manpage do not align with the standard identifiers. This affects network,
mount, and uts namespaces. The standard identifiers are: "mnt", "uts", and
"net" whereas lxc-unshare and lxc-attach use "MOUNT", "UTSNAME", and "NETWORK".
I'm weary to hack this into namespace.{c.h} by e.g. adding additional members
to the ns_info struct or to special case this in lxc_fill_namespace_flags().
Internally, we should only accept standard identifiers to ensure that we are
always correctly aligned with the kernel. So let's use some cheap memmove()s to
replace them by their standard identifiers in lxc-unshare and lxc-attach.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2016-11-22 17:27:45 +01:00
Serge Hallyn
7688de67c6 Merge pull request #1256 from brauner/2016-09-06/remove_atoi
remove atoi
2016-11-21 22:46:21 -06:00
Christian Brauner
d47f1b43c6
confile: non-functional change
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:47:06 +01:00
Christian Brauner
31299e70d8
tools/lxc_console: use lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:47:04 +01:00
Christian Brauner
63610340c2
tools/lxc_autostart: use lxc_safe_{int,long}()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:47:02 +01:00
Christian Brauner
98de68602c
tools/lxc_ls: use lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:19 +01:00
Christian Brauner
45419e74ef
tools/lxc_top: use lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:17 +01:00
Christian Brauner
2a9a36aa0e
tools/lxc_stop: use lxc_safe_long()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:15 +01:00
Christian Brauner
cb9df6d4a7
tests: add unit tests for lxc_safe_long()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:13 +01:00