Skip to content

Commit

Permalink
perf symbols: Check kptr_restrict for root
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
WangNan0 authored and acmel committed May 27, 2016
1 parent 275ae41 commit 38272dc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,17 +1933,17 @@ int setup_intlist(struct intlist **list, const char *list_str,
static bool symbol__read_kptr_restrict(void)
{
bool value = false;
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");

if (geteuid() != 0) {
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
if (fp != NULL) {
char line[8];
if (fp != NULL) {
char line[8];

if (fgets(line, sizeof(line), fp) != NULL)
value = atoi(line) != 0;
if (fgets(line, sizeof(line), fp) != NULL)
value = (geteuid() != 0) ?
(atoi(line) != 0) :
(atoi(line) == 2);

fclose(fp);
}
fclose(fp);
}

return value;
Expand Down

0 comments on commit 38272dc

Please sign in to comment.