Skip to content

Commit ad5ff3d

Browse files
committed
AppArmor: Add ability to load extended policy
Add the base support for the new policy extensions. This does not bring any additional functionality, or change current semantics. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Kees Cook <kees@ubuntu.com>
1 parent 57fa1e1 commit ad5ff3d

4 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎security/apparmor/include/apparmor.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
#include "match.h"
2121

22+
/*
23+
* Class of mediation types in the AppArmor policy db
24+
*/
25+
#define AA_CLASS_ENTRY 0
26+
#define AA_CLASS_UNKNOWN 1
27+
#define AA_CLASS_FILE 2
28+
#define AA_CLASS_CAP 3
29+
#define AA_CLASS_NET 4
30+
#define AA_CLASS_RLIMITS 5
31+
#define AA_CLASS_DOMAIN 6
32+
33+
#define AA_CLASS_LAST AA_CLASS_DOMAIN
34+
2235
/* Control parameters settable through module/boot flags */
2336
extern enum audit_mode aa_g_audit;
2437
extern bool aa_g_audit_header;

‎security/apparmor/include/policy.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ struct aa_namespace {
129129
struct list_head sub_ns;
130130
};
131131

132+
/* struct aa_policydb - match engine for a policy
133+
* dfa: dfa pattern match
134+
* start: set of start states for the different classes of data
135+
*/
136+
struct aa_policydb {
137+
/* Generic policy DFA specific rule types will be subsections of it */
138+
struct aa_dfa *dfa;
139+
unsigned int start[AA_CLASS_LAST + 1];
140+
141+
};
142+
132143
/* struct aa_profile - basic confinement data
133144
* @base - base components of the profile (name, refcount, lists, lock ...)
134145
* @parent: parent of profile
@@ -143,6 +154,7 @@ struct aa_namespace {
143154
* @flags: flags controlling profile behavior
144155
* @path_flags: flags controlling path generation behavior
145156
* @size: the memory consumed by this profiles rules
157+
* @policy: general match rules governing policy
146158
* @file: The set of rules governing basic file access and domain transitions
147159
* @caps: capabilities for the profile
148160
* @rlimits: rlimits for the profile
@@ -179,6 +191,7 @@ struct aa_profile {
179191
u32 path_flags;
180192
int size;
181193

194+
struct aa_policydb policy;
182195
struct aa_file_rules file;
183196
struct aa_caps caps;
184197
struct aa_rlimit rlimits;

‎security/apparmor/policy.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ static void free_profile(struct aa_profile *profile)
749749

750750
aa_free_sid(profile->sid);
751751
aa_put_dfa(profile->xmatch);
752+
aa_put_dfa(profile->policy.dfa);
752753

753754
aa_put_profile(profile->replacedby);
754755

‎security/apparmor/policy_unpack.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e)
469469
{
470470
struct aa_profile *profile = NULL;
471471
const char *name = NULL;
472-
int error = -EPROTO;
472+
int i, error = -EPROTO;
473473
kernel_cap_t tmpcap;
474474
u32 tmp;
475475

@@ -562,6 +562,28 @@ static struct aa_profile *unpack_profile(struct aa_ext *e)
562562
if (!unpack_rlimits(e, profile))
563563
goto fail;
564564

565+
if (unpack_nameX(e, AA_STRUCT, "policydb")) {
566+
/* generic policy dfa - optional and may be NULL */
567+
profile->policy.dfa = unpack_dfa(e);
568+
if (IS_ERR(profile->policy.dfa)) {
569+
error = PTR_ERR(profile->policy.dfa);
570+
profile->policy.dfa = NULL;
571+
goto fail;
572+
}
573+
if (!unpack_u32(e, &profile->policy.start[0], "start"))
574+
/* default start state */
575+
profile->policy.start[0] = DFA_START;
576+
/* setup class index */
577+
for (i = AA_CLASS_FILE; i <= AA_CLASS_LAST; i++) {
578+
profile->policy.start[i] =
579+
aa_dfa_next(profile->policy.dfa,
580+
profile->policy.start[0],
581+
i);
582+
}
583+
if (!unpack_nameX(e, AA_STRUCTEND, NULL))
584+
goto fail;
585+
}
586+
565587
/* get file rules */
566588
profile->file.dfa = unpack_dfa(e);
567589
if (IS_ERR(profile->file.dfa)) {

0 commit comments

Comments
 (0)