linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>,
	Paul Moore <paul@paul-moore.com>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	Casey Schaufler <casey@schaufler-ca.com>,
	Tyler Hicks <tyhicks@linux.microsoft.com>,
	tusharsu@linux.microsoft.com, Sasha Levin <sashal@kernel.org>,
	James Morris <jmorris@namei.org>,
	linux-integrity@vger.kernel.org,
	SElinux list <selinux@vger.kernel.org>,
	LSM List <linux-security-module@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] SELinux: Measure state and hash of policy using IMA
Date: Tue, 8 Sep 2020 07:58:07 -0400	[thread overview]
Message-ID: <CAEjxPJ6eGcmbtGX7Kvn8e=ZxBUQD5G=8D+o9-BsVXyDFcyPYMw@mail.gmail.com> (raw)
In-Reply-To: <7c4e2e9f-54e1-1dee-c33c-64dac0fe9678@linux.microsoft.com>

On Tue, Sep 8, 2020 at 12:44 AM Lakshmi Ramasubramanian
<nramas@linux.microsoft.com> wrote:
>
> On 9/7/20 3:32 PM, Stephen Smalley wrote:
>
> >> Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
> >> Suggested-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> >> Reported-by: kernel test robot <lkp@intel.com> # error: implicit declaration of function 'vfree'
> >> Reported-by: kernel test robot <lkp@intel.com> # error: implicit declaration of function 'crypto_alloc_shash'
> >> Reported-by: kernel test robot <lkp@intel.com> # sparse: symbol 'security_read_selinux_policy' was not declared. Should it be static?
> >
> > Not sure these Reported-by lines are useful since they were just on
> > submitted versions of the patch not on an actual merged commit.
>
> I'll remove them when I update the patch.
>
> >
> >> diff --git a/security/selinux/measure.c b/security/selinux/measure.c
> >> new file mode 100644
> >> index 000000000000..caf9107937d9
> >> --- /dev/null
> >> +++ b/security/selinux/measure.c
> > <snip>
> >> +void selinux_measure_state(struct selinux_state *state, bool policy_mutex_held)
> >> +{
> > <snip>
> >> +
> >> +       if (!policy_mutex_held)
> >> +               mutex_lock(&state->policy_mutex);
> >> +
> >> +       rc = security_read_policy_kernel(state, &policy, &policy_len);
> >> +
> >> +       if (!policy_mutex_held)
> >> +               mutex_unlock(&state->policy_mutex);
> >
> > This kind of conditional taking of a mutex is generally frowned upon
> > in my experience.
> > You should likely just always take the mutex in the callers of
> > selinux_measure_state() instead.
> > In some cases, it may be the caller of the caller.  Arguably selinuxfs
> > could be taking it around all state modifying operations (e.g.
> > enforce, checkreqprot) not just policy modifying ones although it
> > isn't strictly for that purpose.
>
> Since currently policy_mutex is not used to synchronize access to state
> variables (enforce, checkreqprot, etc.) I am wondering if
> selinux_measure_state() should measure only state if policy_mutex is not
> held by the caller - similar to how we skip measuring policy if
> initialization is not yet completed.

No, we want to measure policy whenever there is a policy to measure.
Just move the taking of the mutex to the callers of
selinux_measure_state() so that it can be unconditional.

  reply	other threads:[~2020-09-08 19:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07 21:38 [PATCH] SELinux: Measure state and hash of policy using IMA Lakshmi Ramasubramanian
2020-09-07 22:32 ` Stephen Smalley
2020-09-08  4:44   ` Lakshmi Ramasubramanian
2020-09-08 11:58     ` Stephen Smalley [this message]
2020-09-08 16:01       ` Lakshmi Ramasubramanian
2020-09-08 12:28 ` Stephen Smalley
2020-09-08 12:35   ` Stephen Smalley
2020-09-08 13:03   ` Ondrej Mosnacek
  -- strict thread matches above, loose matches on Subject: below --
2020-08-22  1:00 Lakshmi Ramasubramanian
2020-08-24 14:00 ` Stephen Smalley
2020-08-24 14:35   ` Lakshmi Ramasubramanian
2020-08-24 18:13   ` Lakshmi Ramasubramanian
2020-08-24 19:29     ` Stephen Smalley
2020-08-24 20:01       ` Ondrej Mosnacek
2020-08-24 21:29         ` Lakshmi Ramasubramanian
2020-08-24 22:18           ` Paul Moore
2020-08-25 20:49             ` Lakshmi Ramasubramanian
2020-08-26 12:51               ` Stephen Smalley
2020-08-31 14:47                 ` Stephen Smalley
2020-08-31 16:39                   ` Lakshmi Ramasubramanian

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='CAEjxPJ6eGcmbtGX7Kvn8e=ZxBUQD5G=8D+o9-BsVXyDFcyPYMw@mail.gmail.com' \
    --to=stephen.smalley.work@gmail.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=nramas@linux.microsoft.com \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sashal@kernel.org \
    --cc=selinux@vger.kernel.org \
    --cc=tusharsu@linux.microsoft.com \
    --cc=tyhicks@linux.microsoft.com \
    --cc=zohar@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).