Skip to content

Commit 524d8e1

Browse files
committed
apparmor: disable showing the mode as part of a secid to secctx
Displaying the mode as part of the seectx takes up unnecessary memory, makes it so we can't use refcounted secctx so we need to alloc/free on every conversion from secid to secctx and introduces a space that could be potentially mishandled by tooling. Eg. In an audit record we get subj_type=firefix (enforce) Having the mode reported is not necessary, and might even be confusing eg. when writing an audit rule to match the above record field you would use -F subj_type=firefox ie. the mode is not included. AppArmor provides ways to find the mode without reporting as part of the secctx. So disable this by default before its use is wide spread and we can't. For now we add a sysctl to control the behavior as we can't guarantee no one is using this. Acked-by: Andrea Righi <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent df43909 commit 524d8e1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

security/apparmor/include/secid.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct aa_label;
2121
/* secid value that matches any other secid */
2222
#define AA_SECID_WILDCARD 1
2323

24+
/* sysctl to enable displaying mode when converting secid to secctx */
25+
extern int apparmor_display_secid_mode;
26+
2427
struct aa_label *aa_secid_to_label(u32 secid);
2528
int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
2629
int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);

security/apparmor/lsm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,14 @@ static struct ctl_table apparmor_sysctl_table[] = {
17641764
.mode = 0600,
17651765
.proc_handler = apparmor_dointvec,
17661766
},
1767+
{
1768+
.procname = "apparmor_display_secid_mode",
1769+
.data = &apparmor_display_secid_mode,
1770+
.maxlen = sizeof(int),
1771+
.mode = 0600,
1772+
.proc_handler = apparmor_dointvec,
1773+
},
1774+
17671775
{ }
17681776
};
17691777

security/apparmor/secid.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
static DEFINE_XARRAY_FLAGS(aa_secids, XA_FLAGS_LOCK_IRQ | XA_FLAGS_TRACK_FREE);
3333

34+
int apparmor_display_secid_mode;
35+
3436
/*
3537
* TODO: allow policy to reserve a secid range?
3638
* TODO: add secid pinning
@@ -64,22 +66,23 @@ int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
6466
{
6567
/* TODO: cache secctx and ref count so we don't have to recreate */
6668
struct aa_label *label = aa_secid_to_label(secid);
69+
int flags = FLAG_VIEW_SUBNS | FLAG_HIDDEN_UNCONFINED | FLAG_ABS_ROOT;
6770
int len;
6871

6972
AA_BUG(!seclen);
7073

7174
if (!label)
7275
return -EINVAL;
7376

77+
if (apparmor_display_secid_mode)
78+
flags |= FLAG_SHOW_MODE;
79+
7480
if (secdata)
7581
len = aa_label_asxprint(secdata, root_ns, label,
76-
FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
77-
FLAG_HIDDEN_UNCONFINED | FLAG_ABS_ROOT,
78-
GFP_ATOMIC);
82+
flags, GFP_ATOMIC);
7983
else
80-
len = aa_label_snxprint(NULL, 0, root_ns, label,
81-
FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
82-
FLAG_HIDDEN_UNCONFINED | FLAG_ABS_ROOT);
84+
len = aa_label_snxprint(NULL, 0, root_ns, label, flags);
85+
8386
if (len < 0)
8487
return -ENOMEM;
8588

0 commit comments

Comments
 (0)