在运行SElinux的系统上,或者是内核中装了grsecurity和pax的系统中,执行某个命令是有时会遇到如本文题目的错误,如下:
************************************************
:/root> ldd /opt/lsb/bin/dummy_link
/opt/lsb/bin/dummy_link: error while loading shared libraries: libdirect-1.0.so.0: cannot enable executable stack as shared object requires: Permission denied
************************************************
$ civclient
civclient: error while loading shared libraries: libsmpeg-0.4.so.0: cannot enable executable stack as shared object requires: Permission denied
************************************************
最简单的解决办法就是执行execstack:
execstack --clear-execstack /usr/lib/libdirect-1.0.so.0.0.0
execstack --clear-execstack /usr/lib/libsmpeg-0.4.so.0.1.4
execstack 部分参数如下:
-s --set-execstack
Mark binary or shared library as requiring executable stack.
-c --clear-execstack
Mark binary or shared library as not requiring executable stack.
-q --query
Query executable stack marking of binaries and shared libraries. For each file it prints either - when executable stack
is not required, X when executable stack is required or ? when it is unknown whether the object requires or doesn’t
require executable stack (the marking is missing).
通过-q参数查看指定文件是否需要executable stack,如果输出的开头是"-",表示executable stack is not required,如果是“X”,表示executable stack is required,如果是“?”,表示未知。
:/root> execstack -q /usr/lib/libdirect-1.0.so.0
? /usr/lib/libdirect-1.0.so.0
:/root> execstack -c /usr/lib/libdirect-1.0.so.0
:/root> execstack -q /usr/lib/libdirect-1.0.so.0
- /usr/lib/libdirect-1.0.so.0
:/root>
另外,可以尝试第二种方法,设施PAX标志位。设置pax标志位的工具有paxctl和chpax,以下以paxctl为例。
首先把PT_GNU_STACK转换成PT_PAX_FLAGS,这样就可以用paxctl来控制了,转换命令:
:/root> paxctl -c /usr/lib/libdirect-1.0.so.0
然后使用-v参数列出指定文件的pax标志位
:/root> paxctl -v /usr/lib/libdirect-1.0.so.0
PaX control v0.5
Copyright 2004,2005,2006,2007 PaX Team
- PaX flags: -------x-e-- [/usr/lib/libdirect-1.0.so.0]
RANDEXEC is disabled
EMUTRAMP is disabled
如上命令,执行结果可以看出有两个标志位是disable的,我们需要把其他标志位也设置为disable,这样,这个文件的权限就放开到最大了。
修改一下pax flag,先去掉mprotect标志:
:/root> paxctl -m /usr/lib/libdirect-1.0.so.0
:/root> paxctl -v /usr/lib/libdirect-1.0.so.0
PaX control v0.5
Copyright 2004,2005,2006,2007 PaX Team
- PaX flags: -----m-x-e-- [/usr/lib/libdirect-1.0.so.0]
MPROTECT is disabled
RANDEXEC is disabled
EMUTRAMP is disabled
此时实验一下要解决的问题是否已经解决,如果没有解决,那就再disable其他的标志位,直到问题解决,命令可以正常执行为止。
PAX标志位一共有6个,分别是p,e,m,r,x,s,一个一个实验吧。其他参数即参数的含义通过man paxctl查看。
阅读(3484) | 评论(0) | 转发(0) |