||It has been suggested that this article be merged with Prebinding. (Discuss) Proposed since October 2011.|
|This article relies on references to primary sources. (March 2011)|
||This article needs additional citations for verification. (March 2010)|
prelink is a free program written by Jakub Jelínek of Red Hat for POSIX-compliant operating systems, principally Linux (because it modifies ELF executables). It is intended to speed up a system by reducing the time a program needs to begin. Actual results have been mixed, but it seems to aid systems with a large number of libraries, such as KDE.
Most programs require libraries to function. Libraries can be integrated into a program once, by a linker, when it is compiled (static linking) or they can be integrated when the program is run by a loader, (dynamic linking). Dynamic linking has advantages in code size and management, but every time a program is run, the loader needs to find the relevant libraries. Because the libraries can move around in memory, this causes a performance penalty, and the more libraries that need to be resolved, the greater the penalty. prelink reduces this penalty by using the system's dynamic linker to reversibly perform this linking in advance ("prelinking" the executable file) by relocating. Afterward, the program only needs to spend time finding the relevant libraries on being run if, for some reason (perhaps an upgrade), the libraries have changed since being prelinked.
prelink will (when run with the "-R" option) randomly select the address base that libraries are loaded at. This makes it more difficult to perform a return-to-libc attack on the system, because the addresses used are unique to that system. The reason prelink does this is because kernel facilities supplying address space layout randomization for libraries cannot be used in conjunction with prelink without defeating the purpose of prelink and forcing the dynamic linker to perform relocations at program load time.
As stated, prelink and per-process library address randomization cannot be used in conjunction. In order to avoid completely removing this security enhancement, prelink supplies its own randomization; however, this does not help a general information leak caused by prelink. Attackers with the ability to read certain arbitrary files on the target system can discover where libraries are loaded in privileged daemons; often libc is enough as it is the most common library used in return-to-libc attacks.
By reading a shared library file such as libc, an attacker with local access can discover the load address of libc in every other application on the system. Since most programs link to libc, the libc library file always has to be readable; any attacker with local access may gather information about the address space of higher privileged processes. Local access may commonly be gained by shell accounts or Web server accounts that allow the use of CGI scripts, which may read and output any file on the system. Directory traversal vulnerabilities can be used by attackers without accounts if CGI script vulnerabilities are available.
Because prelink is often run periodically, typically every two weeks, the address of any given library has a chance of changing over time. prelink is often used in an incremental mode in which already prelinked libraries are not altered unless absolutely necessary, so a library may not change its base address when prelink is re-run. This gives any address derived a half-life of the period in which prelink is run. Also note that if a new version of the library is installed, the addresses change.
Jakub Jelínek points out that position independent executables ignore prelinking on Red Hat Enterprise Linux and Fedora Core, and recommends that network and SUID programs be built PIE to facilitate a more secure environment.
Possible Issues 
Occasionally prelinking can cause issues with application checkpoint and restart libraries like blcr, as well as other libraries (like OpenMPI) that use blcr internally. Specifically when checkpointing a program on one host, and trying to restart on a different host, the restarted program may fail with a segfault due to differences in host-specific library memory address randomization. 
See also 
- James Crasta (2004-05-17). "ELF Prelinking and what it can do for you". Retrieved 2006-05-10.
- "BLCR FAQ". Retrieved 2012-01-05.
- Hursey, Josh (2011-12-29). "segfault when resuming on different host". OpenMPI Users mailing list. http://www.open-mpi.org/community/lists/users/2011/12/18071.php. Retrieved 2012-01-05.
Further reading 
- Jakub Jelínek (2004-03-04). Prelink. Draft 0.7. Retrieved 2006-07-14.
- Linux Administration and Privileged Commands Manual : prelink ELF shared libraries and binaries to speed up startup time –
- Quintin Riis (2008-06-15). "Speed up application load time in Ubuntu Linux Hardy Heron using prelink: HOWTO and benchmarks (mention in ubuntuforums/original link is dead)". Retrieved 2008-08-22.
- Stefan Jones (2007-04-02). "Gentoo Linux Prelink Guide". Retrieved 2006-05-10.
- John Richard Moser (2006-07-05). "Prelink and Address Space Randomization". Retrieved 2006-07-13.