]> git.proxmox.com Git - mirror_lxc.git/commit
apparmor: prefer /proc/.../attr/apparmor/current over legacy interface
authorAleksa Sarai <cyphar@cyphar.com>
Fri, 19 Feb 2021 09:45:37 +0000 (20:45 +1100)
committerAleksa Sarai <cyphar@cyphar.com>
Fri, 19 Feb 2021 09:53:50 +0000 (20:53 +1100)
commit47f4914d88dfb8d8b2207c955c37af347032444d
tree3edf27e75a44502f31c533081c57cda820b04cea
parent301a5f8e786c61fb3dcc107a9ae18ae507857895
apparmor: prefer /proc/.../attr/apparmor/current over legacy interface

It turns out that since Linux 5.1 there are now per-LSM subdirectories
for major LSMs, which users are recommended to use over the "legacy"
top-level /proc/$pid/attr/... files[1]:

> Process attributes associated with “major” security modules should be
> accessed and maintained using the special files in /proc/.../attr. A
> security module may maintain a module specific subdirectory there,
> named after the module. /proc/.../attr/smack is provided by the Smack
> security module and contains all its special files. The files directly
> in /proc/.../attr remain as legacy interfaces for modules that provide
> subdirectories.

AppArmor has had such a directory since Linux 5.8[2], and it turns out
that with certain CONFIG_LSM configurations you can end up with AppArmor
files not being accessible from the legacy interface. Arch Linux
recently added BPF as one of the enabled LSM in their configuration, and
this broke runc[3] and LXC.

The solution is to first try to use /proc/$pid/attr/apparmor/current and
fall back to /proc/$pid/attr/current if the former is not available.

[1]: https://www.kernel.org/doc/html/latest/admin-guide/LSM/index.html
[2]: Linux 5.8 ; commit 6413f852ce08 ("apparmor: add proc subdir to attrs")
[3]: https://github.com/opencontainers/runc/issues/2801

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
src/lxc/lsm/apparmor.c
src/lxc/macro.h