Skip to content

Commit 38272dc

Browse files
WangNan0acmel
authored andcommitted
perf symbols: Check kptr_restrict for root
If kptr_restrict is set to 2, even root is not allowed to see pointers. This patch checks kptr_restrict even if euid == 0. For root, report error if kptr_restrict is 2. Signed-off-by: Wang Nan <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 275ae41 commit 38272dc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tools/perf/util/symbol.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,17 +1933,17 @@ int setup_intlist(struct intlist **list, const char *list_str,
19331933
static bool symbol__read_kptr_restrict(void)
19341934
{
19351935
bool value = false;
1936+
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
19361937

1937-
if (geteuid() != 0) {
1938-
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
1939-
if (fp != NULL) {
1940-
char line[8];
1938+
if (fp != NULL) {
1939+
char line[8];
19411940

1942-
if (fgets(line, sizeof(line), fp) != NULL)
1943-
value = atoi(line) != 0;
1941+
if (fgets(line, sizeof(line), fp) != NULL)
1942+
value = (geteuid() != 0) ?
1943+
(atoi(line) != 0) :
1944+
(atoi(line) == 2);
19441945

1945-
fclose(fp);
1946-
}
1946+
fclose(fp);
19471947
}
19481948

19491949
return value;

0 commit comments

Comments
 (0)