From: Casey Schaufler <casey@schaufler-ca.com>
To: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH] Smack: Fix wrong semantics in smk_access_entry()
Date: Thu, 15 Jul 2021 08:15:12 -0700 [thread overview]
Message-ID: <ae938c7b-2f7a-27ec-7077-ceeb517ba97f@schaufler-ca.com> (raw)
In-Reply-To: <20210715091724.45768-1-tianjia.zhang@linux.alibaba.com>
On 7/15/2021 2:17 AM, Tianjia Zhang wrote:
> 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.
Indeed, the code as written is functioning correctly by
sheer luck. I will take this patch. Thank you.
>
> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> ---
> security/smack/smack_access.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
> index 1f391f6a3d47..d2186e2757be 100644
> --- a/security/smack/smack_access.c
> +++ b/security/smack/smack_access.c
> @@ -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;
> }
>
> /**
next prev parent reply other threads:[~2021-07-15 15:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-15 9:17 Tianjia Zhang
2021-07-15 15:15 ` Casey Schaufler [this message]
2021-07-20 16:32 ` Casey Schaufler
2021-07-21 3:10 ` Tianjia Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ae938c7b-2f7a-27ec-7077-ceeb517ba97f@schaufler-ca.com \
--to=casey@schaufler-ca.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=tianjia.zhang@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®