Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set kptr_restrict to 0?

I am currently having trouble running linux perf, mostly because /proc/sys/kernel/kptr_restrict is currently set to 1.

However, if I try to /proc/sys/kernel/kptr_restrict by echoing 0 to it as follows...

echo 0 > /proc/sys/kernel/kptr_restrict

I get a permission denied error. I don't think I can change permissions on it either.

Is there a way to set this directly somehow? I am super user. I don't think perf will function acceptably without this being set.

like image 899
jab Avatar asked Dec 05 '13 03:12

jab


People also ask

What is Kptr_restrict?

Official reference. This toggle indicates whether restrictions are placed on exposing kernel addresses via /proc and other interfaces. When kptr_restrict is set to 0 (the default) the address is hashed before printing. (This is the equivalent to %p.)

What is proc sys kernel Perf_event_paranoid?

The kernel. perf_event_paranoid sysctl key defines how paranoid the kernel should be related to performance monitoring. * perf event paranoia level (from kernel/perf_event.c) -1 - not paranoid at all. 0 - disallow raw tracepoint access for unprivileged users.


2 Answers

In your example, echo is running as root, but your shell is running as you.

So please try this command:

sudo sh -c " echo 0 > /proc/sys/kernel/kptr_restrict"
like image 191
Jun Ge Avatar answered Oct 10 '22 07:10

Jun Ge


All the files located in /proc/sys can only be modified by root (actually 99.9% files, check with ls -l). Therefore you have to use sudo to modify those files (or your preferred way to execute commands as root).

The proper way to modify the files in /proc/sys is to use the sysctl tool. Note that yu should replace the slashes (/) with dots (.) and omit the /proc/sys/ prefix... read the fine manual.

Read the current value:

$ sysctl kernel.kptr_restrict 
kernel.kptr_restrict = 1

Modify the value:

$ sudo sysctl -w kernel.kptr_restrict=0
sysctl kernel.kptr_restrict=1

To make your modifications reboot persistent, you should edit /etc/sysctl.conf or create a file in /etc/sysctl.d/50-mytest.conf (edit the file as root or using sudoedit), containing:

kernel.kptr_restrict=1

In which case you should execute this command to reload your configuration:

$ sysctl -p /etc/sysctl.conf

P.S. it is possible to directly write in the virtual file. https://stackoverflow.com/users/321730/cdyson37 command is quite elegant: echo 0 | sudo tee /proc/sys/kernel/kptr_restrict

like image 28
Franklin Piat Avatar answered Oct 10 '22 09:10

Franklin Piat