]> git.ipfire.org Git - thirdparty/lxc.git/log
thirdparty/lxc.git
8 years agolog: make sure that date is correctly formatted 1334/head
Christian Brauner [Tue, 29 Nov 2016 06:50:29 +0000 (07:50 +0100)] 
log: make sure that date is correctly formatted

- single digit months, days, hours, minutes, and seconds should always be
  preceded by a 0.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1331 from brauner/2016-11-27/use_sec_nanosec_since_epoch
Serge Hallyn [Tue, 29 Nov 2016 03:24:57 +0000 (21:24 -0600)] 
Merge pull request #1331 from brauner/2016-11-27/use_sec_nanosec_since_epoch

log: drop all timezone conversion functions

8 years agolog: annotate lxc_unix_epoch_to_utc() 1331/head
Christian Brauner [Tue, 29 Nov 2016 00:26:25 +0000 (01:26 +0100)] 
log: annotate lxc_unix_epoch_to_utc()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolog: use lxc_unix_epoch_to_utc()
Christian Brauner [Mon, 28 Nov 2016 21:19:02 +0000 (22:19 +0100)] 
log: use lxc_unix_epoch_to_utc()

This allows us to generate nice timestamps in a thread-safe manner without
relying on locale touching functions from any libc.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolog: add lxc_unix_epoch_to_utc()
Christian Brauner [Mon, 28 Nov 2016 21:08:37 +0000 (22:08 +0100)] 
log: add lxc_unix_epoch_to_utc()

Converts a unix time Epoch given by a struct timespec to a UTC string useable
in our logging functions. Maybe expanded to allow for more generic formatting.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolog: drop all timezone conversion functions
Christian Brauner [Sun, 27 Nov 2016 22:42:11 +0000 (23:42 +0100)] 
log: drop all timezone conversion functions

Our log functions need to make extra sure that they are thread-safe. We had
some problems with that before. This especially involves time-conversion
functions. I don't want to find any localtime() or gmtime() functions or
relatives in here. Not even localtime_r() or gmtime_r() or relatives. They all
fiddle with global variables and locking in various libcs. They cause deadlocks
when liblxc is used multi-threaded and no matter how smart you think you are,
you __will__ cause trouble using them.
(As a short example how this can cause trouble: LXD uses forkstart to fork off
a new process that runs the container. At the same time the go runtime LXD
relies on does its own multi-threading thing which we can't control. The
fork()ing + threading then seems to mess with the locking states in these time
functions causing deadlocks.)
The current solution is to be good old unix people and use the Epoch as our
reference point and simply use the seconds and nanoseconds that have past since
then. This relies on clock_gettime() which is explicitly marked MT-Safe with no
restrictions! This way, anyone who is really strongly invested in getting the
actual time the log entry was created, can just convert it for themselves. Our
logging is mostly done for debugging purposes so don't try to make it pretty.
Pretty might cost you thread-safety.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoutils: add macro __LXC_NUMSTRLEN
Christian Brauner [Sun, 27 Nov 2016 22:41:06 +0000 (23:41 +0100)] 
utils: add macro __LXC_NUMSTRLEN

This macro can be used to set or allocate a string buffer that can hold any
64bit representable number.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1329 from brauner/2016-11-27/log_signal_error_on_container_stop
Stéphane Graber [Sun, 27 Nov 2016 06:00:55 +0000 (01:00 -0500)] 
Merge pull request #1329 from brauner/2016-11-27/log_signal_error_on_container_stop

lxccontainer: log failure to send sig to init pid

8 years agoMerge pull request #1328 from brauner/2016-11-27/make_running_hooks_async_signal_safe
Stéphane Graber [Sun, 27 Nov 2016 05:10:53 +0000 (00:10 -0500)] 
Merge pull request #1328 from brauner/2016-11-27/make_running_hooks_async_signal_safe

conf: remove thread-unsafe strsignal + improve log

8 years agolxccontainer: log failure to send sig to init pid 1329/head
Christian Brauner [Sun, 27 Nov 2016 05:01:36 +0000 (06:01 +0100)] 
lxccontainer: log failure to send sig to init pid

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1327 from brauner/2016-11-26/make_lxc_monitord_async_signal_safe
Stéphane Graber [Sun, 27 Nov 2016 03:56:58 +0000 (22:56 -0500)] 
Merge pull request #1327 from brauner/2016-11-26/make_lxc_monitord_async_signal_safe

lxc_monitord: make lxc-monitord async signal safe

8 years agoconf: remove thread-unsafe strsignal + improve log 1328/head
Christian Brauner [Sun, 27 Nov 2016 03:44:06 +0000 (04:44 +0100)] 
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>
8 years agolxc_monitord: make lxc-monitord async signal safe 1327/head
Christian Brauner [Sun, 27 Nov 2016 00:43:37 +0000 (01:43 +0100)] 
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>
8 years agoMerge pull request #1326 from brauner/2016-11-26/improve_logging_for_monitord
Stéphane Graber [Sat, 26 Nov 2016 20:13:41 +0000 (15:13 -0500)] 
Merge pull request #1326 from brauner/2016-11-26/improve_logging_for_monitord

lxc_monitord: improve log + set log level to DEBUG

8 years agolxc_monitord: improve log + set log level to DEBUG 1326/head
Christian Brauner [Sat, 26 Nov 2016 18:39:44 +0000 (19:39 +0100)] 
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>
8 years agoMerge pull request #1325 from brauner/2016-11-26/improve_command_logging
Stéphane Graber [Sat, 26 Nov 2016 17:57:40 +0000 (12:57 -0500)] 
Merge pull request #1325 from brauner/2016-11-26/improve_command_logging

commands: improve logging

8 years agoMerge pull request #1324 from brauner/2016-11-26/more_logging_for_monitor
Stéphane Graber [Sat, 26 Nov 2016 17:57:16 +0000 (12:57 -0500)] 
Merge pull request #1324 from brauner/2016-11-26/more_logging_for_monitor

monitor: add more logging

8 years agoMerge pull request #1322 from brauner/2016-11-26/remove_werror_vla
Stéphane Graber [Sat, 26 Nov 2016 17:56:54 +0000 (12:56 -0500)] 
Merge pull request #1322 from brauner/2016-11-26/remove_werror_vla

configure: remove -Werror=vla

8 years agocommands: improve logging 1325/head
Christian Brauner [Sat, 26 Nov 2016 08:16:25 +0000 (09:16 +0100)] 
commands: improve logging

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agomonitor: add more logging 1324/head
Christian Brauner [Sat, 26 Nov 2016 06:40:59 +0000 (07:40 +0100)] 
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>
8 years agoMerge pull request #1323 from hallyn/2016-11-25/droplock
Christian Brauner [Sat, 26 Nov 2016 06:31:22 +0000 (01:31 -0500)] 
Merge pull request #1323 from hallyn/2016-11-25/droplock

lvm: supress warnings about leaked files

8 years agoconfigure: remove -Werror=vla 1322/head
Christian Brauner [Sat, 26 Nov 2016 06:07:25 +0000 (07:07 +0100)] 
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>
8 years agolvm: supress warnings about leaked files 1323/head
Serge Hallyn [Sat, 26 Nov 2016 06:07:15 +0000 (00:07 -0600)] 
lvm: supress warnings about leaked files

Closes #1283

Signed-off-by: Serge Hallyn <serge@hallyn.com>
8 years agoMerge pull request #1321 from brauner/2016-11-25/cleanup_monitor
Stéphane Graber [Sat, 26 Nov 2016 05:22:19 +0000 (00:22 -0500)] 
Merge pull request #1321 from brauner/2016-11-25/cleanup_monitor

cleanup monitor + improve log

8 years agoMerge pull request #1315 from brauner/2016-11-23/memfd_create
Stéphane Graber [Sat, 26 Nov 2016 04:50:28 +0000 (23:50 -0500)] 
Merge pull request #1315 from brauner/2016-11-23/memfd_create

conf, criu: add make_anonymous_mount_file()

8 years agomonitor: log which pipe fd is currently used 1321/head
Christian Brauner [Sat, 26 Nov 2016 04:28:58 +0000 (05:28 +0100)] 
monitor: log which pipe fd is currently used

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agomonitor: non-functional changes
Christian Brauner [Sat, 26 Nov 2016 04:03:55 +0000 (05:03 +0100)] 
monitor: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1320 from brauner/2016-11-25/remove_vlas
Stéphane Graber [Sat, 26 Nov 2016 04:04:21 +0000 (23:04 -0500)] 
Merge pull request #1320 from brauner/2016-11-25/remove_vlas

tree-wide: remove any variable length arrays

8 years agoconf, criu: add make_anonymous_mount_file() 1315/head
Christian Brauner [Wed, 23 Nov 2016 05:47:37 +0000 (06:47 +0100)] 
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>
8 years agoconfigure: check for memfd_create()
Christian Brauner [Fri, 25 Nov 2016 19:55:38 +0000 (20:55 +0100)] 
configure: check for memfd_create()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: non-functional changes
Christian Brauner [Wed, 23 Nov 2016 05:47:07 +0000 (06:47 +0100)] 
conf: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotree-wide: remove any variable length arrays 1320/head
Christian Brauner [Fri, 25 Nov 2016 21:01:20 +0000 (22:01 +0100)] 
tree-wide: remove any variable length arrays

They are pointless and marked optional since C11.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1319 from brauner/2016-11-25/fix_logging_race
Stéphane Graber [Fri, 25 Nov 2016 23:20:25 +0000 (18:20 -0500)] 
Merge pull request #1319 from brauner/2016-11-25/fix_logging_race

log: fix race

8 years agoconfigure: do not allow variable length arrays
Christian Brauner [Fri, 25 Nov 2016 21:00:45 +0000 (22:00 +0100)] 
configure: do not allow variable length arrays

There pointless and marked as optional since C11.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolog: use N/A if getpid() != gettid() when threaded 1319/head
Christian Brauner [Fri, 25 Nov 2016 19:23:00 +0000 (20:23 +0100)] 
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>
8 years agolog: fix race
Christian Brauner [Fri, 25 Nov 2016 16:28:18 +0000 (17:28 +0100)] 
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>
8 years agoconfigure: check whether gettid() is declared
Christian Brauner [Fri, 25 Nov 2016 19:02:24 +0000 (20:02 +0100)] 
configure: check whether gettid() is declared

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoMerge pull request #1317 from brauner/2016-11-24/cleanup_attach
Stéphane Graber [Fri, 25 Nov 2016 17:46:03 +0000 (12:46 -0500)] 
Merge pull request #1317 from brauner/2016-11-24/cleanup_attach

cleanup attach

8 years agoMerge pull request #1318 from brauner/2016-11-25/fix_logging_race
Stéphane Graber [Fri, 25 Nov 2016 02:22:04 +0000 (21:22 -0500)] 
Merge pull request #1318 from brauner/2016-11-25/fix_logging_race

log: use thread-safe localtime_r()

8 years agolog: use thread-safe localtime_r() 1318/head
Christian Brauner [Fri, 25 Nov 2016 01:42:51 +0000 (02:42 +0100)] 
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>
8 years agoattach: non-functional changes 1317/head
Christian Brauner [Thu, 24 Nov 2016 07:16:59 +0000 (08:16 +0100)] 
attach: non-functional changes

- improve logging
- simplify functions

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoattach: simplify lsm_openat()
Christian Brauner [Thu, 24 Nov 2016 06:58:01 +0000 (07:58 +0100)] 
attach: simplify lsm_openat()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoattach: do not send procfd to attached process
Christian Brauner [Tue, 8 Nov 2016 18:21:19 +0000 (19:21 +0100)] 
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>
8 years agoMerge pull request #1314 from ccope/static-mac
Christian Brauner [Wed, 23 Nov 2016 04:04:45 +0000 (23:04 -0500)] 
Merge pull request #1314 from ccope/static-mac

Configure a static MAC address on the LXC bridge

8 years agoConfigure a static MAC address on the LXC bridge 1314/head
Cam Cope [Tue, 22 Nov 2016 23:16:32 +0000 (15:16 -0800)] 
Configure a static MAC address on the LXC bridge

Signed-off-by: Cam Cope <cam@dropbox.com>
8 years agoMerge pull request #1312 from brauner/2016-11-22/fix_lxc_unshare_parsing
Stéphane Graber [Tue, 22 Nov 2016 17:12:21 +0000 (12:12 -0500)] 
Merge pull request #1312 from brauner/2016-11-22/fix_lxc_unshare_parsing

tools: replace non-standard namespace identifiers

8 years agoMerge pull request #1313 from brauner/2016-11-22/fix_lxc_tests
Stéphane Graber [Tue, 22 Nov 2016 17:10:41 +0000 (12:10 -0500)] 
Merge pull request #1313 from brauner/2016-11-22/fix_lxc_tests

tests: remove overflow tests

8 years agotests: remove overflow tests 1313/head
Christian Brauner [Tue, 22 Nov 2016 16:38:18 +0000 (17:38 +0100)] 
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>
8 years agotools: replace non-standard namespace identifiers 1312/head
Christian Brauner [Tue, 22 Nov 2016 08:42:59 +0000 (09:42 +0100)] 
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>
8 years agoMerge pull request #1256 from brauner/2016-09-06/remove_atoi
Serge Hallyn [Tue, 22 Nov 2016 04:46:21 +0000 (22:46 -0600)] 
Merge pull request #1256 from brauner/2016-09-06/remove_atoi

remove atoi

8 years agoconfile: non-functional change 1256/head
Christian Brauner [Tue, 22 Nov 2016 03:44:14 +0000 (04:44 +0100)] 
confile: non-functional change

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_console: use lxc_safe_uint()
Christian Brauner [Sat, 29 Oct 2016 11:29:26 +0000 (13:29 +0200)] 
tools/lxc_console: use lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_autostart: use lxc_safe_{int,long}()
Christian Brauner [Sat, 29 Oct 2016 11:23:47 +0000 (13:23 +0200)] 
tools/lxc_autostart: use lxc_safe_{int,long}()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_ls: use lxc_safe_uint()
Christian Brauner [Sat, 29 Oct 2016 11:13:21 +0000 (13:13 +0200)] 
tools/lxc_ls: use lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_top: use lxc_safe_int()
Christian Brauner [Sat, 29 Oct 2016 11:11:14 +0000 (13:11 +0200)] 
tools/lxc_top: use lxc_safe_int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_stop: use lxc_safe_long()
Christian Brauner [Sat, 29 Oct 2016 10:40:15 +0000 (12:40 +0200)] 
tools/lxc_stop: use lxc_safe_long()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotests: add unit tests for lxc_safe_long()
Christian Brauner [Sat, 29 Oct 2016 10:39:54 +0000 (12:39 +0200)] 
tests: add unit tests for lxc_safe_long()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoutils: add lxc_safe_long()
Christian Brauner [Sat, 29 Oct 2016 10:39:36 +0000 (12:39 +0200)] 
utils: add lxc_safe_long()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_stop: use lxc_safe_uint()
Christian Brauner [Sat, 29 Oct 2016 10:23:39 +0000 (12:23 +0200)] 
tools/lxc_stop: use lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotools/lxc_execute: use lxc_safe_uint()
Christian Brauner [Sat, 29 Oct 2016 10:22:17 +0000 (12:22 +0200)] 
tools/lxc_execute: use lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf: use lxc_safe_{u}int()
Christian Brauner [Sat, 29 Oct 2016 10:20:14 +0000 (12:20 +0200)] 
conf: use lxc_safe_{u}int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agostart: use lxc_safe_int()
Christian Brauner [Sat, 29 Oct 2016 10:08:00 +0000 (12:08 +0200)] 
start: use lxc_safe_int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agolxc_monitord: use lxc_safe_int() && use exit()
Christian Brauner [Sat, 29 Oct 2016 10:03:49 +0000 (12:03 +0200)] 
lxc_monitord: use lxc_safe_int() && use exit()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoutils: use lxc_safe_int()
Christian Brauner [Sat, 29 Oct 2016 10:00:06 +0000 (12:00 +0200)] 
utils: use lxc_safe_int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: avoid atoi() in config_no_new_privs()
Christian Brauner [Fri, 28 Oct 2016 18:26:51 +0000 (20:26 +0200)] 
conf/ile: avoid atoi() in config_no_new_privs()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: avoid atoi() in config_ephemeral()
Christian Brauner [Fri, 28 Oct 2016 18:24:17 +0000 (20:24 +0200)] 
conf/ile: avoid atoi() in config_ephemeral()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_uint() in config_autodev()
Christian Brauner [Fri, 28 Oct 2016 18:22:35 +0000 (20:22 +0200)] 
conf/ile: use lxc_safe_uint() in config_autodev()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: avoid atoi in config_lsm_aa_incomplete()
Christian Brauner [Fri, 28 Oct 2016 18:10:25 +0000 (20:10 +0200)] 
conf/ile: avoid atoi in config_lsm_aa_incomplete()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_uint() in config_kmsg()
Christian Brauner [Fri, 28 Oct 2016 18:08:12 +0000 (20:08 +0200)] 
conf/ile: use lxc_safe_uint() in config_kmsg()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_uint() in config_tty()
Christian Brauner [Fri, 28 Oct 2016 18:06:40 +0000 (20:06 +0200)] 
conf/ile: use lxc_safe_uint() in config_tty()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_uint() in config_monitor()
Christian Brauner [Fri, 28 Oct 2016 18:05:07 +0000 (20:05 +0200)] 
conf/ile: use lxc_safe_uint() in config_monitor()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_u/int() in config_start()
Christian Brauner [Fri, 28 Oct 2016 18:01:21 +0000 (20:01 +0200)] 
conf/ile: use lxc_safe_u/int() in config_start()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: use lxc_safe_uint() in config_pts()
Christian Brauner [Fri, 28 Oct 2016 17:58:10 +0000 (19:58 +0200)] 
conf/ile: use lxc_safe_uint() in config_pts()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconfile: use lxc_safe_u/int in config_init_{u,g}id
Christian Brauner [Fri, 28 Oct 2016 17:53:19 +0000 (19:53 +0200)] 
confile: use lxc_safe_u/int in config_init_{u,g}id

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf/ile: get ip prefix via lxc_safe_uint()
Christian Brauner [Fri, 28 Oct 2016 17:41:42 +0000 (19:41 +0200)] 
conf/ile: get ip prefix via lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotests: add unit tests for lxc_safe_int()
Christian Brauner [Wed, 7 Sep 2016 15:51:33 +0000 (17:51 +0200)] 
tests: add unit tests for lxc_safe_int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoutils: add lxc_safe_int()
Christian Brauner [Wed, 7 Sep 2016 15:47:50 +0000 (17:47 +0200)] 
utils: add lxc_safe_int()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agotests: add unit tests for lxc_safe_uint()
Christian Brauner [Tue, 6 Sep 2016 15:41:34 +0000 (17:41 +0200)] 
tests: add unit tests for lxc_safe_uint()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoutils: add lxc_safe_uint()
Christian Brauner [Tue, 6 Sep 2016 15:32:47 +0000 (17:32 +0200)] 
utils: add lxc_safe_uint()

This function safely parses an unsigned integer. On success it returns 0 and
stores the unsigned integer in @converted. On error it returns a negative
errno.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoMerge pull request #1309 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling
Serge Hallyn [Mon, 21 Nov 2016 23:57:05 +0000 (17:57 -0600)] 
Merge pull request #1309 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling

cgroup: improve isolcpus handling

8 years agocgroups: handle non-existent isolcpus file 1309/head
Christian Brauner [Mon, 21 Nov 2016 21:31:39 +0000 (22:31 +0100)] 
cgroups: handle non-existent isolcpus file

If the file "/sys/devices/system/cpu/isolated" doesn't exist, we can't just
simply bail. We still need to check whether we need to copy the parents cpu
settings.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agocgroup: improve isolcpus handling
Christian Brauner [Mon, 21 Nov 2016 17:11:32 +0000 (18:11 +0100)] 
cgroup: improve isolcpus handling

- add more logging
- only write to cpuset.cpus if we really have to
- simplify cleanup on error and success

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoMerge pull request #1308 from brauner/2016-11-20/use_ns_info_struct
Stéphane Graber [Sun, 20 Nov 2016 06:11:24 +0000 (01:11 -0500)] 
Merge pull request #1308 from brauner/2016-11-20/use_ns_info_struct

use ns info struct and always attach to user namespace first

8 years agonamespace: always attach to user namespace first 1308/head
Christian Brauner [Sun, 20 Nov 2016 05:20:07 +0000 (06:20 +0100)] 
namespace: always attach to user namespace first

Move the user namespace at the first position in the array so that we always
attach to it first when iterating over the struct and using setns() to switch
namespaces. This especially affects lxc_attach(): Suppose you cloned a new user
namespace and mount namespace as an unprivileged user on the host and want to
setns() to the mount namespace. This requires you to attach to the user
namespace first otherwise the kernel will fail this check:

    if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) ||
        !ns_capable(current_user_ns(), CAP_SYS_CHROOT) ||
        !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
     return -EPERM;

in

    linux/fs/namespace.c:mntns_install().

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoattach: use ns_info[LXC_NS_MAX] struct
Christian Brauner [Sun, 20 Nov 2016 05:17:53 +0000 (06:17 +0100)] 
attach: use ns_info[LXC_NS_MAX] struct

Using custom structs in attach.c risks getting out of sync with the commonly
used ns_info[LXC_NS_MAX] struct and thus attaching to wrong namespaces. Switch
to using ns_info[LXC_NS_MAX].

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoMerge pull request #1255 from brauner/2016-10-27/cleanup_netdevs_lxd#2439_lxc#1253
Serge Hallyn [Sat, 19 Nov 2016 18:17:11 +0000 (12:17 -0600)] 
Merge pull request #1255 from brauner/2016-10-27/cleanup_netdevs_lxd#2439_lxc#1253

remove veth device from host

8 years agoattach, utils: bugfixes 1255/head
Christian Brauner [Sat, 19 Nov 2016 04:45:01 +0000 (05:45 +0100)] 
attach, utils: bugfixes

- simply check /proc/self/ns
- improve SYSERROR() report
- use #define to prevent gcc & clang to use a VLA

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agostart, namespace: move ns_info to namespace.{c,h}
Christian Brauner [Mon, 31 Oct 2016 14:54:42 +0000 (15:54 +0100)] 
start, namespace: move ns_info to namespace.{c,h}

It's much more appropriate there and makes start.{c,h} cleaner and leaner.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agostart, error: improve log + non-functional changes
Christian Brauner [Sat, 29 Oct 2016 15:27:49 +0000 (17:27 +0200)] 
start, error: improve log + non-functional changes

Improve log and comments in a bunch of places to make it easier for us on bug
reports.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agostart, utils: improve preserve_ns()
Christian Brauner [Sat, 29 Oct 2016 14:58:48 +0000 (16:58 +0200)] 
start, utils: improve preserve_ns()

- Allocating an error message that the caller must free seems pointless. We can
  just print the error message in preserve_ns() itself. This also allows us to
  avoid using the GNU extension asprintf().
- Improve lxc_preserve_ns(): By passing in NULL or "" as the second argument
  the function can now also be used to check whether namespaces are supported
  by the kernel.
- Use lxc_preserve_ns() in preserve_ns().

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf, start: be smarter when deleting networks
Christian Brauner [Fri, 28 Oct 2016 11:40:44 +0000 (13:40 +0200)] 
conf, start: be smarter when deleting networks

- So far we blindly called lxc_delete_network() to make sure that we deleted
  all network interfaces. This resulted in pointless netlink calls, especially
  when a container had multiple networks defined. Let's be smarter and have
  lxc_delete_network() return a boolean that indicates whether *all* configured
  networks have been deleted. If so, don't needlessly try to delete them again
  in start.c. This also decreases confusing error messages a user might see.

- When we receive -ENODEV from one of our lxc_netdev_delete_*() functions,
  let's assume that either the network device already got deleted or that it
  got moved to a different network namespace. Inform the user about this but do
  not report an error in this case.

- When we have explicitly deleted the host side of a veth pair let's
  immediately free(priv.veth_attr.pair) and NULL it, or
  memset(priv.veth_attr.pair, ...) the corresponding member so we don't
  needlessly try to destroy them again when we have to call
  lxc_delete_network() again in start.c

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf: explicitly remove veth device from host
Christian Brauner [Thu, 27 Oct 2016 12:41:49 +0000 (14:41 +0200)] 
conf: explicitly remove veth device from host

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf, start: improve log output
Christian Brauner [Thu, 27 Oct 2016 19:09:27 +0000 (21:09 +0200)] 
conf, start: improve log output

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agolxc_user_nic: use lxc_preserve_ns()
Christian Brauner [Fri, 28 Oct 2016 08:48:20 +0000 (10:48 +0200)] 
lxc_user_nic: use lxc_preserve_ns()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoattach: use lxc_preserve_ns()
Christian Brauner [Fri, 28 Oct 2016 10:33:30 +0000 (12:33 +0200)] 
attach: use lxc_preserve_ns()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoconf: use lxc_preserve_ns()
Christian Brauner [Thu, 27 Oct 2016 12:39:45 +0000 (14:39 +0200)] 
conf: use lxc_preserve_ns()

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agostart: add netnsfd to lxc_handler
Christian Brauner [Thu, 27 Oct 2016 12:35:26 +0000 (14:35 +0200)] 
start: add netnsfd to lxc_handler

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoutils: add lxc_preserve_ns()
Christian Brauner [Thu, 27 Oct 2016 12:37:24 +0000 (14:37 +0200)] 
utils: add lxc_preserve_ns()

This allows to retrieve a file descriptor referring to a namespace.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
8 years agoMerge pull request #1305 from brauner/2016-11-16/cgfsng_debug
Stéphane Graber [Thu, 17 Nov 2016 16:48:06 +0000 (09:48 -0700)] 
Merge pull request #1305 from brauner/2016-11-16/cgfsng_debug

cgroups: prevent segfault in cgfsng

8 years agocgroups: prevent segfault in cgfsng 1305/head
Christian Brauner [Wed, 16 Nov 2016 15:43:20 +0000 (16:43 +0100)] 
cgroups: prevent segfault in cgfsng

When we set LXC_DEBUG_CGFSNG=1 we print out info about detected cgroup
hierarchies. When there's no named cgroup mounted we need to make sure that we
don't try to index an unallocated pointer.

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>