Is there a way to set kptr_restrict to 0?

五迷三道 提交于 2019-12-03 02:07:38
Jun Ge

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"
Franklin Piat

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!