Skip to content
/ linux Public

Commit dbbe0a2

Browse files
jrjohansenSasha Levin
authored andcommitted
apparmor: make label_match return a consistent value
[ Upstream commit a4c9efa ] compound match is inconsistent in returning a state or an integer error this is problemati if the error is ever used as a state in the state machine Fixes: f1bd904 ("apparmor: add the base fns() for domain labels") Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0563743 commit dbbe0a2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

security/apparmor/label.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ static inline aa_state_t match_component(struct aa_profile *profile,
12881288
* @request: permissions to request
12891289
* @perms: perms struct to set
12901290
*
1291-
* Returns: 0 on success else ERROR
1291+
* Returns: state match stopped at or DFA_NOMATCH if aborted early
12921292
*
12931293
* For the label A//&B//&C this does the perm match for A//&B//&C
12941294
* @perms should be preinitialized with allperms OR a previous permission
@@ -1315,7 +1315,7 @@ static int label_compound_match(struct aa_profile *profile,
13151315

13161316
/* no component visible */
13171317
*perms = allperms;
1318-
return 0;
1318+
return state;
13191319

13201320
next:
13211321
label_for_each_cont(i, label, tp) {
@@ -1327,14 +1327,11 @@ static int label_compound_match(struct aa_profile *profile,
13271327
goto fail;
13281328
}
13291329
*perms = *aa_lookup_perms(rules->policy, state);
1330-
if ((perms->allow & request) != request)
1331-
return -EACCES;
1332-
1333-
return 0;
1330+
return state;
13341331

13351332
fail:
13361333
*perms = nullperms;
1337-
return state;
1334+
return DFA_NOMATCH;
13381335
}
13391336

13401337
/**
@@ -1416,11 +1413,12 @@ int aa_label_match(struct aa_profile *profile, struct aa_ruleset *rules,
14161413
struct aa_label *label, aa_state_t state, bool subns,
14171414
u32 request, struct aa_perms *perms)
14181415
{
1419-
int error = label_compound_match(profile, rules, label, state, subns,
1420-
request, perms);
1421-
if (!error)
1422-
return error;
1416+
aa_state_t tmp = label_compound_match(profile, rules, label, state, subns,
1417+
request, perms);
1418+
if ((perms->allow & request) == request)
1419+
return 0;
14231420

1421+
/* failed compound_match try component matches */
14241422
*perms = allperms;
14251423
return label_components_match(profile, rules, label, state, subns,
14261424
request, perms);

0 commit comments

Comments
 (0)