linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott Mayhew <smayhew@redhat.com>
To: Paul Moore <paul@paul-moore.com>
Cc: selinux@vger.kernel.org, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v2 1/2] selinux: Fix selinux_sb_mnt_opts_compat()
Date: Tue, 25 Jan 2022 13:51:51 -0500	[thread overview]
Message-ID: <YfBGx+M9jQZa80rZ@aion.usersys.redhat.com> (raw)
In-Reply-To: <CAHC9VhTwXUE9dYBHrkA3Xkr=AgXvcnfSzLLBJ4QqYd4R+kFbbA@mail.gmail.com>

On Tue, 25 Jan 2022, Paul Moore wrote:

> On Tue, Jan 25, 2022 at 12:31 PM Scott Mayhew <smayhew@redhat.com> wrote:
> > On Mon, 24 Jan 2022, Paul Moore wrote:
> > > On Thu, Jan 20, 2022 at 4:50 PM Scott Mayhew <smayhew@redhat.com> wrote:
> > > >
> > > > selinux_sb_mnt_opts_compat() is called under the sb_lock spinlock and
> > > > shouldn't be performing any memory allocations.  Fix this by parsing the
> > > > sids at the same time we're chopping up the security mount options
> > > > string and then using the pre-parsed sids when doing the comparison.
> > > >
> > > > Fixes: cc274ae7763d ("selinux: fix sleeping function called from invalid context")
> > > > Fixes: 69c4a42d72eb ("lsm,selinux: add new hook to compare new mount to an existing mount")
> > > > Signed-off-by: Scott Mayhew <smayhew@redhat.com>
> > > > ---
> > > >  security/selinux/hooks.c | 112 ++++++++++++++++++++++++++-------------
> > > >  1 file changed, 76 insertions(+), 36 deletions(-)
> 
> ...
> 
> > > >         switch (token) {
> > > >         case Opt_context:
> > > >                 if (opts->context || opts->defcontext)
> > > >                         goto err;
> > > >                 opts->context = s;
> > > > +               if (preparse_sid) {
> > > > +                       rc = parse_sid(NULL, s, &sid);
> > > > +                       if (rc == 0) {
> > > > +                               opts->context_sid = sid;
> > > > +                               opts->preparsed |= CONTEXT_MNT;
> > > > +                       }
> > > > +               }
> > >
> > > Is there a reason why we need a dedicated sid variable as opposed to
> > > passing opt->context_sid as the parameter?  For example:
> > >
> > >   rc = parse_sid(NULL, s, &opts->context_sid);
> >
> > We don't need a dedicated sid variable.  Should I make similar changes
> > in the second patch (get rid of the local sid variable in
> > selinux_sb_remount() and the *context_sid variables in
> > selinux_set_mnt_opts())?
> 
> Yes please, I should have explicitly mentioned that.

Actually, delayed_superblock_init() calls selinux_set_mnt_opts() with
mnt_opts == NULL, so there would have to be a lot of checks like

        if (opts && opts->fscontext_sid) {

in the later parts of that function, which is kind of clunky.  I can
still do it if you want though.

-Scott

> 
> Thanks.
> 
> -- 
> paul moore
> paul-moore.com
> 


  reply	other threads:[~2022-01-25 18:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 21:49 [PATCH RFC v2 0/2] selinux: parse sids earlier to avoid doing memory allocations under spinlock Scott Mayhew
2022-01-20 21:49 ` [PATCH RFC v2 1/2] selinux: Fix selinux_sb_mnt_opts_compat() Scott Mayhew
2022-01-24 21:27   ` Paul Moore
2022-01-25 17:30     ` Scott Mayhew
2022-01-25 17:45       ` Paul Moore
2022-01-25 18:51         ` Scott Mayhew [this message]
2022-01-25 22:32           ` Paul Moore
2022-01-26 20:41             ` Scott Mayhew
2022-01-28  1:53               ` Paul Moore
2022-01-27  9:54   ` Ondrej Mosnacek
2022-01-28  2:25     ` Paul Moore
2022-01-31 12:46       ` Ondrej Mosnacek
2022-01-31 16:16         ` Paul Moore
2022-02-01 14:38           ` Ondrej Mosnacek
2022-02-01 16:19             ` Paul Moore
2022-01-20 21:49 ` [PATCH RFC v2 2/2] selinux: try to use preparsed sid before calling parse_sid() Scott Mayhew

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=YfBGx+M9jQZa80rZ@aion.usersys.redhat.com \
    --to=smayhew@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    /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).