Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa1de33 authored by Tianjia Zhang's avatar Tianjia Zhang Committed by Greg Kroah-Hartman
Browse files

Smack: Fix wrong semantics in smk_access_entry()



[ Upstream commit 6d14f5c7028eea70760df284057fe198ce7778dd ]

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: default avatarTianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent b4c76419
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -90,17 +90,12 @@ 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.
			 */
@@ -108,6 +103,10 @@ int smk_access_entry(char *subject_label, char *object_label,
				may |= MAY_LOCK;
			return may;
		}
	}

	return -ENOENT;
}

/**
 * smk_access - determine if a subject has a specific access to an object