1 |
On Thu, Aug 27, 2015 at 03:02:59PM +0200, François wrote: |
2 |
> this is my first message here, I hope I'm not off-topic! |
3 |
> |
4 |
> I've been reading [1], and tried on my gentoo system: |
5 |
> |
6 |
> fser@regal /tmp$ ./aslr-test-without |
7 |
> main @ 0x4005da |
8 |
> doit @ 0x40059b |
9 |
> fser@regal /tmp$ ./aslr-test-without |
10 |
> main @ 0x4005da |
11 |
> doit @ 0x40059b |
12 |
> fser@regal /tmp$ ./aslr-test-without |
13 |
> main @ 0x4005da |
14 |
> doit @ 0x40059b |
15 |
> |
16 |
> |
17 |
> and |
18 |
> |
19 |
> fser@regal /tmp$ ./aslr-test-withpie |
20 |
> main @ 0x468f410820 |
21 |
> doit @ 0x468f4107e1 |
22 |
> fser@regal /tmp$ ./aslr-test-withpie |
23 |
> main @ 0x6d8a0f9820 |
24 |
> doit @ 0x6d8a0f97e1 |
25 |
> fser@regal /tmp$ ./aslr-test-withpie |
26 |
> main @ 0x33eb5d8820 |
27 |
> doit @ 0x33eb5d87e1 |
28 |
> fser@regal /tmp$ ./aslr-test-withpie |
29 |
> main @ 0x769c4a5820 |
30 |
> doit @ 0x769c4a57e1 |
31 |
> |
32 |
> I was under the impression that ASLR was enforced by the kernel, when |
33 |
> creating a new context for a process. |
34 |
> Reading the description of [1], I was expecting the adress of main (at |
35 |
> least) to be different. |
36 |
> |
37 |
> Can someone explain me this behavior? |
38 |
|
39 |
ASLR only works properly with binaries that use Position Independent Code. That |
40 |
means that the generated machine code does not hardcode any (virtual) |
41 |
addresses, instead uses relative addressing. Some information about this is |
42 |
at |
43 |
https://wiki.gentoo.org/wiki/Hardened/Introduction_to_Position_Independent_Code |
44 |
but the page can benefit from some clean-ups and editing. |
45 |
|
46 |
With ASLR, applications are given a random base address. With non-PIC |
47 |
applications, this doesn't matter as the base address is hardly used. The |
48 |
code has hardcoded locations anyway, so the (randomized) base address is |
49 |
ignored. |
50 |
|
51 |
Wkr, |
52 |
Sven Vermeulen |