Commit Graph

10927 Commits

Author SHA1 Message Date
Stéphane Graber
10fe481d5f
Fix typos
This fixes all typos identified by lintian.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-07-28 15:14:38 -04:00
Christian Brauner
7294a26d3d
conf: ensure devpts_fd is set to -EBADF
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-28 18:40:14 +02:00
Christian Brauner
ecfc18270e
terminal: ttyname_r() returns an error number on failure
In other words, how inconsistent can an API be?

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-28 18:40:13 +02:00
Christian Brauner
289b707bd1
conf: use new mount api for devpts setup
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-28 18:40:13 +02:00
Christian Brauner
f10866f0d5
Merge pull request #3910 from petris/tty_enxio
lxc_setup_ttys: Handle existing ttyN file without underlying device
2021-07-22 09:24:15 +02:00
Christian Brauner
b9327b7f92
Merge pull request #3909 from petris/bpf_enosys_warn
bpf: simplify detection if BPF is supported
2021-07-21 15:25:36 +02:00
Christian Brauner
669953fbd1
Merge pull request #3911 from siv0/fix_legacy_cgroup_devices
Fix legacy cgroup devices
2021-07-20 17:57:42 +02:00
Petr Malat
7bf85dd20e bpf: bpf_devices_cgroup_supported() should check if bpf() is available
bpf_devices_cgroup_supported() tries to load a simple BPF program to
test if BPF works. This is problematic because the function used to load
the program - bpf_program_load_kernel() - emits an error to the log if
BPF is not enabled in the kernel although device controller is not
requested in the configuration. Users could interpret that as a problem.

Make bpf_devices_cgroup_supported() check if the BPF syscall is available
before calling bpf_program_load_kernel(). We can do it by passing a NULL
pointer instead of the syscall argument as the kernel returns either
ENOSYS, when the syscall is not implemented or EFAULT, when it is
implemented.

Signed-off-by: Petr Malat <oss@malat.biz>
2021-07-20 17:51:23 +02:00
Petr Malat
128655e765 lxc_setup_ttys: Handle existing ttyN file without underlying device
If a device file is opened and there isn't the underlying device,
the open call fails with ENXIO, but the path can be opened with
O_PATH, which is enough for mounting over the device file.

Generalize this idea and use O_PATH for all cases when the file
is there. One still must check for both ENXIO and EEXIST as it's
unspecified what error is reported if multiple error conditions
occur at the same time.

Signed-off-by: Petr Malat <oss@malat.biz>
2021-07-20 15:43:24 +02:00
Stoiko Ivanov
eece10d519 cgroups: remove unneeded variables from cgroup_tree_create
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2021-07-20 12:06:27 +02:00
Stoiko Ivanov
60052c3be7 cgroups: populate hierarchy for device cgroup
With the changes introduced in:
b7b1e3a34c
the hierarchy-struct did not have the path_lim set anymore, which is
needed by setup_limits_legacy (->cg_legacy_set_data->lxc_write_openat)
to actually access the cgroup directory.

The issue can be reproduced with a container config having
```
lxc.cgroup.devices.deny = a
```
(or any lxc.cgroup.devices entry) set on a system booted with
systemd.unified_cgroup_hierarchy=0.

This affects all privileged containers on PVE (due to the default
devices.deny entry).

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2021-07-20 12:04:35 +02:00
Stéphane Graber
0a75530661
Merge pull request #3908 from brauner/2021-07-15.fixes.4
terminal: fix error handling
2021-07-15 16:14:07 -04:00
Christian Brauner
7a31655917
terminal: fix error handling
Fixes: f382bcc6d8 ("terminal: log TIOCGPTPEER failure less alarmingly")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 22:09:31 +02:00
Stéphane Graber
8cff10d6a8
Merge pull request #3907 from brauner/2021-07-15.fixes.3
terminal: log TIOCGPTPEER failure less alarmingly
2021-07-15 13:19:26 -04:00
Stéphane Graber
93e2548209
Merge pull request #3906 from brauner/2021-07-15.fixes.2
grammar fixes
2021-07-15 12:48:14 -04:00
Christian Brauner
95103b6095
af_unix: report error when no fd is to be sent
Fixes: #3624
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 18:47:27 +02:00
Christian Brauner
f382bcc6d8
terminal: log TIOCGPTPEER failure less alarmingly
This is not a fatal error and the fallback codepath is equally safe.
When we use TIOCGPTPEER we're using a stashed fd to the container's
devpts mount's ptmx device and allocating a new fd non-path based
through this ioctl. If this ioctl can't be used we're falling back to
allocating a pts device from the host's devpts mount's ptmx device which
is path-based but is not under control of the container and so that's
safe. The difference is just that the first method gets you a nice
native terminal with all the pleasantries of having tty and friends
working whereas the latter method does not.

Fixes: #3625
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 18:37:22 +02:00
Christian Brauner
1d500fed48
sync: fix log message
Fixes: #3875
Suggested-by: Hank.shi <shk242673@163.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 18:18:25 +02:00
Christian Brauner
77093b7ccf
start: fix logging message
Fixes: #3875
Suggested-by: Hank.shi <shk242673@163.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 18:16:39 +02:00
Stéphane Graber
984f5f0bc5
Merge pull request #3905 from brauner/2021-07-15.fixes
initutils: include pthread.h
2021-07-15 08:58:57 -04:00
Christian Brauner
d461a40845
initutils: include pthread.h
Otherwise we might end up with implicit function declaration warnings.

Link: https://jenkins.linuxcontainers.org/job/lxc-build-android/8915/console
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-15 10:37:47 +02:00
Stéphane Graber
b2a311c2df
Merge pull request #3904 from hallyn/2021-07-14/mantypo
doc/common_options: add trace and alert loglevels
2021-07-15 00:47:44 -04:00
Serge Hallyn
44b87e816b doc/common_options: add trace and alert loglevels
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2021-07-14 22:17:40 -05:00
Stéphane Graber
68963becaa
Merge pull request #3900 from brauner/2021-07-08.fixes
file_utils: surface ENOENT when falling back to openat()
2021-07-08 12:10:00 -04:00
Christian Brauner
ebb79ad32a
file_utils: surface ENOENT when falling back to openat()
Link: https://discuss.linuxcontainers.org/t/error-failed-to-retrieve-pid-of-executing-child-process
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-08 14:49:26 +02:00
Edênis Freindorfer Azevedo
35a5efc917
Improve bash completion.
Use as much as possible from each command `--help` for completion.

Some options require a long list of completions that should be dumped by
some command option. These are not added here yet.

Examples of those are: `lxc-info --config`, `lxc-execute --define` and
`lxc-start --define`.

Signed-off-by: Edenis Freindorfer Azevedo <edenisfa@gmail.com>
2021-07-06 22:50:24 -03:00
Edênis Freindorfer Azevedo
7d55228595
Create rules to add/remove symlinks for bash completion.
By default, there is no out-of-the-box bash completion for lxc tools.
This is due to dynamic loading of completions, that requires the
completion filename to be the same as the command (e.g. `lxc-start`
expects a completion filename `lxc-start`). But all commands are in file
`lxc`, which is not read.

Signed-off-by: Edenis Freindorfer Azevedo <edenisfa@gmail.com>
2021-07-06 22:50:24 -03:00
Edênis Freindorfer Azevedo
f8fae86f13
Fix typo on documentation for lxc-{attach,execute}.
According to `[1]`, `lxc-attach` uses `-u,-g` instead of `--u,--g`.
According to `[2]`, `lxc-execute` uses `-u,-g` instead of `--u,--g`.

- [1] https://github.com/lxc/lxc/blob/stable-4.0/src/lxc/tools/lxc_attach.c#L131-L132
- [2] https://github.com/lxc/lxc/blob/stable-4.0/src/lxc/tools/lxc_execute.c#L59-L60

Signed-off-by: Edenis Freindorfer Azevedo <edenisfa@gmail.com>
2021-07-06 22:50:24 -03:00
Edênis Freindorfer Azevedo
98632d6ae0
Fix typo on documentation for lxc-autostart.
According to `[1,2]`, this command has `--groups` instead of `--group`.

- [1] https://github.com/lxc/lxc/blob/stable-4.0/src/lxc/tools/lxc_autostart.c#L64
- [2] https://github.com/lxc/lxc/blob/stable-4.0/src/lxc/tools/lxc_autostart.c#L84

Signed-off-by: Edenis Freindorfer Azevedo <edenisfa@gmail.com>
2021-07-06 22:50:24 -03:00
Christian Brauner
78598e2b30
Merge pull request #3896 from Blub/include-userns-config-dir
RFC: conf: userns.conf: include userns.conf.d
2021-07-05 17:25:24 +02:00
Stéphane Graber
483f5b4f3d
Merge pull request #3897 from brauner/2021-07-05.fixes
lxc-unshare: fixes
2021-07-05 08:49:08 -04:00
Christian Brauner
a1ac26802c
lxc_unshare: fix network device handling
We were passing the wrong PID. Fix this!

Link: https://discuss.linuxcontainers.org/t/problem-with-moving-interface-new-network-namespace-in-lxc-unshare
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-05 12:19:31 +02:00
Christian Brauner
ecd92dffbc
lxc_unshare: make mount table private
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-05 12:11:42 +02:00
Wolfgang Bumiller
dc73e0f0cb confile: allow including nonexisting directories
If an include directive ends with a trailing slash, we now
always assume it is a directory and do not treat the
non-existence as an error.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-07-05 10:53:41 +02:00
Wolfgang Bumiller
9508fc2727 conf: userns.conf: include userns.conf.d
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-07-05 09:02:36 +02:00
Stéphane Graber
b235962c17
Merge pull request #3895 from tenforward/japanese
Update Japanese lxc.container.conf(5)
2021-07-04 23:36:01 -04:00
KATOH Yasufumi
d47d8b6d4d doc: Fix typo in English lxc.container.conf(5)
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2021-07-05 12:00:32 +09:00
KATOH Yasufumi
caf30f2731 doc: Add new idmap= option to Japanese lxc.container.conf(5)
Update for commit 1852be9048

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2021-07-05 11:54:43 +09:00
KATOH Yasufumi
27bf2abc68 doc: Append description of net type field
Update for commit 320061b34f

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2021-07-05 11:23:49 +09:00
KATOH Yasufumi
5793ff9bd2 doc: Add eBPF-based device controller semantics to Japanese man page
Update for commit 5025f3a690

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2021-07-05 11:23:35 +09:00
Stéphane Graber
a0f38dbf0b
Merge pull request #3891 from brauner/2021-07-01.fixes
cgroups: handle funky cgroup layouts
2021-07-01 10:23:24 -04:00
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