Commit Graph

10783 Commits

Author SHA1 Message Date
Christian Brauner
5ba5725cb4
cgroups: modify cgroup2 attach logic
Recent kernels have seen various permission checking fixes when moving
processes into cgroups. So we're forced to modify how we attach to
containers.

Link: https://discuss.linuxcontainers.org/t/lxd-4-23-unable-to-start-nested-containers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-02-24 11:33:16 -05:00
Christian Brauner
1e4631641e
ttys: ensure container_ttys= env variable is set correctly
Fixes: #4088
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-02-23 09:41:28 -05:00
KATOH Yasufumi
8ef019a6ce
doc: Fix reverse allowlist/denylist in Japanese man page
Update for commit 2965130c45

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2022-02-21 23:05:41 -05:00
Christian Brauner
f1c4a17e7d
cgroups: log fd of newly created cgroup
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-02-21 23:05:37 -05:00
Christian Brauner
f7446b4e10
cgroups: check that opened file descriptor is a cgroup filesystem
Link: https://discuss.linuxcontainers.org/t/lxd-4-23-unable-to-start-nested-containers/13416
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-02-21 23:05:34 -05:00
Stéphane Graber
71ba7f6561
doc: Fix reverse allowlist/denylist
Reported at: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1957934
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-02-21 23:05:30 -05:00
Stéphane Graber
f314419d1e
lxc-checkconfig: Fix bashism
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-02-21 23:05:27 -05:00
Antonio Terceiro
ca4c25c6e9
lxc-net: don't start by default inside lxc
When lxc is installed inside an lxc container, trying to bring up
lxc-net with the default parameters will conflict with the networking
setup for lxc on the host. This breaks all networking inside the
container where lxc is installed.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
2022-02-21 23:05:24 -05:00
Stéphane Graber
7e37cc96bb
Release LXC 4.0.12
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-02-01 23:26:09 -05:00
Christian Brauner
d678aa61e0
lxccontainer: allow xdev when creating the container dir
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:25 +01:00
Stéphane Graber
bc61d2354b
github: Clear default ACL on /home
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-01-27 10:32:22 +01:00
Christian Brauner
fb0e0b3dd2
github: add systemd-coredump
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:20 +01:00
Christian Brauner
53e0d390cc
github: more detailed compilation instructions
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:17 +01:00
Christian Brauner
db84a8b6b0
github: log system info
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:13 +01:00
Christian Brauner
e9282b6a6e
github: ensure system liblxc is wiped
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:11 +01:00
Christian Brauner
ad8a3bd68a
lxccontainer: properly wrap lxcapi_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:07 +01:00
Christian Brauner
bceb81cd26
build: simplify thread local storage handling
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:04 +01:00
Christian Brauner
919da35b03
build: only enable LTO for regular builds
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:32:01 +01:00
Christian Brauner
d0a1e9c44b
lxccontainer: simplify partial file creation
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:57 +01:00
Christian Brauner
62b5c00510
lxccontainer: improve create_partial()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:54 +01:00
Christian Brauner
bfe24cb6ac
lxccontainer: improve do_lxcapi_create()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:51 +01:00
Christian Brauner
1a5c236acf
lxccontainer: improve do_lxcapi_save_config()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:47 +01:00
Christian Brauner
bae0d71965
conf: log termination status
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:43 +01:00
Christian Brauner
4eb09aaad4
conf: improve userns_exec_mapped_root()
As we do in all other places, first drop groups, then use
setres{g,u}id().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:39 +01:00
Simon Deziel
9289432805
github: stop installing gnupg now that it's unused
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
2022-01-27 10:31:26 +01:00
Stéphane Graber
7c70b0d143
lxc-download: Rely on HTTPS only
GPG has been a major source of issues over the years with various
attacks on the key network as well as client side issues making it hard
to retrieve our keys.

Back when we introduced the image server, SSL certificates were still
expensive and annoying to setup, so not something we'd have expected
potential mirrors to setup for us. They were also issued for multiple
years, making a compromise of such a certificate quite problematic.

But things have changed since, we now have completely free, very easily
deployable SSL certificates everywhere with the majority of those being
shortlived and with good reporting of issued certificates.

With that, we can now deprecate the GPG validation, disable the fallback
to non-HTTPS download and rely on our indices being accurate because
they've been downloaded from a server with a valid certificate.

This puts LXC more in line with what LXD has done since the beginning
and should offer a more reliable user experience.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2022-01-27 10:31:23 +01:00
Devin Norgarb
199d2077c6
Update README.md: Fix broken link (403 Forbidden)
Signed-off-by: Devin Norgarb dnorgarb@gmail.com
2022-01-27 10:31:19 +01:00
Christian Brauner
0b6b230e34
attach: don't pointlessly call cgroup_init()
We can let attach detect that it is running on a cgroup layout without
writable cgroup hierarchies. In that case attach can finish early and
doesn't need to run the heavy-handed cgroup parsing code.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:16 +01:00
Christian Brauner
dbef704fbc
commands: log command during file descriptor retrieval
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:31:11 +01:00
Tim
733f9c909b
lxc-checkconfig.in: CONFIG_NF_NAT_IPV4 was removed from the kernel 2019-03-03
Signed-off-by: Tim L <elatllat@gmail.com>
2022-01-27 10:31:07 +01:00
Serge Hallyn
ce392e2309
(trivial) Fix error message, failure was connect not bind
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2022-01-27 10:31:04 +01:00
Christian Brauner
5628bff79d
seccomp: close seccomp notifier fd in cleanup handler
Reported-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2022-01-27 10:30:58 +01:00
Christian Brauner
1f2af83a99
seccomp: only guard seccomp notify behind HAVE_DECL_SECCOMP_NOTIFY_FD
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-12-13 16:09:12 +01:00
Christian Brauner
9451303d5e
api-extensions: don't advertise seccomp notify support if it's not compiled in
Link: https://discuss.linuxcontainers.org/t/runtimeerror-failed-to-read-zi-bytes-from-dev-urandom
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-12-13 16:09:09 +01:00
Wolfgang Bumiller
23d07c3157
use 2 sysfs instances for sys:mixed
In order to facilitate this, the default mount list's
'destination' may now be NULL to mean that the source should
be unmounted instead.

Here's what we need to do:

1) Ensure the first sysfs mount point is writable.
2) Mount a read-only sysfs on /sys
3) Bind devices/virtual/net *writably* into /sys

We use /proc/sys as a staging directory for the first sysfs
mount in read-write mode, then mount /sys r/o. Afterwards we
bind the r/w devices/virtual/net and unmount the staging
/proc/sys mount point.

The staging directory would not be required with the new
mount API, but this way we can support the old API and keep
the general workflow in the `default_mounts`.

Once we drop support for the old mount API, the
default_mounts table could just get a subdirectory field to
mount subdirectories directly.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-06 11:24:02 +01:00
Stéphane Graber
0dd3258bdd
Revert "api: ->save_config() doesn't need to create container dir"
This reverts commit 2fde07c399.

We need to investigate this in more detail but this commit is breaking
LXD, causing startup to fail with:

lxc foo 20211130202833.906 INFO     conf - conf.c:run_script_argv:336 - Executing script "/bin/mount -t shiftfs -o passthrough=3 "/lxc-ci/build/tmp.WemmpzWGYz/go/src/github.com/lxc/lxd/test/tmp.Cli/0To/containers/foo/rootfs" "/lxc-ci/build/tmp.WemmpzWGYz/go/src/github.com/lxc/lxd/test/tmp.Cli/0To/containers/foo/rootfs"" for container "foo"
lxc foo 20211130202833.912 ERROR    conf - conf.c:run_buffer:321 - Script exited with status 32
lxc foo 20211130202833.912 ERROR    conf - conf.c:lxc_setup_rootfs_prepare_root:3947 - Failed to run pre-mount hooks
lxc foo 20211130202833.912 ERROR    conf - conf.c:lxc_setup:4317 - Failed to setup rootfs
lxc foo 20211130202833.912 ERROR    start - start.c:do_start:1275 - Failed to setup container "foo"

Not entirely sure why we're seeing things blow up as the directory
definitely exists (and contains a valid rootfs) but this was caused by
today's liblxc update.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-12-01 10:38:58 -05:00
Tycho Andersen
93edd510ae
api: ->save_config() doesn't need to create container dir
If we're saving the config file to somewhere that's *not* the container
dir, we don't need to create the container dir. Let's not do this and
thus not require its parent to exist, which can be confusing, especially in
light of the sparse logging through these functions.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2021-11-30 13:18:52 +01:00
Tycho Andersen
28b2e04f17
cgroups: fix compiler warning
I get:

In file included from cgroups/cgfsng.c:42:
In function 'cpuset1_cpus_initialize',
    inlined from 'cpuset1_initialize' at cgroups/cgfsng.c:658:7,
    inlined from '__cgroup_tree_create.constprop' at cgroups/cgfsng.c:723:26:
./log.h:376:9: error: '%s' directive argument is null [-Werror=format-overflow=]
  376 |         LXC_ERROR(&locinfo, format, ##__VA_ARGS__);                     \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./log.h:457:17: note: in expansion of macro 'ERROR'
  457 |                 ERROR("%s - " format, ptr, ##__VA_ARGS__); \
      |                 ^~~~~
./log.h:491:17: note: in expansion of macro 'SYSERROR'
  491 |                 SYSERROR(format, ##__VA_ARGS__);              \
      |                 ^~~~~~~~
cgroups/cgfsng.c:585:24: note: in expansion of macro 'log_error_errno'
  585 |                 return log_error_errno(false, errno, "Failed to read file \"%s\"", fpath);
      |                        ^~~~~~~~~~~~~~~

it turns out here that fpath is not used, so let's get rid of it and just
render the dfd+pathname directly.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2021-11-30 13:18:49 +01:00
Wolfgang Bumiller
15515f9a3b
Revert "initutils: use vfork() in lxc_container_init()"
This reverts commit d65e5e492f.

With vfork the child process modifies the parent's memory,
so the calls to `signal`, `fprintf` and regular `exit` may
be dangerous and might cause conflicting states in the
parent.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-11-15 10:45:15 +01:00
Christian Brauner
41d2530d1d
macro: ensure necessary io_uring flags are defined
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-10 11:51:34 +01:00
Joan Bruguera
fc4e948c9b
autotools: Avoid multiple liblxc.so with --enable-pam
When installing LXC with the default options, a single non-symlink liblxc.so*
(e.g. liblxc.so.1.7.0) file is created:

```
    $ ./autogen.sh && ./configure && make && \
    rm -rf "$HOME/lxci" && make DESTDIR="$HOME/lxci" install && \
    stat -c%N "$HOME/lxci/usr/local/lib/liblxc.so"*
    [...]
    '/home/someone/lxci/usr/local/lib/liblxc.so' -> 'liblxc.so.1'
    '/home/someone/lxci/usr/local/lib/liblxc.so.1' -> 'liblxc.so.1.7.0'
    '/home/someone/lxci/usr/local/lib/liblxc.so.1.7.0'
```

However, when automake>=1.16.5, and the `--enable-pam` option is used, two
non-symlink liblxc.so* (e.g. liblxc.so.1.0.0 and liblxc.so.1.7.0) are
erroneously created:

```
    $ ./autogen.sh && ./configure --enable-pam && make && \
    rm -rf "$HOME/lxci" && make DESTDIR="$HOME/lxci" install && \
    stat -c%N "$HOME/lxci/usr/local/lib/liblxc.so"*
    [...]
    '/home/someone/lxci/usr/local/lib/liblxc.so' -> 'liblxc.so.1.0.0'
    '/home/someone/lxci/usr/local/lib/liblxc.so.1' -> 'liblxc.so.1.0.0'
    '/home/someone/lxci/usr/local/lib/liblxc.so.1.0.0'
    '/home/someone/lxci/usr/local/lib/liblxc.so.1.7.0'
```

This is due to infighting between libtool's and LXC's versioning:
libtool creates liblxc.so.1.0.0, then LXC's `install-exec-local` hook in
`Makefile.am` moves it to liblxc.so.1.7.0. However, with `--enable-pam`, the
`install-libLTLIBRARIES` target is re-triggered after `install-pamLTLIBRARIES`,
which will create liblxc.so.1.0.0 again.

The bigger problem here is that the install for the pam_cgfs library is done on
the `data` phase of the automake install process instead of the `exec` phase
(https://www.gnu.org/software/automake/manual/html_node/The-Two-Parts-of-Install.html),
which gives `install-libLTLIBRARIES` a chance to run again after the
`install-exec-local` / `install-exec-hook` targets have already run.

To fix this, we add an "exec_" prefix to the pam_cgfs library to make it run
during the `exec` phase (see link above). We also consolidate the various hooks
in the `install-exec-hook` target, which runs after the whole install, avoiding
needing to manually specify the dependencies like in `install-exec-local`.

Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
2021-11-09 14:04:53 +01:00
Christian Brauner
a616a311a3
build: refuse to compile with unsupported liburing version
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:41 +01:00
Christian Brauner
93be4e5121
tests: add lxc.proc.* test
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:40 +01:00
Christian Brauner
d8027e49c3
tests: add lxc.sysctls.* test
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:39 +01:00
Christian Brauner
6f580343e5
test: improve logging helpers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:38 +01:00
Christian Brauner
a10ff34188
conf: improve logging setting sysctl and /proc/<pid>/ parameters
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:36 +01:00
Christian Brauner
334cf7beba
conf: apply /proc/sys and /proc/<pid>/ parameters
When porting to the new list type we added an accidental ! when checking
whether the list is empty.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-04 16:29:33 +01:00
Christian Brauner
1b74e01add
tests: include config.h
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-03 10:42:42 +01:00
Christian Brauner
c363794319
build: move _FILE_OFFSET_BITS to common option
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-03 10:42:39 +01:00
Christian Brauner
f24c234ee9
start: log signal name and number
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-11-03 10:42:37 +01:00