Commit Graph

10986 Commits

Author SHA1 Message Date
Stéphane Graber
d31bfd247d
Merge pull request #3892 from brauner/2021-07-01.fixes.2
terminal: ensure newlines are turned into newlines+carriage return fo…
2021-07-01 08:56:59 -04:00
Stéphane Graber
161b0ff427
Merge pull request #3893 from brauner/2021-07-01.fixes.3
cmd/lxc-checkconfig: list cgroup namespaces and rename confusing ns_c…
2021-07-01 08:51:44 -04:00
Christian Brauner
d1073415db
cmd/lxc-checkconfig: list cgroup namespaces and rename confusing ns_cgroup entry
Link: https://discuss.linuxcontainers.org/t/cgroup-namespace-required-in-lxc-checkconfig-and-config-cgroup-ns
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 13:40:18 +02:00
Christian Brauner
9027547494
terminal: ensure newlines are turned into newlines+carriage return for terminal output
Fixes: #3879
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 10:23:47 +02:00
Christian Brauner
f4afdfbe65
cgroups: handle funky cgroup layouts
Old versions of Docker emulate a cgroup namespace by bind-mounting the
container's cgroup over the corresponding controller:

/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime master:11 - cgroup cgroup rw,xattr,name=systemd
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/net_cls,net_prio rw,nosuid,nodev,noexec,relatime master:15 - cgroup cgroup rw,net_cls,net_prio
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime master:16 - cgroup cgroup rw,cpu,cpuacct
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime master:17 - cgroup cgroup rw,memory
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime master:18 - cgroup cgroup rw,devices
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime master:19 - cgroup cgroup rw,hugetlb
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime master:20 - cgroup cgroup rw,perf_event
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime master:21 - cgroup cgroup rw,cpuset
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime master:22 - cgroup cgroup rw,blkio
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/pids rw,nosuid,nodev,noexec,relatime master:23 - cgroup cgroup rw,pids
/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod7d4424e6_bb13_42f4_a47a_45a4828bf54d.slice/docker-d0b3604b67ac7930dd34ba3a796627e3e4717d12309e90a4afe3f38b6816ac98.scope /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime master:24 - cgroup cgroup rw,freezer

New versions of LXC always stash a file descriptor for the root of the
cgroup mount at /sys/fs/cgroup and then resolve the current cgroup
parsed from /proc/{1,self}/cgroup relative to that file descriptor. This
doesn't work when the caller's cgroup is mouned over the controllers.
Older versions of LXC simply counted such layouts as having no cgroups
available for delegation at all and moved on provided no cgroup limits
were requested. But mainline LXC would fail such layouts. While I would
argue that failing such layouts is the semantically clean approach we
shouldn't regress users so make mainline LXC treat such cgroup layouts
as having no cgroups available for delegation.

Fixes: #3890
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 09:57:09 +02:00
Stéphane Graber
e751379640
Merge pull request #3888 from brauner/2021-06-30.fixes
Improve read-only /sys with read-write /sys/devices/virtual/net
2021-06-30 10:30:27 -04:00
Christian Brauner
d777ffccff
tests: add tests for read-only /sys with read-write /sys/devices/virtual/net
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-30 13:58:27 +02:00
Christian Brauner
cb4889abc8
conf: improve read-only /sys with read-write /sys/devices/virtual/net
Some tools require /sys/devices/virtual/net to be read-write. At the
same time we want all other parts of /sys to be read-only. To do this we
created a layout where we hade a read-only instance of sysfs mounted on
top of a read-write instance of sysfs:

`-/sys                                  sysfs                                                        sysfs      rw,nosuid,nodev,noexec,relatime
  `-/sys                                sysfs                                                        sysfs      ro,nosuid,nodev,noexec,relatime
    |-/sys/devices/virtual/net          sysfs                                                        sysfs      rw,relatime
    | `-/sys/devices/virtual/net        sysfs[/devices/virtual/net]                                  sysfs      rw,nosuid,nodev,noexec,relatime

This causes issues for systemd services that create a separate mount
namespace as they get confused to what mount options need to be
respected.

Simplify our mounting logic so we end up with a single read-only mount
of sysfs on /sys and a read-write bind-mount of /sys/devices/virtual/net:

├─/sys                                sysfs                                                                                  sysfs         ro,nosuid,nodev,noexec,relatime
│ ├─/sys/devices/virtual/net          sysfs[/devices/virtual/net]                                                            sysfs         rw,nosuid,nodev,noexec,relatime

Link: systemd/systemd#20032
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-30 13:22:15 +02:00
Christian Brauner
fda9bfb721
Merge pull request #3887 from simondeziel/closedir
initutils: close dirfd in error path
2021-06-30 12:56:03 +02:00
Simon Deziel
9884f0a64b initutils: close dirfd in error path
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
2021-06-29 11:50:09 -04:00
Christian Brauner
804f3e2a12
Merge pull request #3885 from tych0/dont-exec-execute
execute: don't exec init, call it
2021-06-29 16:08:19 +02:00
Christian Brauner
734a677ed2
execute: ensure parent is notified about child exec and close all unneeded fds
lxc_container_init() creates the container payload process as it's child
so lxc_container_init() itself never really exits and thus the parent
isn't notified about the child exec'ing since the sync file descriptor
is never closed. Make sure it's closed to notify the parent about the
child's exec.

In addition we're currently leaking all file descriptors associated with
the handler into the stub init. Make sure that all file descriptors
other than stderr are closed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 11:20:55 +02:00
Christian Brauner
a1150aa174
network: log network devices while sending
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 10:39:38 +02:00
Christian Brauner
d65e5e492f
initutils: use vfork() in lxc_container_init()
We can let the child finish calling exec before continuing in the
parent.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 10:39:38 +02:00
Tycho Andersen
96294efb35
execute: don't exec init, call it
Instead of having a statically linked init that we put on the host fs
somewhere via packaging, have to either bind mount in or detect fexecve()
functionality, let's just call it as a library function. This way we don't
have to do any of that.

This also fixes up a bunch of conditions from:

if (quiet)
    fprintf(stderr, "log message");

to

if (!quiet)
    fprintf(stderr, "log message");

:)

and it drops all the code for fexecve() detection and bind mounting our
init in, since we no longer need any of that.

A couple other thoughts:

* I left the lxc-init binary in since we ship it, so someone could be using
  it outside of the internal uses.
* There are lots of unused arguments to lxc-init (including presumably
  --quiet, since nobody noticed the above); those may be part of the API
  though and so we don't want to drop them.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2021-06-29 10:39:36 +02:00
Wolfgang Bumiller
f1c64634c4
Merge pull request #3877 from tomasz-blaszczak-red/fix-crash-after-remove-from-array
remove_from_array() causes a crash
2021-06-29 08:54:43 +02:00
Tomasz Blaszczak
bc5f0449c0 When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, memory allocated for that item
should be freed, successive items should be left-shifted and the array
realloc()ed again (size-1).

Additional changes:
- If strdup() fails in add_to_array(), then an array should be
  realloc()ed again to original size.
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-29 08:20:51 +02:00
Wolfgang Bumiller
5e3ec98927
Merge pull request #3884 from brauner/2021-06-28.fixes
cgroups: verify that hierarchies are non-empty
2021-06-28 12:32:11 +02:00
Christian Brauner
414fbacca9
cgroups: verify that hierarchies are non-empty
Fixes: #3881
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-28 09:44:20 +02:00
Christian Brauner
0aa47c8fe2
Merge pull request #3882 from stgraber/master
lxc-download: Switch GPG server
2021-06-28 09:39:50 +02:00
Stéphane Graber
f2a5d95d00
lxc-download: Switch GPG server
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-06-27 23:42:52 -04:00
Tomasz Blaszczak
5364ae41aa Resize array in remove_from_array() and fix a crash
When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, allocated memory pointed by
the item (not the item itself) should be freed, successive items should
be left-shifted and the array realloc()ed again (size-1).

Additional changes:
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-25 13:16:24 +02:00
Tomasz Blaszczak
fe444ea6bc When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, memory allocated for that item
should be freed, successive items should be left-shifted and the array
realloc()ed again (size-1).

Additional changes:
- If strdup() fails in add_to_array(), then an array should be
  realloc()ed again to original size.
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-23 10:41:39 +02:00
Stéphane Graber
2ccc8081d2
Merge pull request #3870 from brauner/2021-06-16.fixes
cgroups: use stable ordering for co-mounted v1 controllers
2021-06-16 08:42:55 -04:00
Christian Brauner
91d0151d89
cgroups: use stable ordering for co-mounted v1 controllers
Fixes: #3703
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-16 10:03:42 +02:00
Stéphane Graber
b103a2ceec
Merge pull request #3867 from brauner/2021-06-14.fixes
remove problematic terminology
2021-06-14 13:41:50 -04:00
Christian Brauner
b7b227cc01
tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:26:24 +02:00
Christian Brauner
8de0119d48
tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:25:39 +02:00
Christian Brauner
f48e807159
tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:21:44 +02:00
Christian Brauner
4f6c7312ef
tree-wide: remove problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:15:43 +02:00
Christian Brauner
1c01dc2c5e
seccomp: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:14:26 +02:00
Christian Brauner
af6a5f3add
common.conf: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 17:13:00 +02:00
Christian Brauner
a065524e28
Merge pull request #3865 from brauner/2021-06-14.listen_fds
Add support for LISTEN_FDS environment variable.
2021-06-14 13:29:20 +02:00
Ruben Jenster
46abf21981
Add support for LISTEN_FDS environment variable.
The LISTEN_FDS environment variable defines the number of
file descriptors that should be inherited by the container,
in addition to stdio.
The LISTEN_FDS environment variable is defined in the OCI spec
and used to support socket activation.

Refs #3845

Signed-off-by: Ruben Jenster <r.jenster@drachenfels.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 11:58:24 +02:00
Christian Brauner
51bbca901b
Merge pull request #3864 from lifeng68/master
string utils: Make sure don't return uninitialized memory.
2021-06-14 11:34:14 +02:00
LiFeng
47f5be06a4 string utils: Make sure don't return uninitialized memory.
The function lxc_string_split_quoted and lxc_string_split_and_trim use
realloc to reduce the memory. But the result may be NULL, the the
returned memory will be uninitialized

Signed-off-by: LiFeng <lifeng68@huawei.com>
2021-06-12 14:56:04 +08:00
Stéphane Graber
a197d2fb5b
Merge pull request #3861 from brauner/2021-06-08.fixes.2
api_extensions: introduce idmapped_mounts_v2 api extension
2021-06-08 10:46:00 -04:00
Christian Brauner
3df13023b0
api_extensions: introduce idmapped_mounts_v2 api extension
This indicates that LXC supports idmapping the rootfs and
idmapped lxc.mount.entry entries.

Link: https://github.com/lxc/lxd/issues/8870
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-08 15:59:13 +02:00
Stéphane Graber
2384faa223
Merge pull request #3860 from brauner/2021-06-08.fixes
tools/lxc_autostart: fix failed count
2021-06-08 09:21:35 -04:00
Christian Brauner
2f7828f699
tools/lxc_autostart: fix failed count
Don't include skipped containers in the failed count.

Fixes: #3857
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-08 15:01:02 +02:00
Stéphane Graber
81ec0d7ebf
Merge pull request #3856 from brauner/2021-06-07.fixes
lsm/apparmor: actually report an error when we fail to wire AppArmor …
2021-06-07 10:31:32 -04:00
Christian Brauner
fd697cc0e9
lsm/apparmor: actually report an error when we fail to wire AppArmor profile
Link: https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/1931064
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-07 15:38:10 +02:00
Stéphane Graber
4e92ee3b5d
Merge pull request #3854 from brauner/2021-06-03.fixes
lxc: add lpthread to lxc.pc
2021-06-03 11:21:35 -04:00
Christian Brauner
c2a7a6977b
lxc: add lpthread to lxc.pc
Fixes: #3853
Suggested-by: Tycho Andersen <tycho@tycho.pizza>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-03 15:50:20 +02:00
Stéphane Graber
ca5843e1bc
Merge pull request #3852 from pablofsf/lxc-net-nftables
Update lxc-net to support nftables
2021-05-28 16:28:57 -04:00
Pablo Correa Gómez
7f4386f096
Update lxc-net to support nftables
Closes #3093
Closes #3602

Add support for nftables firewall rules if `nft` command line
interface is available in the system

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
2021-05-28 14:33:23 +02:00
Stéphane Graber
6805cc3666
Merge pull request #3851 from brauner/2021-05-25.fixes
fixes
2021-05-25 09:56:43 -04:00
Christian Brauner
4db0514d56
network: please broken compilers
Some users report that compilation fails because of reports that this
variable can be used uninitialized. Initialize it to silence the
compiler.

Fixes: https://github.com/lxc/lxc/issues/3850
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-25 14:24:01 +02:00
Christian Brauner
f07ba4f991
Merge pull request #3849 from stgraber/master
README: Update IRC
2021-05-25 09:01:34 +02:00
Stéphane Graber
c49b9f61b2
README: Update IRC
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-05-24 12:13:20 -04:00