linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf/core: fix unconditional security_locked_down() call
@ 2021-02-24 21:56 Ondrej Mosnacek
  2021-03-16 13:53 ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Ondrej Mosnacek @ 2021-02-24 21:56 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	selinux, linux-security-module, linux-kernel, David Howells,
	Matthew Garrett

Currently, the lockdown state is queried unconditionally, even though
its result is used only if the PERF_SAMPLE_REGS_INTR bit is set in
attr.sample_type. While that doesn't matter in case of the Lockdown LSM,
it causes trouble with the SELinux's lockdown hook implementation.

SELinux implements the locked_down hook with a check whether the current
task's type has the corresponding "lockdown" class permission
("integrity" or "confidentiality") allowed in the policy. This means
that calling the hook when the access control decision would be ignored
generates a bogus permission check and audit record.

Fix this by checking sample_type first and only calling the hook when
its result would be honored.

Fixes: b0c8fdc7fdb7 ("lockdown: Lock down perf when in confidentiality mode")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 kernel/events/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 129dee540a8b..0f857307e9bd 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11796,12 +11796,12 @@ SYSCALL_DEFINE5(perf_event_open,
 			return err;
 	}
 
-	err = security_locked_down(LOCKDOWN_PERF);
-	if (err && (attr.sample_type & PERF_SAMPLE_REGS_INTR))
-		/* REGS_INTR can leak data, lockdown must prevent this */
-		return err;
-
-	err = 0;
+	/* REGS_INTR can leak data, lockdown must prevent this */
+	if (attr.sample_type & PERF_SAMPLE_REGS_INTR) {
+		err = security_locked_down(LOCKDOWN_PERF);
+		if (err)
+			return err;
+	}
 
 	/*
 	 * In cgroup mode, the pid argument is used to pass the fd
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf/core: fix unconditional security_locked_down() call
  2021-02-24 21:56 [PATCH] perf/core: fix unconditional security_locked_down() call Ondrej Mosnacek
@ 2021-03-16 13:53 ` Paul Moore
  2021-03-16 14:30   ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Moore @ 2021-03-16 13:53 UTC (permalink / raw)
  To: Ondrej Mosnacek
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	selinux, linux-security-module, linux-kernel, David Howells,
	Matthew Garrett

On Wed, Feb 24, 2021 at 4:59 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> Currently, the lockdown state is queried unconditionally, even though
> its result is used only if the PERF_SAMPLE_REGS_INTR bit is set in
> attr.sample_type. While that doesn't matter in case of the Lockdown LSM,
> it causes trouble with the SELinux's lockdown hook implementation.
>
> SELinux implements the locked_down hook with a check whether the current
> task's type has the corresponding "lockdown" class permission
> ("integrity" or "confidentiality") allowed in the policy. This means
> that calling the hook when the access control decision would be ignored
> generates a bogus permission check and audit record.
>
> Fix this by checking sample_type first and only calling the hook when
> its result would be honored.
>
> Fixes: b0c8fdc7fdb7 ("lockdown: Lock down perf when in confidentiality mode")
> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> ---
>  kernel/events/core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Perf/core folks, do you want to pull this in via your tree?  If I
don't hear anything in the next day I'll pull this in via the
selinux/next tree.

Reviewed-by: Paul Moore <paul@paul-moore.com>

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 129dee540a8b..0f857307e9bd 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -11796,12 +11796,12 @@ SYSCALL_DEFINE5(perf_event_open,
>                         return err;
>         }
>
> -       err = security_locked_down(LOCKDOWN_PERF);
> -       if (err && (attr.sample_type & PERF_SAMPLE_REGS_INTR))
> -               /* REGS_INTR can leak data, lockdown must prevent this */
> -               return err;
> -
> -       err = 0;
> +       /* REGS_INTR can leak data, lockdown must prevent this */
> +       if (attr.sample_type & PERF_SAMPLE_REGS_INTR) {
> +               err = security_locked_down(LOCKDOWN_PERF);
> +               if (err)
> +                       return err;
> +       }
>
>         /*
>          * In cgroup mode, the pid argument is used to pass the fd
> --
> 2.29.2

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf/core: fix unconditional security_locked_down() call
  2021-03-16 13:53 ` Paul Moore
@ 2021-03-16 14:30   ` Peter Zijlstra
  2021-03-16 15:12     ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2021-03-16 14:30 UTC (permalink / raw)
  To: Paul Moore
  Cc: Ondrej Mosnacek, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	selinux, linux-security-module, linux-kernel, David Howells,
	Matthew Garrett

On Tue, Mar 16, 2021 at 09:53:21AM -0400, Paul Moore wrote:
> On Wed, Feb 24, 2021 at 4:59 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> >
> > Currently, the lockdown state is queried unconditionally, even though
> > its result is used only if the PERF_SAMPLE_REGS_INTR bit is set in
> > attr.sample_type. While that doesn't matter in case of the Lockdown LSM,
> > it causes trouble with the SELinux's lockdown hook implementation.
> >
> > SELinux implements the locked_down hook with a check whether the current
> > task's type has the corresponding "lockdown" class permission
> > ("integrity" or "confidentiality") allowed in the policy. This means
> > that calling the hook when the access control decision would be ignored
> > generates a bogus permission check and audit record.
> >
> > Fix this by checking sample_type first and only calling the hook when
> > its result would be honored.
> >
> > Fixes: b0c8fdc7fdb7 ("lockdown: Lock down perf when in confidentiality mode")
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > ---
> >  kernel/events/core.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> Perf/core folks, do you want to pull this in via your tree?  If I
> don't hear anything in the next day I'll pull this in via the
> selinux/next tree.
> 
> Reviewed-by: Paul Moore <paul@paul-moore.com>

Ah, fell in the cracks... I've no idea what Changelog is trying to tell
me. It is pure gibberish to me. But the patch seems harmless enough to me.

Let me queue it then.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf/core: fix unconditional security_locked_down() call
  2021-03-16 14:30   ` Peter Zijlstra
@ 2021-03-16 15:12     ` Paul Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2021-03-16 15:12 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ondrej Mosnacek, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	selinux, linux-security-module, linux-kernel, David Howells,
	Matthew Garrett

On Tue, Mar 16, 2021 at 10:30 AM Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Mar 16, 2021 at 09:53:21AM -0400, Paul Moore wrote:
> > On Wed, Feb 24, 2021 at 4:59 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > >
> > > Currently, the lockdown state is queried unconditionally, even though
> > > its result is used only if the PERF_SAMPLE_REGS_INTR bit is set in
> > > attr.sample_type. While that doesn't matter in case of the Lockdown LSM,
> > > it causes trouble with the SELinux's lockdown hook implementation.
> > >
> > > SELinux implements the locked_down hook with a check whether the current
> > > task's type has the corresponding "lockdown" class permission
> > > ("integrity" or "confidentiality") allowed in the policy. This means
> > > that calling the hook when the access control decision would be ignored
> > > generates a bogus permission check and audit record.
> > >
> > > Fix this by checking sample_type first and only calling the hook when
> > > its result would be honored.
> > >
> > > Fixes: b0c8fdc7fdb7 ("lockdown: Lock down perf when in confidentiality mode")
> > > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > > ---
> > >  kernel/events/core.c | 12 ++++++------
> > >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > Perf/core folks, do you want to pull this in via your tree?  If I
> > don't hear anything in the next day I'll pull this in via the
> > selinux/next tree.
> >
> > Reviewed-by: Paul Moore <paul@paul-moore.com>
>
> Ah, fell in the cracks... I've no idea what Changelog is trying to tell
> me. It is pure gibberish to me. But the patch seems harmless enough to me.
>
> Let me queue it then.

Great, thanks.

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-16 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 21:56 [PATCH] perf/core: fix unconditional security_locked_down() call Ondrej Mosnacek
2021-03-16 13:53 ` Paul Moore
2021-03-16 14:30   ` Peter Zijlstra
2021-03-16 15:12     ` Paul Moore

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).