Skip to contentSkip to conversation

perf cap: Add __NR_capget to arch/x86 unistd

PATCH Applied Ian Rogers 3 participants 4 messages Oct 26, 2024 – Oct 28, 2024 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf cap: Add __NR_capget to arch/x86 unistd

As there are duplicated kernel headers in tools/include libc can pick up the wrong definitions. This was causing the wrong system call for capget in perf.

---
 tools/arch/x86/include/uapi/asm/unistd_32.h |  3 +++
 tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
 tools/perf/util/cap.c                       | 10 +++-------
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/arch/x86/include/uapi/asm/unistd_32.h +3 -0
index 9de35df1afc3..63182a023e9d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 132
 #endif
+#ifndef __NR_capget
+#define __NR_capget 184
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 224
 #endif
tools/arch/x86/include/uapi/asm/unistd_64.h +3 -0
index d0f2043d7132..77311e8d1b5d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 121
 #endif
+#ifndef __NR_capget
+#define __NR_capget 125
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 186
 #endif
tools/perf/util/cap.c +3 -7
index 7574a67651bc..69d9a2bcd40b 100644
@@ -7,13 +7,9 @@
 #include "debug.h"
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <linux/capability.h>
 #include <sys/syscall.h>
-
-#ifndef SYS_capget
-#define SYS_capget 90
-#endif
+#include <unistd.h>
 
 #define MAX_LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
 
@@ -21,9 +17,9 @@ bool perf_cap__capable(int cap, bool *used_root)
 {
 	struct __user_cap_header_struct header = {
 		.version = _LINUX_CAPABILITY_VERSION_3,
-		.pid = getpid(),
+		.pid = 0,
 	};
-	struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S];
+	struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S] = {};
 	__u32 cap_val;
 
 	*used_root = false;
Signature · 1 line
2.47.0.163.g1226f6d8fa-goog
author reviewer
#1 lore raw
Quoted 7 lines · Ian Rogers

As there are duplicated kernel headers in tools/include libc can pick up the wrong definitions. This was causing the wrong system call for capget in perf.

Forgot:

Fixes e25ebda78e23 ("perf cap: Tidy up and improve capability testing")

Thanks,
Ian

Quoted 68 lines
---
 tools/arch/x86/include/uapi/asm/unistd_32.h |  3 +++
 tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
 tools/perf/util/cap.c                       | 10 +++-------
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/arch/x86/include/uapi/asm/unistd_32.h +3 -0
index 9de35df1afc3..63182a023e9d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 132
 #endif
+#ifndef __NR_capget
+#define __NR_capget 184
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 224
 #endif
tools/arch/x86/include/uapi/asm/unistd_64.h +3 -0
index d0f2043d7132..77311e8d1b5d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 121
 #endif
+#ifndef __NR_capget
+#define __NR_capget 125
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 186
 #endif
tools/perf/util/cap.c +3 -8
index 7574a67651bc..69d9a2bcd40b 100644
@@ -7,13 +7,9 @@
 #include "debug.h"
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <linux/capability.h>
 #include <sys/syscall.h>
-
-#ifndef SYS_capget
-#define SYS_capget 90
-#endif
+#include <unistd.h>
 
 #define MAX_LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
 
@@ -21,9 +17,9 @@ bool perf_cap__capable(int cap, bool *used_root)
 {
        struct __user_cap_header_struct header = {
                .version = _LINUX_CAPABILITY_VERSION_3,
-               .pid = getpid(),
+               .pid = 0,
        };
-       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S];
+       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S] = {};
        __u32 cap_val;
 
        *used_root = false;
--

2.47.0.163.g1226f6d8fa-goog

reviewer Tested-by
#2 lore raw
Quoted 11 lines · Ian Rogers
Quoted 7 lines · Ian Rogers

As there are duplicated kernel headers in tools/include libc can pick up the wrong definitions. This was causing the wrong system call for capget in perf.

Forgot:

Fixes e25ebda78e23 ("perf cap: Tidy up and improve capability testing")

Works for me, thank you!

Quoted 72 lines

Thanks,
Ian

Quoted 68 lines
---
 tools/arch/x86/include/uapi/asm/unistd_32.h |  3 +++
 tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
 tools/perf/util/cap.c                       | 10 +++-------
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/arch/x86/include/uapi/asm/unistd_32.h +3 -0
index 9de35df1afc3..63182a023e9d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 132
 #endif
+#ifndef __NR_capget
+#define __NR_capget 184
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 224
 #endif
tools/arch/x86/include/uapi/asm/unistd_64.h +3 -0
index d0f2043d7132..77311e8d1b5d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 121
 #endif
+#ifndef __NR_capget
+#define __NR_capget 125
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 186
 #endif
tools/perf/util/cap.c +3 -8
index 7574a67651bc..69d9a2bcd40b 100644
@@ -7,13 +7,9 @@
 #include "debug.h"
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <linux/capability.h>
 #include <sys/syscall.h>
-
-#ifndef SYS_capget
-#define SYS_capget 90
-#endif
+#include <unistd.h>
 
 #define MAX_LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
 
@@ -21,9 +17,9 @@ bool perf_cap__capable(int cap, bool *used_root)
 {
        struct __user_cap_header_struct header = {
                .version = _LINUX_CAPABILITY_VERSION_3,
-               .pid = getpid(),
+               .pid = 0,
        };
-       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S];
+       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S] = {};
        __u32 cap_val;
 
        *used_root = false;
--

2.47.0.163.g1226f6d8fa-goog

maintainer Applied
#3 lore raw
Quoted 10 lines · Adrian Hunter
Quoted 9 lines · Ian Rogers
Quoted 7 lines · Ian Rogers

As there are duplicated kernel headers in tools/include libc can pick up the wrong definitions. This was causing the wrong system call for capget in perf.

Quoted 6 lines
Quoted 2 lines

Forgot:

Fixes e25ebda78e23 ("perf cap: Tidy up and improve capability testing")

Works for me, thank you!

Thanks, I also added this:

Applied to perf-tools, for v6.12-rc.

- Arnaldo

Quoted 72 lines
Quoted 72 lines

Thanks,
Ian

Quoted 68 lines
---
 tools/arch/x86/include/uapi/asm/unistd_32.h |  3 +++
 tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
 tools/perf/util/cap.c                       | 10 +++-------
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/arch/x86/include/uapi/asm/unistd_32.h +3 -0
index 9de35df1afc3..63182a023e9d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 132
 #endif
+#ifndef __NR_capget
+#define __NR_capget 184
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 224
 #endif
tools/arch/x86/include/uapi/asm/unistd_64.h +3 -0
index d0f2043d7132..77311e8d1b5d 100644
@@ -11,6 +11,9 @@
 #ifndef __NR_getpgid
 #define __NR_getpgid 121
 #endif
+#ifndef __NR_capget
+#define __NR_capget 125
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 186
 #endif
tools/perf/util/cap.c +3 -8
index 7574a67651bc..69d9a2bcd40b 100644
@@ -7,13 +7,9 @@
 #include "debug.h"
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <linux/capability.h>
 #include <sys/syscall.h>
-
-#ifndef SYS_capget
-#define SYS_capget 90
-#endif
+#include <unistd.h>
 
 #define MAX_LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
 
@@ -21,9 +17,9 @@ bool perf_cap__capable(int cap, bool *used_root)
 {
        struct __user_cap_header_struct header = {
                .version = _LINUX_CAPABILITY_VERSION_3,
-               .pid = getpid(),
+               .pid = 0,
        };
-       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S];
+       struct __user_cap_data_struct data[MAX_LINUX_CAPABILITY_U32S] = {};
        __u32 cap_val;
 
        *used_root = false;
--

2.47.0.163.g1226f6d8fa-goog