Commit Graph

10927 Commits

Author SHA1 Message Date
Christian Brauner
c7a1f72aca
cgroups: handle lxc.cgroup.use global parameter
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:33:43 +01:00
Christian Brauner
b8a4fe1282
cgroups: fix cg_legacy_freeze() return type
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:33:43 +01:00
Christian Brauner
2e85effb00
file_utils: tweak lxc_write_openat()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:33:43 +01:00
Christian Brauner
ca72ccb50f
cgroups: improve utility controller handling
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:32:56 +01:00
Christian Brauner
042f9e9c75
cgroups: s/cgroup2_chown/delegate/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:18:28 +01:00
Christian Brauner
4cd3a76456
cgroups: move cgroup2 parameters into substruct
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 14:15:18 +01:00
Christian Brauner
b1b1a60f16
cgroups: s/container_limit_path/path_lim/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:26:30 +01:00
Christian Brauner
67ed60ce6b
cgroups: s/container_full_path/path_con/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:26:29 +01:00
Christian Brauner
c0af7b1c96
cgroups: s/cgfd_limit/dfd_lim/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:41 +01:00
Christian Brauner
6a32c81772
cgroups: s/cgfd_mon/dfd_mon/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:41 +01:00
Christian Brauner
e33870e511
cgroups: s/cgfd_con/dfd_con/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:41 +01:00
Christian Brauner
a58be2ad8b
cgroups: s/mountpoint/at_mnt/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:41 +01:00
Christian Brauner
44585f1a90
cgroups: s/container_base_path/at_base/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:41 +01:00
Christian Brauner
e18e905394
cgroups: rename cgroupfs mount fd
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 11:25:38 +01:00
Christian Brauner
a9db9474ae
cgroups: simplify and fix mounting on non-cgroup namespace aware kernels
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 01:40:11 +01:00
Christian Brauner
b8572e8c2f
cgroups: introduce cgroup hierarchy type
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 01:28:45 +01:00
Christian Brauner
e821c3b74a
cgroups: remove unused helpers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 01:25:49 +01:00
Christian Brauner
179754a25e
cgroups: s/add_hierarchy()/cgroup_hierarchy_add()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 01:09:33 +01:00
Christian Brauner
0da35ac723
cgroups: split delegation checks into separate helpers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 01:07:12 +01:00
Christian Brauner
63ba9eafcf
cgroups: simplify string list handling
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 00:46:23 +01:00
Christian Brauner
35ec1a385a
cgroups: rework cgroup initialization
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-21 00:18:09 +01:00
Christian Brauner
0e3af26b2f
cgroups: split out unified cgroup helpers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 03:17:47 +01:00
Christian Brauner
6407ddf4da
memory_utils: adapt to new pointer error macros
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 03:17:46 +01:00
Christian Brauner
844d929d2e
macro: add pointer error encoding support
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 01:36:00 +01:00
Christian Brauner
45069107aa
compiler: add likely() and unlikely() support
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 01:33:23 +01:00
Christian Brauner
0eb3b1ceed
cgroups: s/basecginfo/cgroup_info/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 01:10:53 +01:00
Christian Brauner
8033666ce2
cgroups: simplify current cgroup retrieval on pure unified cgroup layouts
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 01:07:43 +01:00
Christian Brauner
a96be3c335
cgroups: tweak return values
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 00:49:25 +01:00
Christian Brauner
0fbf99d600
cgroups: tweak lxc.cgroup.use handling in __cgroup_init()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 00:43:43 +01:00
Christian Brauner
7a0c8ed32c
cgroups: s/must_copy_string()/strdup()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 00:40:32 +01:00
Christian Brauner
0d83967fa3
cgroups: avoid additional variable for single access
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-20 00:38:57 +01:00
Christian Brauner
37ac0b481d
cgroups: fix prune_init_scope()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 18:25:30 +01:00
Christian Brauner
d9be3d2694
string_utils: move lxc_iterate_parts()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 18:09:13 +01:00
Stéphane Graber
c33840f6f9
Merge pull request #3684 from brauner/2021-02-18/fixes_2
bpf: device cgroup improvements
2021-02-19 12:04:56 -05:00
Stéphane Graber
02882d8358
Merge pull request #3687 from brauner/2021-02-19/fixes
lsm: fixes
2021-02-19 11:58:43 -05:00
Christian Brauner
54dbe498b9
doc: tweak cgroup headline
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:29 +01:00
Christian Brauner
5025f3a690
doc: epxlain eBPF-based device controller semantics
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:29 +01:00
Christian Brauner
e9b3d28df4
doc: add missing ".[controller file] suffix to lxc.cgroup{2}. key explanations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:27 +01:00
Christian Brauner
0ede37250c
bpf: update device cgroup semantics
LXC has supported the bpf device controlller for a while now. A bpf device
program can be attached to the container's cgroup if this is a pure cgroup2
host.

The format for specifying device rules for the cgroup2 bpf device controller is
the same as for the legacy cgroup device controller; only the configuration key
prefix has to change. Specifically, device rules for the legacy cgroup device
controller are specified by via lxc.cgroup.devices.{allow,deny} whereas for the
cgroup2 bpf device controller lxc.cgroup2.devices.{allow,deny} must be used.

The following semantics apply:
1. The device rule "lxc.cgroup2.devices.deny = a" will cause LXC to instruct
   the kernel to block access to all devices by default. To grant access to
   devices "allow device rules" must be added via the
   "lxc.cgroup2.devices.allow" key. This is referred to as a "allowlist" device
   program.
2. The device rule "lxc.cgroup2.devices.allow = a" will cause LXC to instruct
   the kernel to allow access to all devices by default. To deny access to
   devices "deny device rules" must be added via "lxc.cgroup2.devices.deny"
   key. This is referred to as a "denylist" device program.
3. Specifying a rule as explained in 1. or 2. will cause all previous rules to
   be cleared, i.e. the device list will be reset.

For example the set of rules:

lxc.cgroup2.devices.deny = a
lxc.cgroup2.devices.allow = c *:* m
lxc.cgroup2.devices.allow = b *:* m
lxc.cgroup2.devices.allow = c 1:3 rwm

implements a "allowlist" device program, i.e. the kernel will block access to
all devices not specifically allowed in this list. This particular program
states that all character and block devices might be created but only /dev/null
might be read or written.

If we to switch to the set of rules to:

lxc.cgroup2.devices.allow = a
lxc.cgroup2.devices.deny = c *:* m
lxc.cgroup2.devices.deny = b *:* m
lxc.cgroup2.devices.deny = c 1:3 rwm

then LXC would instruct the kernel to implement a "denylist", i.e. the kernel
will allow access to all devices not specifically denied in this list. This
particular program states that no character devices or block devices might be
created and that /dev/null is not allow allowed to be read, written, or
created.

Consider the same program but followed by a rule as explained in 1. or 2.:

lxc.cgroup2.devices.allow = a
lxc.cgroup2.devices.deny = c *:* m
lxc.cgroup2.devices.deny = b *:* m
lxc.cgroup2.devices.deny = c 1:3 rwm
lxc.cgroup2.devices.allow = a

The last line will cause LXC to reset the device list without changing the type
of device program.

lxc.cgroup2.devices.allow = a
lxc.cgroup2.devices.deny = c *:* m
lxc.cgroup2.devices.deny = b *:* m
lxc.cgroup2.devices.deny = c 1:3 rwm
lxc.cgroup2.devices.deny = a

The last line will cause LXC to reset the device list and switch from a
"allowlist" program to a "denylist" program.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
30bfbd3ff1
cgroups: tweak bpf_device_cgroup_prepare()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
a7744f125e
conf: expose lxc_clear_cgroup2_devices()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
d6c06927df
conf: improve lxc_clear_cgroups()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
159702774c
bpf: fix typos
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
a0f0e9df1d
bpf: comment bpf_cgroup_devices_update()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
60532b18f4
commands: only update bpf device program if really needed
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
a134099de5
cgroups: make device cgroup handling smarter and simpler
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:26 +01:00
Christian Brauner
fc4612cb39
cgroups: ensure no garbage is returned
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 15:23:25 +01:00
Christian Brauner
ba9055c96b
lsm: twek apparmor_process_label_get()
Fixes: Coverity 1473189
Fixes: Coverity 1473190
Fixes: 47f4914d88 ("apparmor: prefer /proc/.../attr/apparmor/current over legacy interface")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 14:40:58 +01:00
Christian Brauner
8b145a8778
file_utils: allow fd_to_buf() to fail for real
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-02-19 14:32:36 +01:00
Christian Brauner
f43ed6a0ab
Merge pull request #3686 from cyphar/apparmor-attr-subdir
apparmor: prefer /proc/.../attr/apparmor/current over legacy interface
2021-02-19 13:15:31 +01:00