Skip to content

Commit 0bece4f

Browse files
committed
apparmor: make sure perm indexes are accumulated
accumulate permission indexes on a first encountered basis. This favors original rulesets so that new ones can not override without profile replacement. Signed-off-by: John Johansen <[email protected]>
1 parent 670f317 commit 0bece4f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

security/apparmor/include/file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ static inline struct aa_label *aa_get_file_label(struct aa_file_ctx *ctx)
8888
* - exec type - which determines how the executable name and index are used
8989
* - flags - which modify how the destination name is applied
9090
*/
91-
#define AA_X_INDEX_MASK 0x00ffffff
91+
#define AA_X_INDEX_MASK AA_INDEX_MASK
9292

9393
#define AA_X_TYPE_MASK 0x0c000000
94-
#define AA_X_NONE 0x00000000
94+
#define AA_X_NONE AA_INDEX_NONE
9595
#define AA_X_NAME 0x04000000 /* use executable name px */
9696
#define AA_X_TABLE 0x08000000 /* use a specified name ->n# */
9797

security/apparmor/include/perms.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ struct aa_perms {
7878
u32 quiet; /* set only when ~allow | deny */
7979
u32 hide; /* set only when ~allow | deny */
8080

81+
8182
u32 xindex;
8283
u32 tag; /* tag string index, if present */
8384
u32 label; /* label string index, if present */
8485
};
8586

87+
/*
88+
* Indexes are broken into a 24 bit index and 8 bit flag.
89+
* For the index to be valid there must be a value in the flag
90+
*/
91+
#define AA_INDEX_MASK 0x00ffffff
92+
#define AA_INDEX_FLAG_MASK 0xff000000
93+
#define AA_INDEX_NONE 0
94+
8695
#define ALL_PERMS_MASK 0xffffffff
8796
extern struct aa_perms nullperms;
8897
extern struct aa_perms allperms;

security/apparmor/lib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ void aa_perms_accum_raw(struct aa_perms *accum, struct aa_perms *addend)
348348
accum->hide &= addend->hide & ~addend->allow;
349349
accum->prompt |= addend->prompt & ~addend->allow & ~addend->deny;
350350
accum->subtree |= addend->subtree & ~addend->deny;
351+
352+
if (!accum->xindex)
353+
accum->xindex = addend->xindex;
354+
if (!accum->tag)
355+
accum->tag = addend->tag;
356+
if (!accum->label)
357+
accum->label = addend->label;
351358
}
352359

353360
/**
@@ -367,6 +374,13 @@ void aa_perms_accum(struct aa_perms *accum, struct aa_perms *addend)
367374
accum->hide &= addend->hide & ~accum->allow;
368375
accum->prompt |= addend->prompt & ~accum->allow & ~accum->deny;
369376
accum->subtree &= addend->subtree & ~accum->deny;
377+
378+
if (!accum->xindex)
379+
accum->xindex = addend->xindex;
380+
if (!accum->tag)
381+
accum->tag = addend->tag;
382+
if (!accum->label)
383+
accum->label = addend->label;
370384
}
371385

372386
void aa_profile_match_label(struct aa_profile *profile, struct aa_label *label,

0 commit comments

Comments
 (0)