Skip to content

Commit 2d9da9b

Browse files
committed
apparmor: allow restricting unprivileged change_profile
unprivileged unconfined can use change_profile to alter the confinement set by the mac admin. Allow restricting unprivileged unconfined by still allowing change_profile but stacking the change against unconfined. This allows unconfined to still apply system policy but allows the task to enter the new confinement. If unprivileged unconfined is required a sysctl is provided to switch to the previous behavior. Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent e105d80 commit 2d9da9b

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

security/apparmor/apparmorfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,11 @@ static struct aa_sfs_entry aa_sfs_entry_domain[] = {
23412341
{ }
23422342
};
23432343

2344+
static struct aa_sfs_entry aa_sfs_entry_unconfined[] = {
2345+
AA_SFS_FILE_BOOLEAN("change_profile", 1),
2346+
{ }
2347+
};
2348+
23442349
static struct aa_sfs_entry aa_sfs_entry_versions[] = {
23452350
AA_SFS_FILE_BOOLEAN("v5", 1),
23462351
AA_SFS_FILE_BOOLEAN("v6", 1),
@@ -2358,6 +2363,7 @@ static struct aa_sfs_entry aa_sfs_entry_policy[] = {
23582363
AA_SFS_FILE_U64("outofband", MAX_OOB_SUPPORTED),
23592364
AA_SFS_FILE_U64("permstable32_version", 1),
23602365
AA_SFS_FILE_STRING("permstable32", PERMS32STR),
2366+
AA_SFS_DIR("unconfined_restrictions", aa_sfs_entry_unconfined),
23612367
{ }
23622368
};
23632369

security/apparmor/domain.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ static int change_profile_perms_wrapper(const char *op, const char *name,
13111311
return error;
13121312
}
13131313

1314+
const char *stack_msg = "change_profile unprivileged unconfined converted to stacking";
1315+
13141316
/**
13151317
* aa_change_profile - perform a one-way profile transition
13161318
* @fqname: name of profile may include namespace (NOT NULL)
@@ -1370,6 +1372,28 @@ int aa_change_profile(const char *fqname, int flags)
13701372
op = OP_CHANGE_PROFILE;
13711373
}
13721374

1375+
/* This should move to a per profile test. Requires pushing build
1376+
* into callback
1377+
*/
1378+
if (!stack && unconfined(label) &&
1379+
label == &labels_ns(label)->unconfined->label &&
1380+
aa_unprivileged_unconfined_restricted &&
1381+
/* TODO: refactor so this check is a fn */
1382+
cap_capable(current_cred(), &init_user_ns, CAP_MAC_OVERRIDE,
1383+
CAP_OPT_NOAUDIT)) {
1384+
/* regardless of the request in this case apparmor
1385+
* stacks against unconfined so admin set policy can't be
1386+
* by-passed
1387+
*/
1388+
stack = true;
1389+
perms.audit = request;
1390+
(void) fn_for_each_in_ns(label, profile,
1391+
aa_audit_file(subj_cred, profile, &perms, op,
1392+
request, auditname, NULL, target,
1393+
GLOBAL_ROOT_UID, stack_msg, 0));
1394+
perms.audit = 0;
1395+
}
1396+
13731397
if (*fqname == '&') {
13741398
stack = true;
13751399
/* don't have label_parse() do stacking */

security/apparmor/include/policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
struct aa_ns;
3535

3636
extern int unprivileged_userns_apparmor_policy;
37+
extern int aa_unprivileged_unconfined_restricted;
3738

3839
extern const char *const aa_profile_mode_names[];
3940
#define APPARMOR_MODE_NAMES_MAX_INDEX 4

security/apparmor/lsm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,13 @@ static struct ctl_table apparmor_sysctl_table[] = {
17981798
.mode = 0600,
17991799
.proc_handler = apparmor_dointvec,
18001800
},
1801+
{
1802+
.procname = "apparmor_restrict_unprivileged_unconfined",
1803+
.data = &aa_unprivileged_unconfined_restricted,
1804+
.maxlen = sizeof(int),
1805+
.mode = 0600,
1806+
.proc_handler = apparmor_dointvec,
1807+
},
18011808

18021809
{ }
18031810
};

security/apparmor/policy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#include "include/resource.h"
8989

9090
int unprivileged_userns_apparmor_policy = 1;
91+
int aa_unprivileged_unconfined_restricted;
9192

9293
const char *const aa_profile_mode_names[] = {
9394
"enforce",

0 commit comments

Comments
 (0)