Commit e844fe9b authored by John Johansen's avatar John Johansen

apparmor: convert policy lookup to use accept as an index

Remap polidydb dfa accept table from embedded perms to an index, and
then move the perm lookup to use the accept entry as an index into the
perm table. This is done so that the perm table can be separated from
the dfa, allowing dfa accept to index to share expanded permission
sets.
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent bf690f59
...@@ -634,7 +634,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms, ...@@ -634,7 +634,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms,
state = aa_dfa_match_len(dfa, profile->policy.start[0], state = aa_dfa_match_len(dfa, profile->policy.start[0],
match_str, match_len); match_str, match_len);
if (state) if (state)
tmp = *aa_lookup_perms(profile->policy.perms, state); tmp = *aa_lookup_perms(&profile->policy, state);
} }
aa_apply_modes_to_perms(profile, &tmp); aa_apply_modes_to_perms(profile, &tmp);
aa_perms_accum_raw(perms, &tmp); aa_perms_accum_raw(perms, &tmp);
......
...@@ -132,14 +132,6 @@ extern struct aa_perms allperms; ...@@ -132,14 +132,6 @@ extern struct aa_perms allperms;
extern struct aa_perms default_perms; extern struct aa_perms default_perms;
static inline struct aa_perms *aa_lookup_perms(struct aa_perms *perms,
unsigned int state)
{
if (!(perms))
return &default_perms;
return &(perms[state]);
}
void aa_perm_mask_to_str(char *str, size_t str_size, const char *chrs, void aa_perm_mask_to_str(char *str, size_t str_size, const char *chrs,
u32 mask); u32 mask);
......
...@@ -90,6 +90,18 @@ static inline void aa_destroy_policydb(struct aa_policydb *policy) ...@@ -90,6 +90,18 @@ static inline void aa_destroy_policydb(struct aa_policydb *policy)
} }
static inline struct aa_perms *aa_lookup_perms(struct aa_policydb *policy,
unsigned int state)
{
unsigned int index = ACCEPT_TABLE(policy->dfa)[state];
if (!(policy->perms))
return &default_perms;
return &(policy->perms[index]);
}
/* struct aa_data - generic data structure /* struct aa_data - generic data structure
* key: name for retrieving this data * key: name for retrieving this data
* size: size of data in bytes * size: size of data in bytes
......
...@@ -1328,7 +1328,7 @@ static int label_compound_match(struct aa_profile *profile, ...@@ -1328,7 +1328,7 @@ static int label_compound_match(struct aa_profile *profile,
if (!state) if (!state)
goto fail; goto fail;
} }
*perms = *aa_lookup_perms(profile->policy.perms, state); *perms = *aa_lookup_perms(&profile->policy, state);
aa_apply_modes_to_perms(profile, perms); aa_apply_modes_to_perms(profile, perms);
if ((perms->allow & request) != request) if ((perms->allow & request) != request)
return -EACCES; return -EACCES;
...@@ -1379,7 +1379,7 @@ static int label_components_match(struct aa_profile *profile, ...@@ -1379,7 +1379,7 @@ static int label_components_match(struct aa_profile *profile,
return 0; return 0;
next: next:
tmp = *aa_lookup_perms(profile->policy.perms, state); tmp = *aa_lookup_perms(&profile->policy, state);
aa_apply_modes_to_perms(profile, &tmp); aa_apply_modes_to_perms(profile, &tmp);
aa_perms_accum(perms, &tmp); aa_perms_accum(perms, &tmp);
label_for_each_cont(i, label, tp) { label_for_each_cont(i, label, tp) {
...@@ -1388,7 +1388,7 @@ static int label_components_match(struct aa_profile *profile, ...@@ -1388,7 +1388,7 @@ static int label_components_match(struct aa_profile *profile,
state = match_component(profile, tp, start); state = match_component(profile, tp, start);
if (!state) if (!state)
goto fail; goto fail;
tmp = *aa_lookup_perms(profile->policy.perms, state); tmp = *aa_lookup_perms(&profile->policy, state);
aa_apply_modes_to_perms(profile, &tmp); aa_apply_modes_to_perms(profile, &tmp);
aa_perms_accum(perms, &tmp); aa_perms_accum(perms, &tmp);
} }
......
...@@ -249,7 +249,7 @@ static int do_match_mnt(struct aa_policydb *policy, unsigned int start, ...@@ -249,7 +249,7 @@ static int do_match_mnt(struct aa_policydb *policy, unsigned int start,
state = match_mnt_flags(policy->dfa, state, flags); state = match_mnt_flags(policy->dfa, state, flags);
if (!state) if (!state)
return 4; return 4;
*perms = *aa_lookup_perms(policy->perms, state); *perms = *aa_lookup_perms(policy, state);
if (perms->allow & AA_MAY_MOUNT) if (perms->allow & AA_MAY_MOUNT)
return 0; return 0;
...@@ -262,7 +262,7 @@ static int do_match_mnt(struct aa_policydb *policy, unsigned int start, ...@@ -262,7 +262,7 @@ static int do_match_mnt(struct aa_policydb *policy, unsigned int start,
state = aa_dfa_match(policy->dfa, state, data); state = aa_dfa_match(policy->dfa, state, data);
if (!state) if (!state)
return 5; return 5;
*perms = *aa_lookup_perms(policy->perms, state); *perms = *aa_lookup_perms(policy, state);
if (perms->allow & AA_MAY_MOUNT) if (perms->allow & AA_MAY_MOUNT)
return 0; return 0;
} }
...@@ -584,7 +584,7 @@ static int profile_umount(struct aa_profile *profile, const struct path *path, ...@@ -584,7 +584,7 @@ static int profile_umount(struct aa_profile *profile, const struct path *path,
state = aa_dfa_match(profile->policy.dfa, state = aa_dfa_match(profile->policy.dfa,
profile->policy.start[AA_CLASS_MOUNT], profile->policy.start[AA_CLASS_MOUNT],
name); name);
perms = *aa_lookup_perms(profile->policy.perms, state); perms = *aa_lookup_perms(&profile->policy, state);
if (AA_MAY_UMOUNT & ~perms.allow) if (AA_MAY_UMOUNT & ~perms.allow)
error = -EACCES; error = -EACCES;
...@@ -655,7 +655,7 @@ static struct aa_label *build_pivotroot(struct aa_profile *profile, ...@@ -655,7 +655,7 @@ static struct aa_label *build_pivotroot(struct aa_profile *profile,
new_name); new_name);
state = aa_dfa_null_transition(profile->policy.dfa, state); state = aa_dfa_null_transition(profile->policy.dfa, state);
state = aa_dfa_match(profile->policy.dfa, state, old_name); state = aa_dfa_match(profile->policy.dfa, state, old_name);
perms = *aa_lookup_perms(profile->policy.perms, state); perms = *aa_lookup_perms(&profile->policy, state);
if (AA_MAY_PIVOTROOT & perms.allow) if (AA_MAY_PIVOTROOT & perms.allow)
error = 0; error = 0;
......
...@@ -125,7 +125,7 @@ int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa, ...@@ -125,7 +125,7 @@ int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa,
buffer[1] = cpu_to_be16((u16) type); buffer[1] = cpu_to_be16((u16) type);
state = aa_dfa_match_len(profile->policy.dfa, state, (char *) &buffer, state = aa_dfa_match_len(profile->policy.dfa, state, (char *) &buffer,
4); 4);
perms = *aa_lookup_perms(profile->policy.perms, state); perms = *aa_lookup_perms(&profile->policy, state);
aa_apply_modes_to_perms(profile, &perms); aa_apply_modes_to_perms(profile, &perms);
return aa_check_perms(profile, &perms, request, sa, audit_net_cb); return aa_check_perms(profile, &perms, request, sa, audit_net_cb);
......
...@@ -1055,13 +1055,15 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) ...@@ -1055,13 +1055,15 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
} }
if (!unpack_nameX(e, AA_STRUCTEND, NULL)) if (!unpack_nameX(e, AA_STRUCTEND, NULL))
goto fail; goto fail;
profile->policy.perms = compute_perms(profile->policy.dfa);
if (!profile->policy.perms) {
info = "failed to remap policydb permission table";
goto fail;
}
/* Do not remap internal dfas */
remap_dfa_accept(profile->policy.dfa, 1);
} else } else
profile->policy.dfa = aa_get_dfa(nulldfa); profile->policy.dfa = aa_get_dfa(nulldfa);
profile->policy.perms = compute_perms(profile->policy.dfa);
if (!profile->policy.perms) {
info = "failed to remap policydb permission table";
goto fail;
}
/* get file rules */ /* get file rules */
profile->file.dfa = unpack_dfa(e); profile->file.dfa = unpack_dfa(e);
...@@ -1238,9 +1240,12 @@ static bool verify_dfa_xindex(struct aa_dfa *dfa, int table_size) ...@@ -1238,9 +1240,12 @@ static bool verify_dfa_xindex(struct aa_dfa *dfa, int table_size)
*/ */
static int verify_profile(struct aa_profile *profile) static int verify_profile(struct aa_profile *profile)
{ {
if (profile->file.dfa && if ((profile->file.dfa &&
!verify_dfa_xindex(profile->file.dfa, !verify_dfa_xindex(profile->file.dfa,
profile->file.trans.size)) { profile->file.trans.size)) ||
(profile->policy.dfa &&
!verify_dfa_xindex(profile->policy.dfa,
profile->policy.trans.size))) {
audit_iface(profile, NULL, NULL, audit_iface(profile, NULL, NULL,
"Unpack: Invalid named transition", NULL, -EPROTO); "Unpack: Invalid named transition", NULL, -EPROTO);
return -EPROTO; return -EPROTO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment