Skip to content

Commit b89ed0a

Browse files
apparmor: skip /proc and /sys restrictions if nesting is enabled
If nesting is enabled, it's already possible to mount your own instance of both procfs and sysfs inside the container, so protecting the "original" ones at /proc and /sys makes no sense, but breaks certain nested container setups. See: lxc/incus@1fbe4bf Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
1 parent 8dd8072 commit b89ed0a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/lxc/lsm/apparmor.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ static const char AA_PROFILE_BASE[] =
170170
" mount options=(rw,move) /s[^y]*{,/**},\n"
171171
" mount options=(rw,move) /sy[^s]*{,/**},\n"
172172
" mount options=(rw,move) /sys?*{,/**},\n"
173+
"\n";
174+
175+
static const char AA_PROFILE_BASE_NO_NESTING[] =
173176
"\n"
174177
" # generated by: lxc-generate-aa-rules.py container-rules.base\n"
175178
" deny /proc/sys/[^kn]*{,/**} wklx,\n"
@@ -755,6 +758,10 @@ static char *get_apparmor_profile_content(struct lsm_ops *ops, struct lxc_conf *
755758
must_append_sized(&profile, &size, AA_PROFILE_BASE,
756759
STRARRAYLEN(AA_PROFILE_BASE));
757760

761+
if (!conf->lsm_aa_allow_nesting)
762+
must_append_sized(&profile, &size, AA_PROFILE_BASE_NO_NESTING,
763+
STRARRAYLEN(AA_PROFILE_BASE_NO_NESTING));
764+
758765
append_all_remount_rules(&profile, &size);
759766

760767
if (ops->aa_supports_unix)
@@ -768,8 +775,10 @@ static char *get_apparmor_profile_content(struct lsm_ops *ops, struct lxc_conf *
768775
if (ops->aa_can_stack && !ops->aa_is_stacked) {
769776
char *namespace, *temp;
770777

771-
must_append_sized(&profile, &size, AA_PROFILE_STACKING_BASE,
772-
STRARRAYLEN(AA_PROFILE_STACKING_BASE));
778+
779+
if (!conf->lsm_aa_allow_nesting)
780+
must_append_sized(&profile, &size, AA_PROFILE_STACKING_BASE,
781+
STRARRAYLEN(AA_PROFILE_STACKING_BASE));
773782

774783
namespace = apparmor_namespace(conf->name, lxcpath);
775784
temp = must_concat(NULL, " change_profile -> \":", namespace, ":*\",\n"
@@ -779,7 +788,7 @@ static char *get_apparmor_profile_content(struct lsm_ops *ops, struct lxc_conf *
779788

780789
must_append_sized(&profile, &size, temp, strlen(temp));
781790
free(temp);
782-
} else {
791+
} else if (!conf->lsm_aa_allow_nesting) {
783792
must_append_sized(&profile, &size, AA_PROFILE_NO_STACKING,
784793
STRARRAYLEN(AA_PROFILE_NO_STACKING));
785794
}

0 commit comments

Comments
 (0)