pax ld flags

Discuss usability issues, general maintenance, and general support issues for a grsecurity-enabled system.

pax ld flags

Postby cmouse » Wed Jan 26, 2005 7:10 am

If I compile something with -Wl,'-z stack' why does it deny the request when it's being used?
cmouse
 
Posts: 98
Joined: Tue Dec 17, 2002 10:58 am

Postby cmouse » Wed Jan 26, 2005 7:22 am

Most importantly this applies to openssl 0.9.7e which seems to be unable to work in any application dynamically linked to it without removing all PaX features from the binary.

Error messages

~$ mysql
mysql: error while loading shared libraries: libcrypto.so.0.9.7: cannot enable executable stack as shared object requires: Permission denied
~$ strace mysql
execve("/usr/bin/mysql", ["mysql"], [/* 23 vars */]) = 0
uname({sys="Linux", node="mordor", ...}) = 0
brk(0) = 0x805cfbc
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/tls/i686/sse2/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/tls/i686/sse2", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/tls/i686/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/tls/i686", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/tls/sse2/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/tls/sse2", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/tls/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/tls", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/i686/sse2/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/i686/sse2", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/i686/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/i686", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/sse2/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql/sse2", 0xbffff168) = -1 ENOENT (No such file or directory)
open("/usr/lib/mysql/libreadline.so.5.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/mysql", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=13492, ...}) = 0
mmap2(NULL, 13492, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ffc000
close(3) = 0
open("/lib/libreadline.so.5.0", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\263"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=206821, ...}) = 0
mmap2(NULL, 179100, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x127000
mmap2(0x14e000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26) = 0x14e000
mmap2(0x152000, 2972, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x152000
close(3) = 0
open("/usr/lib/mysql/libncurses.so.5", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libncurses.so.5", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0\341\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=289457, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ffb000
mmap2(NULL, 263884, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x153000
mmap2(0x18b000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x38) = 0x18b000
mmap2(0x193000, 1740, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x193000
close(3) = 0
open("/usr/lib/mysql/libmysqlclient.so.14", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\266"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=413581, ...}) = 0
mmap2(NULL, 376480, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x194000
mmap2(0x1cc000, 147456, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x37) = 0x1cc000
close(3) = 0
open("/usr/lib/mysql/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libcrypt.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p\10\0\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=25233, ...}) = 0
mmap2(NULL, 184636, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x1f0000
mmap2(0x1f5000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4) = 0x1f5000
mmap2(0x1f7000, 155964, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x1f7000
close(3) = 0
open("/usr/lib/mysql/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libnsl.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0@5\0\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=88309, ...}) = 0
mmap2(NULL, 83968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x21e000
mmap2(0x22f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10) = 0x22f000
mmap2(0x231000, 6144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x231000
close(3) = 0
open("/usr/lib/mysql/libz.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libz.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \26\0\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=75598, ...}) = 0
mmap2(NULL, 72652, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x233000
mmap2(0x244000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10) = 0x244000
close(3) = 0
open("/usr/lib/mysql/libssl.so.0.9.7", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libssl.so.0.9.7", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0@\337\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=228279, ...}) = 0
mmap2(NULL, 205124, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x245000
mmap2(0x275000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x30) = 0x275000
mmap2(0x277000, 324, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x277000
close(3) = 0
open("/usr/lib/mysql/libcrypto.so.0.9.7", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libcrypto.so.0.9.7", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300\324"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=1184395, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ffa000
mmap2(NULL, 1037400, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x278000
mmap2(0x365000, 53248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xed) = 0x365000
mmap2(0x372000, 13400, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x372000
mprotect(0xbffff000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSDOWN) = -1 EACCES (Permission denied)
close(3) = 0
writev(2, [{"mysql", 5}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libcrypto.so.0.9.7", 18}, {": ", 2}, {"cannot enable executable stack a"..., 56}, {": ", 2}, {"Permission denied", 17}, {"\n", 1}], 10mysql: error while loading shared libraries: libcrypto.so.0.9.7: cannot enable executable stack as shared object requires: Permission denied
) = 141
exit_group(127) = ?
~# paxctl -p mysql
~$ strace mysql
execve("/usr/bin/mysql", ["mysql"], [/* 23 vars */]) = 0
+++ killed by SIGKILL +++
~$

Related kernel config

CONFIG_PAX=y
# CONFIG_PAX_SOFTMODE is not set
CONFIG_PAX_EI_PAX=y
CONFIG_PAX_PT_PAX_FLAGS=y
# CONFIG_PAX_NO_ACL_FLAGS is not set
CONFIG_PAX_HAVE_ACL_FLAGS=y
# CONFIG_PAX_HOOK_ACL_FLAGS is not set
CONFIG_PAX_NOEXEC=y
CONFIG_PAX_PAGEEXEC=y
# CONFIG_PAX_SEGMEXEC is not set
# CONFIG_PAX_EMUTRAMP is not set
CONFIG_PAX_MPROTECT=y
# CONFIG_PAX_NOELFRELOCS is not set
CONFIG_PAX_KERNEXEC=y
CONFIG_PAX_ASLR=y
CONFIG_PAX_RANDKSTACK=y
# CONFIG_PAX_RANDUSTACK is not set
# CONFIG_PAX_RANDMMAP is not set
CONFIG_PAX_NOVSYSCALL=y

RBAC not enabled, so not included.
cmouse
 
Posts: 98
Joined: Tue Dec 17, 2002 10:58 am

Re: pax ld flags

Postby PaX Team » Wed Jan 26, 2005 10:26 am

cmouse wrote:If I compile something with -Wl,'-z stack' why does it deny the request when it's being used?
it's -Wl,-z,execstack (or noexecstack), but in your case it's easier to use execstack -c on the library itself. you can verify the effect by looking at the readelf -d output, the GNU_STACK line should say RW and not RWE.
PaX Team
 
Posts: 2310
Joined: Mon Mar 18, 2002 4:35 pm

Postby spender » Wed Jan 26, 2005 10:27 am

Why are you enabling executable stacks on things that don't need it? If you allow an app to execute arbitrary code, you'll have to turn off at least MPROTECT and and most PAGEEXEC/SEGMEXEC.

-Brad
spender
 
Posts: 2185
Joined: Wed Feb 20, 2002 8:00 pm

Postby cmouse » Sat Jan 29, 2005 6:27 am

Odd. Because I compiled it without -z parameter, first. And after that I used -z because I thought it might help. But didn't.
cmouse
 
Posts: 98
Joined: Tue Dec 17, 2002 10:58 am


Return to grsecurity support