Commit Graph

174 Commits

Author SHA1 Message Date
Christian Brauner
8e64b6736f
cgroups/cgfsng: rework cgroup removal
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-12-10 22:55:44 +01:00
Christian Brauner
fe70edeee5
cgroups: flatten hierarchy
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-12-10 14:07:08 +01:00
Christian Brauner
cc73685dd0
lxc: switch to SPDX
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-12-04 13:48:46 +01:00
Christian Brauner
4d8bdfa030 start: handle setting pdeath signal in new pidns
In the usual case the child runs in a separate pid namespace. So far we haven't
been able to reliably set the pdeath signal. When we set the pdeath signal we
need to verify that we haven't lost a race whereby we have been orphaned and
though we have set a pdeath signal it won't help us since, well, the parent is
dead.
We were able to correctly handle this case when we were in the same pidns since
getppid() will return a valid pid. When we are in a separate pidns 0 will be
returned since the parent doesn't exist in our pidns.
A while back, while Jann and I were discussing other things he came up with a
nifty idea: simply pass an fd for the parent's status file and check the
"State:" field. This is the implementation of that idea.

Suggested-by: Jann Horn <jann@thejh.net>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-10-04 07:31:37 -07:00
Julio Faracco
7c3d3976fa 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>
2019-08-03 02:16:13 -03:00
Serge Hallyn
fa2bb6ba53 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>
2019-06-13 22:19:27 -05:00
Alexander Kriventsov
b9f80409d7 getgrgid_r fails with ERANGE if buffer is too small. Retry with a larger buffer.
Signed-off-by: Alexander Kriventsov <akriventsov@nic.ru>
2019-06-03 18:11:56 +03:00
tomponline
99a8edfc3a lvm: Updates lvcreate to wipe signatures if supported, fallbacks to old command if not.
Signed-off-by: tomponline <tomp@tomp.uk>
2019-03-26 08:44:28 +00:00
Christian Brauner
ebf3a6af23
conf: remove fgets() from run_buffer()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-03-01 12:17:46 +01:00
Josh Soref
54d423b874 spelling: allocate
Signed-off-by: Josh Soref <jsoref@gmail.com>
2018-10-30 06:45:18 +00:00
Christian Brauner
07a50156ed
raw_syscalls: move lxc_raw_gettid()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 13:10:55 +02:00
Christian Brauner
303037d2f6
syscall_wrappers: move signalfd()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 13:08:51 +02:00
Christian Brauner
e8f764b6bc
syscall_wrappers: move unshare()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 13:03:30 +02:00
Christian Brauner
364932cfae
syscall_wrappers: move sethostname()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 13:00:21 +02:00
Christian Brauner
59524108dd
syscall_wrappers: move setns()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 12:57:32 +02:00
Christian Brauner
6a886ddf19
syscall_wrappers: move memfd_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 12:49:46 +02:00
Christian Brauner
c7f493aee0
utils: fix lxc_set_death_signal()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-02 21:00:59 +02:00
Christian Brauner
d7b58715b6
raw_syscalls: add lxc_raw_getpid()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-30 20:20:16 +02:00
Christian Brauner
b25291da14
utils: add lxc_setup_keyring()
Allocate a new keyring if we can to prevent information leak.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-28 13:41:14 +02:00
Christian Brauner
d38dd64a51
tree-wide: fix includes to fix bionic builds
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-27 01:01:33 +02:00
Christian Brauner
464c46115f
utils: make lxc_switch_uid_gid() return bool
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-11 10:55:07 +02:00
Christian Brauner
8af07f821c
utils: make lxc_setgroups() return bool
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-11 10:54:46 +02:00
Christian Brauner
db2d1af171
utils: improve lxc_switch_uid_gid()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-11 00:44:57 +02:00
Christian Brauner
b962868f4c
utils: improve get_ns_uid() and add get_ns_gid()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-11 00:44:56 +02:00
Christian Brauner
37ef15bbd2
utils: split into {file,string}_utils.{c,h}
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-21 13:00:20 +02:00
Christian Brauner
f26dc127bf
CVE 2018-6556: verify netns fd in lxc-user-nic
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-06 12:15:39 -04:00
Christian Brauner
279c45eed3
macro: add new macro header
This allows us to use a bunch of macros in our static build for init.lxc.static
without having to link against all of utils.{c,h}.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-04 20:11:58 +02:00
Christian Brauner
521b4771a9
utils: add lxc_iterate_parts()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-26 16:23:09 +02:00
Wolfgang Bumiller
eb5c2e6aee utils: add must_concat helper
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-07-25 12:12:27 +02:00
Liza Tretyakova
f6310f1844
utils: add shared mount point detection
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
2018-07-22 15:25:15 +02:00
2xsec
d7ab03757c
utils: move recursive_destroy() from cfgsng to utils.
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-07-03 14:44:24 +09:00
Christian Brauner
a9d4ebc168
utils: add fd_cloexec()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-07-01 20:00:14 +02:00
2xsec
b14fc1007c utils: code cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-06-30 18:45:21 +09:00
Christian Brauner
573ad77fc2
utils: fix task_blocking_signal()
Closes #2342.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-05-26 21:47:46 +02:00
Christian Brauner
7ad3767052
utils: add remove_trailing_newlines()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-05-24 13:38:08 +02:00
Felix Abecassis
eacebcc3cb seccomp: fix type mismatch when parsing syscall arguments filters
Specifier %lli was insufficient for the type uint64_t, all values
between 2^63-1 and 2^64-1 were silently converted to 2^63-1.

We can't use %llu since it doesn't handle hexadecimal. Instead, we
parse the values as strings and then use strtoull(3).

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-05-23 22:38:25 -07:00
Christian Brauner
aa769a272f
utils: add LXC_PROC_PID_FD_LEN
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-05-04 11:59:11 +02:00
Christian Brauner
7cea590585
lxccontainer: use thread-safe open() + write()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-04-29 16:42:44 +02:00
Christian Brauner
9e320621fd
utils: define __NR_setns if missing on old glibcs
Closes #2248.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-04-10 12:27:39 +02:00
Christian Brauner
238b3e5ea4
lxccontainer: move macros to utils.h
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-02-24 21:38:03 +01:00
Christian Brauner
9994d1402c
confile: use mmap() to parse config file
Sigh, this is going to be fun. Essentially, dynamic memory allocation through
malloc() and friends is unsafe when fork()ing in threads. The locking state
that glibc maintains internally might get messed up when the process that
fork()ed calls malloc or calls functions that malloc() internally. Functions
that internally malloc() include fopen(). One solution here is to use open() +
mmap() instead of fopen() + getline().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-02-24 21:37:39 +01:00
Christian Brauner
5038d11a98
utils: include linux/types.h
Closes #2178.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-02-21 10:13:12 +01:00
Christian Brauner
1fd0f41eff
utils: add lxc_set_death_signal()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-02-19 10:58:56 +01:00
Serge Hallyn
477aa378e9 define am_guest_unpriv
Sometimes we want to know whether we are privileged wrt our
namespaces, and sometimes we want to know whether we are priv
wrt init_user_ns.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
2018-02-08 12:06:39 -06:00
Christian Brauner
0c3deb94f4
cgroups: cgfsng_create: handle unified hierarchy
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-31 16:35:31 +01:00
Serge Hallyn
26f0e9151a
Merge pull request #2102 from brauner/2018-01-22/lsm_simplifications
lsm: simplifcations
2018-01-29 17:08:38 -06:00
Tycho Andersen
5384e99dee rename am_unpriv to am_host_unpriv
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2018-01-26 22:11:50 +00:00
Tycho Andersen
4692c01af2 better unprivileged detection
In particular, if we are already in a user namespace we are unprivileged,
and doing things like moving the physical nics back to the host netns won't
work. Let's do the same thing LXD does if euid == 0: inspect
/proc/self/uid_map and see what that says.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2018-01-26 22:11:50 +00:00
Christian Brauner
5288a74faa
apparmor: do not call aa_change_profile()
We can simply write the label ourselves. There's no magic happening.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-22 12:14:14 +01:00
Christian Brauner
0059379ff4
tree-wide: s/getpid()/lxc_raw_getpid()/g
This is to avoid bad surprises caused by older glibc's pid cache (up to 2.25)
when using clone().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:03 +01:00