Commit Graph

5245 Commits

Author SHA1 Message Date
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
Christian Brauner
8c57d93034
utils: add lxc_safe_long()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:11 +01:00
Christian Brauner
0406409813
tools/lxc_stop: use lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:10 +01:00
Christian Brauner
fb111ba0ad
tools/lxc_execute: use lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:08 +01:00
Christian Brauner
b7b2fde48f
conf: use lxc_safe_{u}int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:06 +01:00
Christian Brauner
d4cff0d21a
start: use lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:04 +01:00
Christian Brauner
7e5af997d3
lxc_monitord: use lxc_safe_int() && use exit()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:02 +01:00
Christian Brauner
2d036ccac0
utils: use lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:46:00 +01:00
Christian Brauner
e8ec7c9efc
conf/ile: avoid atoi() in config_no_new_privs()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:45:58 +01:00
Christian Brauner
66ffdb1a20
conf/ile: avoid atoi() in config_ephemeral()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:43:02 +01:00
Christian Brauner
ff6cb4ed82
conf/ile: use lxc_safe_uint() in config_autodev()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:41:37 +01:00
Christian Brauner
a56e2df9cf
conf/ile: avoid atoi in config_lsm_aa_incomplete()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 04:39:25 +01:00
Christian Brauner
91863d360b
conf/ile: use lxc_safe_uint() in config_kmsg()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:22 +01:00
Christian Brauner
1c30b4adbd
conf/ile: use lxc_safe_uint() in config_tty()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:19 +01:00
Christian Brauner
226dc30e4f
conf/ile: use lxc_safe_uint() in config_monitor()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:17 +01:00
Christian Brauner
3590152f01
conf/ile: use lxc_safe_u/int() in config_start()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:15 +01:00
Christian Brauner
1791996979
conf/ile: use lxc_safe_uint() in config_pts()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:13 +01:00
Christian Brauner
d1e5d63673
confile: use lxc_safe_u/int in config_init_{u,g}id
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:11 +01:00
Christian Brauner
1c6333988f
conf/ile: get ip prefix via lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:09 +01:00
Christian Brauner
aa75cefcef
tests: add unit tests for lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:07 +01:00
Christian Brauner
b5f845e7e0
utils: add lxc_safe_int()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:05 +01:00
Christian Brauner
57c7adc3c8
tests: add unit tests for lxc_safe_uint()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-22 03:41:03 +01:00
Christian Brauner
6bc2eafe90
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>
2016-11-22 03:40:59 +01:00
Serge Hallyn
995ea94114 Merge pull request #1309 from brauner/2016-11-21/cgfsng_improve_isolcpus_handling
cgroup: improve isolcpus handling
2016-11-21 17:57:05 -06:00
Christian Brauner
65d29cbc57
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>
2016-11-21 22:31:39 +01:00
Christian Brauner
6f9584d885
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>
2016-11-21 21:39:47 +01:00
Stéphane Graber
b8ca2bc7c9 Merge pull request #1308 from brauner/2016-11-20/use_ns_info_struct
use ns info struct and always attach to user namespace first
2016-11-20 01:11:24 -05:00
Christian Brauner
29ed9c13ac
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>
2016-11-20 06:26:03 +01:00
Christian Brauner
2681861894
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>
2016-11-20 06:17:53 +01:00
Serge Hallyn
88a66d0112 Merge pull request #1255 from brauner/2016-10-27/cleanup_netdevs_lxd#2439_lxc#1253
remove veth device from host
2016-11-19 12:17:11 -06:00
Christian Brauner
a052913dd0
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>
2016-11-19 05:45:01 +01:00
Christian Brauner
9662e444d9
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>
2016-11-19 05:11:41 +01:00
Christian Brauner
408da065fb
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>
2016-11-19 05:11:39 +01:00
Christian Brauner
4d8ac866fc
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>
2016-11-19 05:11:36 +01:00
Christian Brauner
358daf49c0
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>
2016-11-19 05:11:34 +01:00
Christian Brauner
e97946ae96
conf: explicitly remove veth device from host
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:32 +01:00
Christian Brauner
198cbbaa1d
conf, start: improve log output
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:30 +01:00
Christian Brauner
5d04811edf
lxc_user_nic: use lxc_preserve_ns()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:28 +01:00
Christian Brauner
383613cc36
attach: use lxc_preserve_ns()
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
2016-11-19 05:11:25 +01:00