Skip to content

Commit 6d14f5c

Browse files
uudiincschaufler
authored andcommitted
Smack: Fix wrong semantics in smk_access_entry()
In the smk_access_entry() function, if no matching rule is found in the rust_list, a negative error code will be used to perform bit operations with the MAY_ enumeration value. This is semantically wrong. This patch fixes this issue. Signed-off-by: Tianjia Zhang <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 2734d6c commit 6d14f5c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

security/smack/smack_access.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,22 @@ int log_policy = SMACK_AUDIT_DENIED;
8181
int smk_access_entry(char *subject_label, char *object_label,
8282
struct list_head *rule_list)
8383
{
84-
int may = -ENOENT;
8584
struct smack_rule *srp;
8685

8786
list_for_each_entry_rcu(srp, rule_list, list) {
8887
if (srp->smk_object->smk_known == object_label &&
8988
srp->smk_subject->smk_known == subject_label) {
90-
may = srp->smk_access;
91-
break;
89+
int may = srp->smk_access;
90+
/*
91+
* MAY_WRITE implies MAY_LOCK.
92+
*/
93+
if ((may & MAY_WRITE) == MAY_WRITE)
94+
may |= MAY_LOCK;
95+
return may;
9296
}
9397
}
9498

95-
/*
96-
* MAY_WRITE implies MAY_LOCK.
97-
*/
98-
if ((may & MAY_WRITE) == MAY_WRITE)
99-
may |= MAY_LOCK;
100-
return may;
99+
return -ENOENT;
101100
}
102101

103102
/**

0 commit comments

Comments
 (0)