Skip to contentSkip to conversation

perf/core: Call LSM hook after copying perf_event_attr

PATCH Superseded Namhyung Kim 2 participants 3 messages Jun 2, 2022 – Jun 24, 2022 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf/core: Call LSM hook after copying perf_event_attr

It passes the attr struct to the security_perf_event_open() but it's not initialized yet.

Fixes da97e18458fb ("perf_event: Add support for LSM and SELinux checks")
Cc Joel Fernandes (Google) <[email protected]>
---
 kernel/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/core.c +3 -3
index 7858bafffa9d..e035545f624f 100644
@@ -12033,12 +12033,12 @@ SYSCALL_DEFINE5(perf_event_open,
 	if (flags & ~PERF_FLAG_ALL)
 		return -EINVAL;
 
-	/* Do we allow access to perf_event_open(2) ? */
-	err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);
+	err = perf_copy_attr(attr_uptr, &attr);
 	if (err)
 		return err;
 
-	err = perf_copy_attr(attr_uptr, &attr);
+	/* Do we allow access to perf_event_open(2) ? */
+	err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);
 	if (err)
 		return err;
 
Signature · 1 line
2.36.1.255.ge46751e96f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Namhyung Kim

It passes the attr struct to the security_perf_event_open() but it's not initialized yet.

Fixes da97e18458fb ("perf_event: Add support for LSM and SELinux checks")
Cc Joel Fernandes (Google) <[email protected]>
---
 kernel/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/core.c +0 -0
index 7858bafffa9d..e035545f624f 100644
@@ -12033,12 +12033,12 @@ SYSCALL_DEFINE5(perf_event_open,
 	if (flags & ~PERF_FLAG_ALL)
 		return -EINVAL;

kernel/events/core.c SYSCALL_DEFINE5(perf_event_open, · line 12041

Quoted 10 lines
kernel/events/core.c +3 -3
 
-	/* Do we allow access to perf_event_open(2) ? */
-	err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);
+	err = perf_copy_attr(attr_uptr, &attr);
 	if (err)
 		return err;
 
-	err = perf_copy_attr(attr_uptr, &attr);
+	/* Do we allow access to perf_event_open(2) ? */
+	err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);

thanks,

- Joel

Quoted 6 lines
kernel/events/core.c +0 -0
 	if (err)
 		return err;
 
Signature · 1 line
2.36.1.255.ge46751e96f-goog
author maintainer
#2 lore raw

Hi Peter,

Quoted 26 lines · Joel Fernandes
Quoted 24 lines · Namhyung Kim

It passes the attr struct to the security_perf_event_open() but it's not initialized yet.

Fixes da97e18458fb ("perf_event: Add support for LSM and SELinux checks")
Cc Joel Fernandes (Google) <[email protected]>
---
 kernel/events/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/core.c +1 -2
index 7858bafffa9d..e035545f624f 100644
@@ -12033,12 +12033,12 @@ SYSCALL_DEFINE5(perf_event_open,
      if (flags & ~PERF_FLAG_ALL)
              return -EINVAL;
 
-     /* Do we allow access to perf_event_open(2) ? */
-     err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);
+     err = perf_copy_attr(attr_uptr, &attr);
      if (err)
              return err;
 
Quoted 5 lines

kernel/events/core.c SYSCALL_DEFINE5(perf_event_open, · line 12041

Quoted 3 lines
kernel/events/core.c +2 -1
-     err = perf_copy_attr(attr_uptr, &attr);
+     /* Do we allow access to perf_event_open(2) ? */
+     err = security_perf_event_open(&attr, PERF_SECURITY_OPEN);

Any chance you can pick this up?

Thanks,
Namhyung