Skip to content

Commit

Permalink
Smack: Fix wrong semantics in smk_access_entry()
Browse files Browse the repository at this point in the history
[ Upstream commit 6d14f5c ]

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 <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
uudiin authored and gregkh committed Sep 18, 2021
1 parent 60a064f commit 01b3c23
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions security/smack/smack_access.c
Expand Up @@ -81,23 +81,22 @@ int log_policy = SMACK_AUDIT_DENIED;
int smk_access_entry(char *subject_label, char *object_label,
struct list_head *rule_list)
{
int may = -ENOENT;
struct smack_rule *srp;

list_for_each_entry_rcu(srp, rule_list, list) {
if (srp->smk_object->smk_known == object_label &&
srp->smk_subject->smk_known == subject_label) {
may = srp->smk_access;
break;
int may = srp->smk_access;
/*
* MAY_WRITE implies MAY_LOCK.
*/
if ((may & MAY_WRITE) == MAY_WRITE)
may |= MAY_LOCK;
return may;
}
}

/*
* MAY_WRITE implies MAY_LOCK.
*/
if ((may & MAY_WRITE) == MAY_WRITE)
may |= MAY_LOCK;
return may;
return -ENOENT;
}

/**
Expand Down

0 comments on commit 01b3c23

Please sign in to comment.