mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Haines <richard_c_haines@btinternet.com>
To: Ondrej Mosnacek <omosnace@redhat.com>
Cc: Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	Eric Paris <eparis@parisplace.org>,
	demiobenour@gmail.com, SElinux list <selinux@vger.kernel.org>,
	Linux kernel mailing list <linux-kernel@vger.kernel.org>,
	selinux-refpolicy@vger.kernel.org,
	Jeff Vander Stoep <jeffv@google.com>
Subject: Re: [PATCH V2] security/selinux: Always allow FIOCLEX and FIONCLEX
Date: Wed, 23 Feb 2022 12:43:19 +0000	[thread overview]
Message-ID: <2b45951fceea5f535550f8ab3f3d25c3ff12a8c5.camel@btinternet.com> (raw)
In-Reply-To: <CAFqZXNuf5J35Jb3nmQ6YRrc6C2f5rk-30U0rB4wTMd-+SBQhEQ@mail.gmail.com>

On Wed, 2022-02-23 at 13:12 +0100, Ondrej Mosnacek wrote:
> On Wed, Feb 23, 2022 at 12:58 PM Richard Haines
> <richard_c_haines@btinternet.com> wrote:
> > On Tue, 2022-02-22 at 18:28 -0500, Paul Moore wrote:
> > > On Mon, Feb 21, 2022 at 8:15 AM Richard Haines
> > > <richard_c_haines@btinternet.com> wrote:
> > > > 
> > > > These ioctls are equivalent to fcntl(fd, F_SETFD, flags), which
> > > > SELinux
> > > > always allows too.  Furthermore, a failed FIOCLEX could result
> > > > in a
> > > > file
> > > > descriptor being leaked to a process that should not have
> > > > access to
> > > > it.
> > > > 
> > > > As this patch removes access controls, a policy capability
> > > > needs to
> > > > be
> > > > enabled in policy to always allow these ioctls.
> > > > 
> > > > Based-on-patch-by: Demi Marie Obenour <demiobenour@gmail.com>
> > > > Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
> > > > ---
> > > > V2 Change: Control via a policy capability. See this thread for
> > > > discussion:
> > > > https://lore.kernel.org/selinux/CAHC9VhQEPxYP_KU56gAGNHKQaxucY8gSsHiUB42PVgADBAccRQ@mail.gmail.com/T/#t
> > > > 
> > > > With this patch and the polcap enabled, the selinux-testsuite
> > > > will
> > > > fail:
> > > > ioctl/test at line 47 - Will need a fix.
> > > > 
> > > >  security/selinux/hooks.c                   | 7 +++++++
> > > >  security/selinux/include/policycap.h       | 1 +
> > > >  security/selinux/include/policycap_names.h | 3 ++-
> > > >  security/selinux/include/security.h        | 7 +++++++
> > > >  4 files changed, 17 insertions(+), 1 deletion(-)
> > > 
> > > Thanks Richard for putting together the v2 of this patch.
> > > 
> > > As far as the test is concerned, it seems like the quick-n-dirty
> > > fix
> > > is to simply remove the ioctl(FIOCLEX) test in test_noioctl.c; is
> > > everyone okay with that?  At least that is what I'm going to do
> > > with
> > > my local copy that I use to validate the kernel-secnext builds
> > > unless
> > > someone has a better patch :)
> > 
> > To fix this I was planning to submit a patch that would change the
> > ioctl(FIOCLEX) tests to ioctl(FS_IOC_GETFSLABEL) as that would
> > continue
> > to test the xperms.
> 
> That one seems to be implemented only by some filesystems. Is there
> any more generic one we could use?

What about  FS_IOC_GETFLAGS

> 
> > 
> > > 
> > > > diff --git a/security/selinux/hooks.c
> > > > b/security/selinux/hooks.c
> > > > index 5b6895e4f..030c41652 100644
> > > > --- a/security/selinux/hooks.c
> > > > +++ b/security/selinux/hooks.c
> > > > @@ -3745,6 +3745,13 @@ static int selinux_file_ioctl(struct
> > > > file
> > > > *file, unsigned int cmd,
> > > >                                             CAP_OPT_NONE,
> > > > true);
> > > >                 break;
> > > > 
> > > > +       case FIOCLEX:
> > > > +       case FIONCLEX:
> > > > +               /* Must always succeed if polcap set, else
> > > > default:
> > > > */
> > > > +               if (selinux_policycap_ioctl_skip_cloexec())
> > > > +                       break;
> > > > +               fallthrough;
> > > > +
> > > 
> > > The break/fallthrough looks like it might be a little more
> > > fragile
> > > than necessary, how about something like this:
> > > 
> > >   case FIOCLEX:
> > >   case FIONCLEX:
> > >     if (!selinux_policycap_ioctl_skip_cloexec())
> > >       error = ioctl_has_perm(cred, file, FILE__IOCTL, (u16) cmd);
> > >       break;
> > > 
> > > Yes, it does duplicate the default ioctl_has_perm() call, but
> > > since
> > > we
> > > are effectively deprecating this and locking the FIOCLEX/FIONCLEX
> > > behavior with this policy capability it seems okay to me (and
> > > preferable to relying on the fallthrough).
> > > 
> > > Thoughts?
> > 
> > Yes I did ponder this and in my first attempt I had this before the
> > switch():
> > 
> >         /* Must always succeed if polcap set */
> >         if (selinux_policycap_ioctl_skip_cloexec() &&
> >             (cmd == FIOCLEX || cmd == FIONCLEX))
> >                 return 0;
> > 
> >         switch (cmd) {
> >         case FIONREAD:
> >         case FIBMAP:
> > 
> > but changed to within the switch(), anyway I'm happy to resubmit a
> > patch either way.
> 
> I agree with Paul's suggestion. Better to duplicate the simple call
> than to complicate the code flow.

Okay will use Paul's.

> 


  reply	other threads:[~2022-02-23 12:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 13:15 Richard Haines
2022-02-22 23:28 ` Paul Moore
2022-02-23 11:58   ` Richard Haines
2022-02-23 12:12     ` Ondrej Mosnacek
2022-02-23 12:43       ` Richard Haines [this message]
2022-02-23 21:36         ` Paul Moore
2022-02-23 21:43           ` Paul Moore

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=2b45951fceea5f535550f8ab3f3d25c3ff12a8c5.camel@btinternet.com \
    --to=richard_c_haines@btinternet.com \
    --cc=demiobenour@gmail.com \
    --cc=eparis@parisplace.org \
    --cc=jeffv@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux-refpolicy@vger.kernel.org \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.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®