lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHC9VhQnRQFrM-mTzUQ3UsyVp2JYw1wUh=7yrdjH7-QmHKidAg@mail.gmail.com>
Date:   Tue, 22 Feb 2022 18:28:31 -0500
From:   Paul Moore <paul@...l-moore.com>
To:     Richard Haines <richard_c_haines@...nternet.com>
Cc:     stephen.smalley.work@...il.com, eparis@...isplace.org,
        demiobenour@...il.com, selinux@...r.kernel.org,
        linux-kernel@...r.kernel.org, selinux-refpolicy@...r.kernel.org,
        jeffv@...gle.com
Subject: Re: [PATCH V2] security/selinux: Always allow FIOCLEX and FIONCLEX

On Mon, Feb 21, 2022 at 8:15 AM Richard Haines
<richard_c_haines@...nternet.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@...il.com>
> Signed-off-by: Richard Haines <richard_c_haines@...nternet.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 :)

> 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?

-- 
paul-moore.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ