Skip to contentSkip to conversation

perf/core: fix unconditional security_locked_down() call

PATCH Applied Ondrej Mosnacek 4 participants 5 messages Feb 24, 2021 – Mar 17, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/core: fix unconditional security_locked_down() call

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")
---
 kernel/events/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/events/core.c +6 -6
index 129dee540a8b..0f857307e9bd 100644
@@ -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
Signature · 1 line
2.29.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Ondrej Mosnacek

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.

Quoted 8 lines

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

Quoted 25 lines
kernel/events/core.c +6 -7
index 129dee540a8b..0f857307e9bd 100644
@@ -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

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#2 lore raw
Quoted 22 lines · Paul Moore
Quoted 12 lines · Ondrej Mosnacek

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.

Quoted 8 lines

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")
---
 kernel/events/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Quoted 5 lines

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.

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.

maintainer
#3 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 26 lines · Paul Moore
Quoted 12 lines · Ondrej Mosnacek

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.

Quoted 8 lines

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

Quoted 6 lines
Quoted 1 line

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.

Signature · 2 lines
paul moore
www.paul-moore.com
#4 lore raw

[tip: perf/core] perf/core: Fix unconditional security_locked_down() call

In reply to Ondrej Mosnacek
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     08ef1af4de5fe7de9c6d69f1e22e51b66e385d9b
Gitweb:        https://git.kernel.org/tip/08ef1af4de5fe7de9c6d69f1e22e51b66e385d9b
Author:        Ondrej Mosnacek <[email protected]>
AuthorDate:    Wed, 24 Feb 2021 22:56:28 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 16 Mar 2021 21:44:43 +01:00

perf/core: Fix unconditional security_locked_down() call

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")
---
 kernel/events/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/events/core.c +6 -6
index 6182cb1..f079431 100644
@@ -11833,12 +11833,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