Skip to content

Commit d5beb15

Browse files
committed
Revert "re-add onexec for apparmor, move label assumption until after container has been setup for attach"
This reverts commit 50dee37. Fixes: lxc#4553 Bisected-by: Simon Deziel <simon.deziel@canonical.com> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent f0e0c9a commit d5beb15

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

src/lxc/attach.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,19 @@ __noreturn static void do_attach(struct attach_payload *ap)
12611261
if (!lxc_switch_uid_gid(ctx->setup_ns_uid, ctx->setup_ns_gid))
12621262
goto on_error;
12631263

1264+
if (attach_lsm(options) && ctx->lsm_label) {
1265+
bool on_exec;
1266+
1267+
/* Change into our new LSM profile. */
1268+
on_exec = options->attach_flags & LXC_ATTACH_LSM_EXEC ? true : false;
1269+
ret = ctx->lsm_ops->process_label_set_at(ctx->lsm_ops, fd_lsm, ctx->lsm_label, on_exec);
1270+
close_prot_errno_disarm(fd_lsm);
1271+
if (ret < 0)
1272+
goto on_error;
1273+
1274+
TRACE("Set %s LSM label to \"%s\"", ctx->lsm_ops->name, ctx->lsm_label);
1275+
}
1276+
12641277
if (conf->no_new_privs || (options->attach_flags & LXC_ATTACH_NO_NEW_PRIVS)) {
12651278
ret = prctl(PR_SET_NO_NEW_PRIVS, prctl_arg(1), prctl_arg(0),
12661279
prctl_arg(0), prctl_arg(0));
@@ -1354,19 +1367,6 @@ __noreturn static void do_attach(struct attach_payload *ap)
13541367
if (!lxc_switch_uid_gid(ctx->target_ns_uid, ctx->target_ns_gid))
13551368
goto on_error;
13561369

1357-
if (attach_lsm(options) && ctx->lsm_label) {
1358-
bool on_exec;
1359-
1360-
/* Change into our new LSM profile. */
1361-
on_exec = options->attach_flags & LXC_ATTACH_LSM_EXEC ? true : false;
1362-
ret = ctx->lsm_ops->process_label_set_at(ctx->lsm_ops, fd_lsm, ctx->lsm_label, on_exec);
1363-
close_prot_errno_disarm(fd_lsm);
1364-
if (ret < 0)
1365-
goto on_error;
1366-
1367-
TRACE("Set %s LSM label to \"%s\"", ctx->lsm_ops->name, ctx->lsm_label);
1368-
}
1369-
13701370
put_attach_payload(ap);
13711371

13721372
/* We're done, so we can now do whatever the user intended us to do. */

src/lxc/lsm/apparmor.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <errno.h>
66
#include <stdio.h>
77
#include <stdlib.h>
8-
#include <sys/apparmor.h>
98
#include <sys/mount.h>
109
#include <sys/stat.h>
1110
#include <sys/types.h>
@@ -1213,17 +1212,15 @@ static int apparmor_process_label_set(struct lsm_ops *ops, const char *inlabel,
12131212
if (strequal(label, "unconfined") && apparmor_am_unconfined(ops))
12141213
return log_info(0, "AppArmor profile unchanged");
12151214

1216-
if (on_exec) {
1217-
ret = aa_change_onexec(label);
1218-
} else {
1219-
ret = aa_change_profile(label);
1220-
}
1221-
1222-
if (ret < 0)
1223-
return log_error_errno(-1, errno, "Failed to set AppArmor%s context to \"%s\"",
1224-
on_exec ? " exec" : "", label);
1225-
1226-
return log_info(0, "Changed AppArmor%s profile to \"%s\"", on_exec ? " exec" : "", label);
1215+
label_fd = apparmor_process_label_fd_get(ops, lxc_raw_gettid(), on_exec);
1216+
if (label_fd < 0)
1217+
return log_error_errno(-EINVAL, EINVAL, "Failed to change AppArmor profile to %s", label);
1218+
1219+
ret = apparmor_process_label_set_at(ops, label_fd, label, on_exec);
1220+
if (ret < 0)
1221+
return log_error_errno(-EINVAL, EINVAL, "Failed to change AppArmor profile to %s", label);
1222+
1223+
return log_info(0, "Changed AppArmor profile to %s", label);
12271224
}
12281225

12291226
static struct lsm_ops apparmor_ops = {

0 commit comments

Comments
 (0)