-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Closed
Labels
Description
I installed Asahi Linux on my M1 Mac Mini. Note that Asahi Linux is a 16 KiB page system.
#include <stdio.h>
extern char _GLOBAL_OFFSET_TABLE_;
int main() {
printf("Hello world\n");
_GLOBAL_OFFSET_TABLE_ = 3;
}
If I run the above program, it should crash because it writes to .got
and .got
should be protected by GNU_RELRO. However, it doesn't actually crash.
$ clang -fuse-ld=/home/ruiu/llvm-project/build/bin/ld.lld -o hello hello.c
$ ./hello
Hello world
I believe it is because RELRO does not end at a page boundary and therefore the last page in the RELRO isn't protected. As you can see, the RELRO in the executable ends at 0x21000, not at 0x30000.
$ readelf --segments hello
Elf file type is DYN (Position-Independent Executable file)
Entry point 0x10780
There are 11 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x000268 0x000268 R 0x8
INTERP 0x0002a8 0x00000000000002a8 0x00000000000002a8 0x00001b 0x00001b R 0x1
[Requesting program interpreter: /lib/ld-linux-aarch64.so.1]
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000750 0x000750 R 0x10000
LOAD 0x000780 0x0000000000010780 0x0000000000010780 0x0001d0 0x0001d0 R E 0x10000
LOAD 0x000950 0x0000000000020950 0x0000000000020950 0x0001f0 0x0001f0 RW 0x10000
LOAD 0x000b40 0x0000000000030b40 0x0000000000030b40 0x000048 0x000049 RW 0x10000
DYNAMIC 0x000960 0x0000000000020960 0x0000000000020960 0x0001b0 0x0001b0 RW 0x8
GNU_RELRO 0x000950 0x0000000000020950 0x0000000000020950 0x0001f0 0x0006b0 R 0x1
GNU_EH_FRAME 0x000644 0x0000000000000644 0x0000000000000644 0x00003c 0x00003c R 0x4
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0
NOTE 0x0002c4 0x00000000000002c4 0x00000000000002c4 0x000038 0x000038 R 0x4