]> git.ipfire.org Git - thirdparty/lxc.git/log
thirdparty/lxc.git
5 years agocgroups: unify cgfsng_{un}freeze()
Christian Brauner [Mon, 2 Sep 2019 21:51:19 +0000 (23:51 +0200)] 
cgroups: unify cgfsng_{un}freeze()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years agocgroups: initialize cgroup root directory - encore
Christian Brauner [Thu, 29 Aug 2019 12:05:17 +0000 (14:05 +0200)] 
cgroups: initialize cgroup root directory - encore

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years agocgroups: check for empty cgroups on freeze/unfreeze
Christian Brauner [Thu, 29 Aug 2019 11:56:56 +0000 (13:56 +0200)] 
cgroups: check for empty cgroups on freeze/unfreeze

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years agocgroups: initialize cgroup root directory
Christian Brauner [Wed, 28 Aug 2019 18:33:39 +0000 (20:33 +0200)] 
cgroups: initialize cgroup root directory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years ago[aa-profile] Deny access to /proc/acpi/**
Pierre-Elliott Bécue [Sat, 10 Aug 2019 20:07:42 +0000 (22:07 +0200)] 
[aa-profile] Deny access to /proc/acpi/**

Signed-off-by: Pierre-Elliott Bécue <becue@crans.org>
5 years agolxc-attach: make sure exit status of command is returned
Antonio Terceiro [Sun, 18 Aug 2019 20:30:32 +0000 (17:30 -0300)] 
lxc-attach: make sure exit status of command is returned

Commit ae68cad763d5b39a6a9e51de2acd1ad128b720ca introduced a regression that
makes lxc-attach ignore the exit status of the executed command. This was first
identified in 3.0.4 LTS, while it worked on 3.0.3.

  # lxc-attach --version
  3.0.4
  # lxc-attach -n test false; echo $?
  0

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=934983

5 years agocgfsng: mount pure unified cgroup layout correctly
Christian Brauner [Mon, 26 Aug 2019 14:16:16 +0000 (16:16 +0200)] 
cgfsng: mount pure unified cgroup layout correctly

When pure cgroup unified mode is used we cannot pre-mount a tmpfs as this
confuses systemd.
Users should also set lxc.mount.auto = cgroup:force to ensure that systemd in
the container and on the host use identical cgroup layouts.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years agolxc-create: check absoule path for param '--dir'
qianfan Zhao [Mon, 19 Aug 2019 01:54:34 +0000 (09:54 +0800)] 
lxc-create: check absoule path for param '--dir'

Fix: #3123

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
5 years agocgroups: support cgroup2 freezer
Christian Brauner [Thu, 15 Aug 2019 17:50:39 +0000 (19:50 +0200)] 
cgroups: support cgroup2 freezer

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
5 years agoattach: don't close stdout of getent
Wolfgang Bumiller [Tue, 13 Aug 2019 12:17:30 +0000 (14:17 +0200)] 
attach: don't close stdout of getent

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
5 years agotry to fix search user instead of search substring
Alexander Kriventsov [Mon, 29 Jul 2019 16:33:39 +0000 (19:33 +0300)] 
try to fix search user instead of search substring

Signed-off-by: Alexander Kriventsov <akriventsov@nic.ru>
5 years agolxccontainer: do_lxcapi_detach_interface to support detaching wlan devices
Thomas Parrott [Fri, 26 Jul 2019 15:14:18 +0000 (16:14 +0100)] 
lxccontainer: do_lxcapi_detach_interface to support detaching wlan devices

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
5 years agosuppress false-negative error in templates and nvidia hook
Lukas Pirl [Mon, 22 Jul 2019 12:29:52 +0000 (14:29 +0200)] 
suppress false-negative error in templates and nvidia hook

``/proc`` might be mounted with ``hidepid=2``.
This makes ``/proc/1/…`` appear absent for non-root users.
When using the templates or the nvidia hook as a non-root user
(e.g., when creating unprivileged containers) the error
"/proc/1/uid_map: No such file or directory" is printed.
Since the script works correctly despite the error, this error
message might be confusing for users.

Signed-off-by: Lukas Pirl <git@lukas-pirl.de>
5 years agoContainer's specific file/directory names
Rachid Koucha [Fri, 21 Jun 2019 12:20:04 +0000 (14:20 +0200)] 
Container's specific file/directory names

To be used when making file/directory names for containers (e.g. in lxccontainer.c)

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
5 years agoUse file/directory names from macro.h
Rachid Koucha [Thu, 20 Jun 2019 16:24:21 +0000 (18:24 +0200)] 
Use file/directory names from macro.h

To make the file/directory names, use the defines from macro.h

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agolxc.pc: Fix invalid @DLOG_LIBS@
Stéphane Graber [Tue, 8 Oct 2019 01:27:14 +0000 (21:27 -0400)] 
lxc.pc: Fix invalid @DLOG_LIBS@

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
6 years agoutils: Fix wrong integer of a function parameter.
Julio Faracco [Sat, 3 Aug 2019 05:16:13 +0000 (02:16 -0300)] 
utils: Fix wrong integer of a function parameter.

If SSL is enabled, utils will include function `do_sha1_hash()` to
generate a sha1 encrypted buffer. Last function argument of
`EVP_DigestFinal_ex()` requires a `unsigned int` but the current
parameter is an `integer` type.

See error:
utils.c:350:38: error: passing 'int *' to parameter of type 'unsigned int *' converts between pointers to integer types with different sign
      [-Werror,-Wpointer-sign]
        EVP_DigestFinal_ex(mdctx, md_value, md_len);
                                            ^~~~~~
/usr/include/openssl/evp.h:549:49: note: passing argument to parameter 's' here
                                  unsigned int *s);

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
6 years agolxccontainer: do_lxcapi_detach_interface to support detaching wlan devices
Thomas Parrott [Fri, 26 Jul 2019 15:14:18 +0000 (16:14 +0100)] 
lxccontainer: do_lxcapi_detach_interface to support detaching wlan devices

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agocgroups: initialize cpuset properly
Christian Brauner [Sun, 28 Jul 2019 21:13:26 +0000 (23:13 +0200)] 
cgroups: initialize cpuset properly

Closes #3108.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agopidfds: don't print a scary warning on ENOSYS
Tycho Andersen [Tue, 23 Jul 2019 15:40:14 +0000 (09:40 -0600)] 
pidfds: don't print a scary warning on ENOSYS

Most kernels don't have this functionality yet, and so the warning is
printed a lot. Our people are scared of warnings, so let's make it INFO
instead in this case.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agolxc-download: Pre-release bump of compat
Stéphane Graber [Mon, 22 Jul 2019 22:23:48 +0000 (18:23 -0400)] 
lxc-download: Pre-release bump of compat

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
6 years agolxc/log: Adds error_log_errno macro
Thomas Parrott [Tue, 21 May 2019 16:25:52 +0000 (17:25 +0100)] 
lxc/log: Adds error_log_errno macro

Suggested usage:

return error_log_errno(err, "Failed: %s", "some error");

It sets errno to the value of err, then calls SYSERROR with the format and remaining args.

It always returns -1.

Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agoSuppress hardcoded table sizes
Rachid Koucha [Thu, 11 Jul 2019 08:01:36 +0000 (10:01 +0200)] 
Suppress hardcoded table sizes

. Use sizeof() instead of hardcoded values
. snprintf(..., size, ""...) is in error if the return code is >= size (not sufficient to set only ">")

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agoTypo fix
Rachid Koucha [Thu, 11 Jul 2019 07:42:05 +0000 (09:42 +0200)] 
Typo fix

Fixed a typo in error message

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agocgroup: check for non-empty conf
Christian Brauner [Wed, 10 Jul 2019 14:34:29 +0000 (16:34 +0200)] 
cgroup: check for non-empty conf

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agopidf_send_signal: fix return value
Wolfgang Bumiller [Mon, 8 Jul 2019 16:10:35 +0000 (18:10 +0200)] 
pidf_send_signal: fix return value

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
6 years agocgroups: hande cpuset initialization race
Christian Brauner [Wed, 3 Jul 2019 15:57:48 +0000 (17:57 +0200)] 
cgroups: hande cpuset initialization race

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: expose LXC_PID to network hooks too
Christian Brauner [Tue, 2 Jul 2019 10:57:12 +0000 (12:57 +0200)] 
start: expose LXC_PID to network hooks too

Closes #3066.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMove code/variable in smaller scope
Rachid Koucha [Sat, 29 Jun 2019 21:21:14 +0000 (23:21 +0200)] 
Move code/variable in smaller scope

In start.c, do not fill path[] table if not necessary

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agofix memory leak in do_storage_create
LiFeng [Fri, 28 Jun 2019 03:49:08 +0000 (23:49 -0400)] 
fix memory leak in do_storage_create

Signed-off-by: LiFeng <lifeng68@huawei.com>
6 years agocgroups: move variable into tighter scope
Christian Brauner [Thu, 27 Jun 2019 12:48:34 +0000 (14:48 +0200)] 
cgroups: move variable into tighter scope

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: correctly order variables
Christian Brauner [Thu, 27 Jun 2019 12:46:47 +0000 (14:46 +0200)] 
cgroups: correctly order variables

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: move variable into tighter scope
Christian Brauner [Thu, 27 Jun 2019 12:45:36 +0000 (14:45 +0200)] 
cgroups: move variable into tighter scope

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: simplify cgfsng_nrtasks()
Christian Brauner [Thu, 27 Jun 2019 12:43:36 +0000 (14:43 +0200)] 
cgroups: simplify cgfsng_nrtasks()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: move variable into tighter scope
Christian Brauner [Thu, 27 Jun 2019 12:43:09 +0000 (14:43 +0200)] 
cgroups: move variable into tighter scope

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: move variable into tighter scope
Christian Brauner [Thu, 27 Jun 2019 12:27:58 +0000 (14:27 +0200)] 
cgroups: move variable into tighter scope

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: use __do_free in cgfsng_attach()
Christian Brauner [Thu, 27 Jun 2019 12:27:39 +0000 (14:27 +0200)] 
cgroups: use __do_free in cgfsng_attach()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: simplify cgfsng_setup_limits()
Christian Brauner [Thu, 27 Jun 2019 12:26:38 +0000 (14:26 +0200)] 
cgroups: simplify cgfsng_setup_limits()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: move variables into tighter scope
Christian Brauner [Thu, 27 Jun 2019 12:26:14 +0000 (14:26 +0200)] 
cgroups: move variables into tighter scope

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups: use __do_free
Christian Brauner [Thu, 27 Jun 2019 12:25:53 +0000 (14:25 +0200)] 
cgroups: use __do_free

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgfsng: fix memory leak in lxc_cpumask_to_cpulist
LiFeng [Thu, 27 Jun 2019 03:54:27 +0000 (23:54 -0400)] 
cgfsng: fix memory leak in lxc_cpumask_to_cpulist

Signed-off-by: LiFeng <lifeng68@huawei.com>
6 years agoRelease LXC 3.0.4 lxc-3.0.4
Stéphane Graber [Fri, 21 Jun 2019 22:02:24 +0000 (18:02 -0400)] 
Release LXC 3.0.4

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
6 years agocgfsng: write cpuset.mems of correct ancestor
Christian Brauner [Thu, 20 Jun 2019 17:37:09 +0000 (19:37 +0200)] 
cgfsng: write cpuset.mems of correct ancestor

Reported-by: Free Ekanayaka <free.ekanayaka@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoparse.c: fix fd leak from memfd_create
t00416110 [Thu, 20 Jun 2019 20:26:59 +0000 (16:26 -0400)] 
parse.c: fix fd leak from memfd_create

Signed-off-by: t00416110 <tanyifeng1@huawei.com>
6 years agolxc.pc.in: add libs.private for static linking
Serge Hallyn [Mon, 17 Jun 2019 13:37:47 +0000 (08:37 -0500)] 
lxc.pc.in: add libs.private for static linking

None of them seem to support pkg-config themselves, else we could add
them to Requires.private.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
6 years agoFixed file descriptor leak for network namespace
Rachid Koucha [Sat, 15 Jun 2019 13:17:50 +0000 (15:17 +0200)] 
Fixed file descriptor leak for network namespace

In privileged mode, the container startup looses a file descriptor for "handler->nsfd[LX_NS_NET]". At line 1782, we preserve the namespaces file descriptor (in privileged mode, the network namespace is also preserved) :
for (i = 0; i < LXC_NS_MAX; i++)
if (handler->ns_on_clone_flags & ns_info[i].clone_flag)
INFO("Cloned %s", ns_info[i].flag_name);

if (!lxc_try_preserve_namespaces(handler, handler->ns_on_clone_flags, handler->pid)) {
ERROR("Failed to preserve cloned namespaces for lxc.hook.stop");
goto out_delete_net;
}

Then at line 1830, we preserve one more time the network namespace :
ret = lxc_try_preserve_ns(handler->pid, "net");
if (ret < 0) {
if (ret != -EOPNOTSUPP) {
SYSERROR("Failed to preserve net namespace");
goto out_delete_net;
}
The latter overwrites the file descriptor already stored in handler->nsfd[LXC_NS_NET] at line 1786.

So, this fix checks that the entry is not already filled.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agonetwork: fix lxc_netdev_rename_by_index()
Christian Brauner [Fri, 14 Jun 2019 10:39:20 +0000 (12:39 +0200)] 
network: fix lxc_netdev_rename_by_index()

Return an error code when the name is invalid instead of pretending that things
are fine.

Closes #3044.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoSwitch from gnutls to openssl for sha1
Serge Hallyn [Fri, 14 Jun 2019 03:08:26 +0000 (03:08 +0000)] 
Switch from gnutls to openssl for sha1

The reason for this is because openssl can be statically linked
against, gnutls cannot.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
6 years agodoc: add a note about shared ns + LSMs to Japanese doc
KATOH Yasufumi [Thu, 13 Jun 2019 12:05:24 +0000 (21:05 +0900)] 
doc: add a note about shared ns + LSMs to Japanese doc

Update for commit 8de90384363fe01f5258d36724dd3eae55918b5b

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
6 years agoCentralize hook names
Rachid Koucha [Wed, 12 Jun 2019 06:36:40 +0000 (08:36 +0200)] 
Centralize hook names

The hook string names must not be repeated in the source code to facilitate future changes

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agostart: generate new boot id on container start
Christian Brauner [Wed, 5 Jun 2019 21:43:53 +0000 (23:43 +0200)] 
start: generate new boot id on container start

Closes #3027.

BugLink: https://bugs.launchpad.net/bugs/1831258
Cc: Dimitri John Ledkov <xnox@ubuntu.com>
Cc: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoproposed fix for #2892 - fix lxcbasename in lxc/lxccontainer.c
Paul Romlow [Wed, 5 Jun 2019 18:28:21 +0000 (13:28 -0500)] 
proposed fix for #2892 - fix lxcbasename in lxc/lxccontainer.c

Signed-off-by: Paul Romlow <paul@romlow.com>
6 years agoMake /tmp accessible to any user
Rachid Koucha [Wed, 5 Jun 2019 11:04:11 +0000 (13:04 +0200)] 
Make /tmp accessible to any user

/tmp created with "rwxrwxrwt" mode

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agocgroups: prevent segfault
Christian Brauner [Wed, 5 Jun 2019 07:27:45 +0000 (09:27 +0200)] 
cgroups: prevent segfault

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: fix handler memory leak at lxc_init failed
LiFeng [Wed, 5 Jun 2019 04:44:17 +0000 (00:44 -0400)] 
start: fix handler memory leak at lxc_init failed

Signed-off-by: LiFeng <lifeng68@huawei.com>
6 years agolxc_usernsexec: continuing after unshare fails leads to confusing and misleading...
Brian McQueen [Tue, 4 Jun 2019 13:46:37 +0000 (06:46 -0700)] 
lxc_usernsexec: continuing after unshare fails leads to confusing and misleading error messages

Signed-off-by: Brian McQueen <bmcqueen@linkedin.com>
6 years agogetgrgid_r fails with ERANGE if buffer is too small. Retry with a larger buffer.
Alexander Kriventsov [Mon, 3 Jun 2019 15:11:56 +0000 (18:11 +0300)] 
getgrgid_r fails with ERANGE if buffer is too small. Retry with a larger buffer.

Signed-off-by: Alexander Kriventsov <akriventsov@nic.ru>
6 years agolxc_clone: add a comment about stack size
Tycho Andersen [Wed, 29 May 2019 15:36:51 +0000 (09:36 -0600)] 
lxc_clone: add a comment about stack size

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agolxc_clone: bump stack size to 8MB
Tycho Andersen [Wed, 29 May 2019 14:47:35 +0000 (08:47 -0600)] 
lxc_clone: bump stack size to 8MB

This is the default thread size for glibc, so it is reasonable to match
that when we clone().

Mostly this is a science experiment suggested by brauner, and who doesn't
love science?

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agofix issue 2765
Alexander Kriventsov [Tue, 28 May 2019 12:58:51 +0000 (15:58 +0300)] 
fix issue 2765

Signed-off-by: Alexander Kriventsov <akriventsov@nic.ru>
6 years agocgroups: handle offline cpus in v1 hierarchy
Christian Brauner [Fri, 24 May 2019 13:59:57 +0000 (15:59 +0200)] 
cgroups: handle offline cpus in v1 hierarchy

Handle offline cpus in v1 hierarchy.

In addition to isolated cpus we also need to account for offline cpus when our
ancestor cgroup is the root cgroup and we have not been initialized yet.

Closes #2953.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxc_clone: get rid of some indirection
Tycho Andersen [Thu, 9 May 2019 18:18:10 +0000 (14:18 -0400)] 
lxc_clone: get rid of some indirection

We have a do_clone(), which just calls a void f(void *) that it gets
passed. We build up a struct consisting of two args that are just the
actual arg and actual function. Let's just have the syscall do this for us.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agodoc: add a little note about shared ns + LSMs
Tycho Andersen [Thu, 9 May 2019 18:13:40 +0000 (14:13 -0400)] 
doc: add a little note about shared ns + LSMs

We should add a little not about the race in the previous patch.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agolxc_clone: pass non-stack allocated stack to clone
Tycho Andersen [Thu, 9 May 2019 17:52:30 +0000 (13:52 -0400)] 
lxc_clone: pass non-stack allocated stack to clone

There are two problems with this code:

1. The math is wrong. We allocate a char *foo[__LXC_STACK_SIZE]; which
   means it's really sizeof(char *) * __LXC_STACK_SIZE, instead of just
   __LXC_STACK SIZE.

2. We can't actually allocate it on our stack. When we use CLONE_VM (which
   we do in the shared ns case) that means that the new thread is just
   running one page lower on the stack, but anything that allocates a page
   on the stack may clobber data. This is a pretty short race window since
   we just do the shared ns stuff and then do a clone without CLONE_VM.

However, it does point out an interesting possible privilege escalation if
things aren't configured correctly: do_share_ns() sets up namespaces while
it shares the address space of the task that spawned it; once it enters the
pid ns of the thing it's sharing with, the thing it's sharing with can
ptrace it and write stuff into the host's address space. Since the function
that does the clone() is lxc_spawn(), it has a struct cgroup_ops* on the
stack, which itself has function pointers called later in the function, so
it's possible to allocate shellcode in the address space of the host and
run it fairly easily.

ASLR doesn't mitigate this since we know exactly the stack offsets; however
this patch has the kernel allocate a new stack, which will help. Of course,
the attacker could just check /proc/pid/maps to find the location of the
stack, but they'd still have to guess where to write stuff in.

The thing that does prevent this is the default configuration of apparmor.
Since the apparmor profile is set in the second clone, and apparmor
prevents ptracing things under a different profile, attackers confined by
apparmor can't do this. However, if users are using a custom configuration
with shared namespaces, care must be taken to avoid this race.

Shared namespaces aren't widely used now, so perhaps this isn't a problem,
but with the advent of crio-lxc for k8s, this functionality will be used
more.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
6 years agoconfigure: remove additional comma
Christian Brauner [Tue, 21 May 2019 13:58:03 +0000 (15:58 +0200)] 
configure: remove additional comma

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: remove unused label
Christian Brauner [Sat, 18 May 2019 10:21:18 +0000 (12:21 +0200)] 
start: remove unused label

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxccontainer: remove unused function
Christian Brauner [Sat, 18 May 2019 10:05:36 +0000 (12:05 +0200)] 
lxccontainer: remove unused function

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxccontainer: cleanup attach functions
Christian Brauner [Fri, 17 May 2019 05:50:45 +0000 (07:50 +0200)] 
lxccontainer: cleanup attach functions

Specifically, refloat function arguments and remove useless comments.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoattach: do not reload container
Christian Brauner [Thu, 16 May 2019 13:29:41 +0000 (15:29 +0200)] 
attach: do not reload container

Let lxc_attach() reuse the already initialized container.

Closes https://github.com/lxc/lxd/issues/5755.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonetwork: Fixes bug that stopped down hook from running for phys netdevs
Thomas Parrott [Wed, 15 May 2019 16:09:47 +0000 (17:09 +0100)] 
network: Fixes bug that stopped down hook from running for phys netdevs

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agonetwork: move phys netdevs back to monitor's net ns rather than pid 1's
Thomas Parrott [Wed, 15 May 2019 14:54:12 +0000 (15:54 +0100)] 
network: move phys netdevs back to monitor's net ns rather than pid 1's

Updates lxc_restore_phys_nics_to_netns() to move phys netdevs back to the monitor's network namespace rather than the previously hardcoded PID 1 net ns.

This is to fix instances where LXC is started inside a net ns different from PID 1 and physical devices are moved back to a different net ns when the container is shutdown than the net ns than where the container was started from.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agoconfigure: handle checks when cross-compiling
Christian Brauner [Wed, 15 May 2019 13:44:36 +0000 (15:44 +0200)] 
configure: handle checks when cross-compiling

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoError prone semicolon
Rachid Koucha [Mon, 13 May 2019 12:57:02 +0000 (14:57 +0200)] 
Error prone semicolon

Suppressed error prone semicolon in SYSTRACE() macro.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agoUse %m instead of strerror() when available
Rachid Koucha [Mon, 13 May 2019 11:21:14 +0000 (13:21 +0200)] 
Use %m instead of strerror() when available

Use %m under HAVE_M_FORMAT instead of strerror()

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agoConfig: check for %m availability
Rachid Koucha [Mon, 13 May 2019 11:13:18 +0000 (13:13 +0200)] 
Config: check for %m availability

GLIBC supports %m to avoid calling strerror(). Using it saves some code space.
==> This check will define HAVE_M_FORMAT to be use wherever possible (e.g. log.h)

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agoinitutils: Fix memleak on realloc failure
Rikard Falkeborn [Sun, 12 May 2019 00:22:15 +0000 (02:22 +0200)] 
initutils: Fix memleak on realloc failure

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
6 years agozfs: Fix return value on zfs_snapshot error
Rikard Falkeborn [Sat, 11 May 2019 23:47:56 +0000 (01:47 +0200)] 
zfs: Fix return value on zfs_snapshot error

Returning -1 in a function with return type bool is the same as
returning true. Change to return false to indicate error properly.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
6 years agolvm: Fix return value if lvm_create_clone fails
Rikard Falkeborn [Sat, 11 May 2019 23:46:27 +0000 (01:46 +0200)] 
lvm: Fix return value if lvm_create_clone fails

Returning -1 in a function with return type bool is the same as
returning true. Change to return false to indicate error properly.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
6 years agocriu: Remove unnecessary return after _exit()
Rikard Falkeborn [Sat, 11 May 2019 23:39:51 +0000 (01:39 +0200)] 
criu: Remove unnecessary return after _exit()

Since _exit() will terminate, the return statement is dead code. Also,
returning -1 from a function with bool as return type is confusing.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
6 years agocriu: Use -v4 instead of -vvvvvv
Radostin Stoyanov [Fri, 10 May 2019 21:25:54 +0000 (22:25 +0100)] 
criu: Use -v4 instead of -vvvvvv

CRIU has only 4 levels of verbosity (errors, warnings, info, debug).
Thus, using `-v4` is more appropriate.

https://criu.org/Logging

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
6 years agoOption --busybox-path instead of --bbpath
Rachid Koucha [Fri, 10 May 2019 19:28:35 +0000 (21:28 +0200)] 
Option --busybox-path instead of --bbpath

As suggested during the review.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agolxccontainer: do not display if missing privileges
Rachid Koucha [Fri, 10 May 2019 16:56:12 +0000 (18:56 +0200)] 
lxccontainer: do not display if missing privileges

lxc-ls without root privileges on privileged containers should not display
information. In lxc_container_new(), ongoing_create()'s result is not checked
for all possible returned values. Hence, an unprivileged user can send command
messages to the container's monitor. For example:

$ lxc-ls -P /.../tests -f
NAME     STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
ctr -     0         -      -    -    false
$ sudo lxc-ls -P /.../tests -f
NAME     STATE   AUTOSTART GROUPS IPV4      IPV6 UNPRIVILEGED
ctr RUNNING 0         -      10.0.3.51 -    false

After this change:

$ lxc-ls -P /.../tests -f      <-------- No more display without root privileges
$ sudo lxc-ls -P /.../tests -f
NAME     STATE   AUTOSTART GROUPS IPV4      IPV6 UNPRIVILEGED
ctr RUNNING 0         -      10.0.3.37 -    false
$

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoNew --bbpath option and unecessary --rootfs checks
Rachid Koucha [Fri, 10 May 2019 15:01:13 +0000 (17:01 +0200)] 
New --bbpath option and unecessary --rootfs checks

. Add the "--bbpath" option to pass an alternate busybox pathname instead of the one found from ${PATH}.
. Take this opportunity to add some formatting in the usage display
. As a try is done to pick rootfs from the config file and set it to ${path}/rootfs, it is unnecessary to make it mandatory

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agocoding style: update
Christian Brauner [Fri, 10 May 2019 11:15:25 +0000 (13:15 +0200)] 
coding style: update

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoRedirect error messages to stderr
Rachid Koucha [Fri, 10 May 2019 05:39:03 +0000 (07:39 +0200)] 
Redirect error messages to stderr

Some error messages were not redirected to stderr.
Moreover, do "exit 0" instead of "exit 1" when "help" option is passed.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agostart: use CLONE_PIDFD
Christian Brauner [Thu, 9 May 2019 17:40:23 +0000 (19:40 +0200)] 
start: use CLONE_PIDFD

Use CLONE_PIDFD when possible.

Note the clone() syscall ignores unknown flags which is usually a design
mistake. However, for us this bug is a feature since we can just pass the flag
along and see whether the kernel has given us a pidfd.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonetwork: Restores phys device MTU on container shutdown
Thomas Parrott [Thu, 9 May 2019 15:40:08 +0000 (16:40 +0100)] 
network: Restores phys device MTU on container shutdown

The phys devices will now have their original MTUs recorded at start and restored at shutdown.

This is to protect the original phys device from having any container level MTU customisation being applied to the device once it is restored to the host.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agonamespace: support CLONE_PIDFD with lxc_clone()
Christian Brauner [Thu, 9 May 2019 15:09:51 +0000 (17:09 +0200)] 
namespace: support CLONE_PIDFD with lxc_clone()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonetwork: Adds mtu support for phys and macvlan types
Thomas Parrott [Thu, 9 May 2019 14:34:20 +0000 (15:34 +0100)] 
network: Adds mtu support for phys and macvlan types

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
6 years agoclone: add infrastructure for CLONE_PIDFD
Christian Brauner [Thu, 9 May 2019 13:01:27 +0000 (15:01 +0200)] 
clone: add infrastructure for CLONE_PIDFD

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eac7078a0fff1e72cf2b641721e3f55ec7e5e21e

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoraw_syscalls: simplify assembly
Christian Brauner [Thu, 9 May 2019 13:00:32 +0000 (15:00 +0200)] 
raw_syscalls: simplify assembly

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
6 years agoutils: improve switch_to_ns()
Christian Brauner [Tue, 12 Mar 2019 16:51:50 +0000 (17:51 +0100)] 
utils: improve switch_to_ns()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoDevices created in rootfs instead of rootfs/dev
Rachid Koucha [Tue, 7 May 2019 14:03:02 +0000 (16:03 +0200)] 
Devices created in rootfs instead of rootfs/dev

Added /dev in the mknod commands.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
6 years agoraw_syscalls: add initial support for pidfd_send_signal()
Christian Brauner [Mon, 6 May 2019 08:49:31 +0000 (10:49 +0200)] 
raw_syscalls: add initial support for pidfd_send_signal()

Well, I added this syscall so we better use it. :)

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocompiler: add __returns_twice attribute
Christian Brauner [Sat, 4 May 2019 11:35:51 +0000 (13:35 +0200)] 
compiler: add __returns_twice attribute

The returns_twice attribute tells the compiler that a function may return more
than one time. The compiler will ensure that all registers are dead before
calling such a function and will emit a warning about the variables that may be
clobbered after the second return from the function. Examples of such functions
are setjmp and vfork. The longjmp-like counterpart of such function, if any,
might need to be marked with the noreturn attribute.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agotree-wide: make socket SOCK_CLOEXEC
Christian Brauner [Fri, 3 May 2019 18:35:02 +0000 (20:35 +0200)] 
tree-wide: make socket SOCK_CLOEXEC

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonamespaces: allow a pathname to a nsfd for namespace to share
Serge Hallyn [Thu, 2 May 2019 01:17:23 +0000 (18:17 -0700)] 
namespaces: allow a pathname to a nsfd for namespace to share

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
6 years agoseccomp: notifier fixes
Christian Brauner [Tue, 30 Apr 2019 22:36:41 +0000 (00:36 +0200)] 
seccomp: notifier fixes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonetwork: Fixes bug in macvlan mode selection
tomponline [Mon, 29 Apr 2019 14:11:17 +0000 (15:11 +0100)] 
network: Fixes bug in macvlan mode selection

Signed-off-by: tomponline <thomas.parrott@canonical.com>
6 years agotests: Updates .gitignore to ignore test build artefacts
tomponline [Mon, 29 Apr 2019 08:49:07 +0000 (09:49 +0100)] 
tests: Updates .gitignore to ignore test build artefacts

Signed-off-by: tomponline <thomas.parrott@canonical.com>