Skip to content

Commit c1ed5da

Browse files
committed
apparmor: allow label to carry debug flags
Allow labels to have debug flags that can be used to trigger debug output only from profiles/labels that are marked. This can help reduce debug output by allowing debug to be target to a specific confinement condition. Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 2504db2 commit c1ed5da

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

security/apparmor/include/label.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ enum label_flags {
9292
FLAG_STALE = 0x800, /* replaced/removed */
9393
FLAG_RENAMED = 0x1000, /* label has renaming in it */
9494
FLAG_REVOKED = 0x2000, /* label has revocation in it */
95+
FLAG_DEBUG1 = 0x4000,
96+
FLAG_DEBUG2 = 0x8000,
9597

9698
/* These flags must correspond with PATH_flags */
9799
/* TODO: add new path flags */

security/apparmor/include/path.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ enum path_flags {
1717
PATH_CHROOT_REL = 0x8, /* do path lookup relative to chroot */
1818
PATH_CHROOT_NSCONNECT = 0x10, /* connect paths that are at ns root */
1919

20-
PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */
21-
PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */
20+
PATH_DELEGATE_DELETED = 0x10000, /* delegate deleted files */
21+
PATH_MEDIATE_DELETED = 0x20000, /* mediate deleted paths */
2222
};
2323

2424
int aa_path_name(const struct path *path, int flags, char *buffer,

security/apparmor/include/policy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ extern const char *const aa_profile_mode_names[];
4848

4949
#define PROFILE_IS_HAT(_profile) ((_profile)->label.flags & FLAG_HAT)
5050

51+
#define CHECK_DEBUG1(_profile) ((_profile)->label.flags & FLAG_DEBUG1)
52+
53+
#define CHECK_DEBUG2(_profile) ((_profile)->label.flags & FLAG_DEBUG2)
54+
5155
#define profile_is_stale(_profile) (label_is_stale(&(_profile)->label))
5256

5357
#define on_list_rcu(X) (!list_empty(X) && (X)->prev != LIST_POISON2)

security/apparmor/include/policy_unpack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void aa_load_ent_free(struct aa_load_ent *ent);
2828
struct aa_load_ent *aa_load_ent_alloc(void);
2929

3030
#define PACKED_FLAG_HAT 1
31+
#define PACKED_FLAG_DEBUG1 2
32+
#define PACKED_FLAG_DEBUG2 4
3133

3234
#define PACKED_MODE_ENFORCE 0
3335
#define PACKED_MODE_COMPLAIN 1

security/apparmor/label.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,18 @@ static bool vec_is_stale(struct aa_profile **vec, int n)
197197
return false;
198198
}
199199

200-
static bool vec_unconfined(struct aa_profile **vec, int n)
200+
static long union_vec_flags(struct aa_profile **vec, int n, long mask)
201201
{
202+
long u = 0;
202203
int i;
203204

204205
AA_BUG(!vec);
205206

206207
for (i = 0; i < n; i++) {
207-
if (!profile_unconfined(vec[i]))
208-
return false;
208+
u |= vec[i]->label.flags & mask;
209209
}
210210

211-
return true;
211+
return u;
212212
}
213213

214214
static int sort_cmp(const void *a, const void *b)
@@ -1097,8 +1097,8 @@ static struct aa_label *label_merge_insert(struct aa_label *new,
10971097
else if (k == b->size)
10981098
return aa_get_label(b);
10991099
}
1100-
if (vec_unconfined(new->vec, new->size))
1101-
new->flags |= FLAG_UNCONFINED;
1100+
new->flags |= union_vec_flags(new->vec, new->size, FLAG_UNCONFINED |
1101+
FLAG_DEBUG1 | FLAG_DEBUG2);
11021102
ls = labels_set(new);
11031103
write_lock_irqsave(&ls->lock, flags);
11041104
label = __label_insert(labels_set(new), new, false);

security/apparmor/policy_unpack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
748748
goto fail;
749749
if (tmp & PACKED_FLAG_HAT)
750750
profile->label.flags |= FLAG_HAT;
751+
if (tmp & PACKED_FLAG_DEBUG1)
752+
profile->label.flags |= FLAG_DEBUG1;
753+
if (tmp & PACKED_FLAG_DEBUG2)
754+
profile->label.flags |= FLAG_DEBUG2;
751755
if (!unpack_u32(e, &tmp, NULL))
752756
goto fail;
753757
if (tmp == PACKED_MODE_COMPLAIN || (e->version & FORCE_COMPLAIN_FLAG)) {

0 commit comments

Comments
 (0)