Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

dynamic loading and random address

 
   Soft32 Home -> Linux -> System Development RSS
Next:  [News] [Rival] Microsoft Expected to Use Politici..  
Author Message
Xend

External


Since: Nov 24, 2008
Posts: 3



(Msg. 1) Posted: Sat Jul 11, 2009 12:58 am
Post subject: dynamic loading and random address
Archived from groups: comp>os>linux>development>system (more info?)

question:
why the address of "libc" dynamic loaded is random?
how and when the random is generate???
thanks

$ cat address_random.sh
#! /usr/bin/env bash

while [ 1 ]
do
sleep 3 &
#print address of libc text segment.
pmap $(pidof sleep | awk '{print $1}') | \
awk '($3 == "r-x--") && ($4 ~ /\/libc-.*\.so$/) {print $1; exit}'
wait %1

$ uname -a
Linux hesen 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:58:03 UTC
2009 x86_64 GNU/Linux

$ ./address_random.sh #random address
00007f10843ae000
00007f16dd467000
00007f056d011000
Back to top
Login to vote
John Reiser

External


Since: Mar 08, 2009
Posts: 12



(Msg. 2) Posted: Sat Jul 11, 2009 9:20 am
Post subject: Re: dynamic loading and random address [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> why the address of "libc" dynamic loaded is random?
> how and when the random is generate???

The address is randomized in order to make it harder to predict.
This offers some defense against simple malware (successfully coping
with the randomness typically requires additional code in the malware)
and helps reduce some programming errors ("accidental" relationships
between addresses tend not to persist.)

As originally built, nearly all shared libraries have 0==Elf32_Phdr.p_vmaddr.
The code to map a shared library into the address space does
mmap(phdr->p_vmaddr, phdr->p_filesz, ...)
Upon seeing
mmap(0, length, ...)
then the operating system may choose any page-aligned initial address
such that the interval [addr, length + addr) is not yet occupied.
In this case the source of the randomness is the operating sytsem kernel.

There are some efficiencies available (less time and space required
for relocation processing during the invocation of the shared library)
if the addresses of the needed shared libraries have been decided in advance.
The utility program 'prelink' assigns addresses in advance according
to its preferences: no overlap among commonly-used sets of libraries, etc.
Prelink does its job by setting the .p_vmaddr. Upon seeing
mmap(addr, length, ...)
with 0!=addr, then the operating system kernel usually _prefers_
to assign the specified address, but still is permitted to choose some
other address if the interval [addr, length + addr) is not entirely
empty, or for any other reason. [This choice can be inhibited by
the flag bit MAP_FIXED.] In the case of a pre-linked shared library,
then the source of the randomness is prelink. Often prelink
is run periodically (for example, once per day or once per week)
to "re-shuffle" the addresses.

--
Back to top
Login to vote
Display posts from previous:   
Related Topics:
RFC3971 - Does anyone know if RFC3971 support is being developed for Linux? It does not seem to be implemented in the mainline..

Size 8 bit, 16 bit, 32 bit and 64 bit systems. - I need to find out what is the size of following data structures in 8 bit, 16 bit, 32 bit, and 64 bit systems. struct....

Size 8 bit, 16 bit, 32 bit and 64 bit systems. - I need to find out what is the size of following data structures in 8 bit, 16 bit, 32 bit, and 64 bit systems. struct....

Access shared memory from kernel module - Hi All, I wanted to know if shared memory created in user space can be accessed from a loadable kernel module. Have no...

Controlling UART transmission of bytes - I'm programming an ARM's UART that comes with a library implementing the standard unix termios interface. Regarding..

[PATCH] blackfin arch PNAV and Bluetechnix CM-BF537 use th.. - Signed-off-by: Bryan Wu <bryan.wu@analog.com> --- arch/blackfin/mach-bf537/boards/eth_mac.c | 5 ++--- 1 file...
       Soft32 Home -> Linux -> System Development All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]