Skip to content

Commit

Permalink
Fix startup to security-relevant statically linked binaries.
Browse files Browse the repository at this point in the history
Before the change they crash on startup.  Perform IREL relocations
earlier to prevent this.

(cherry picked from commit 1c3c269)
  • Loading branch information
Ulrich Drepper authored and Petr Baudis committed Dec 4, 2009
1 parent b15f34a commit 4f9d265
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2009-11-24 Ulrich Drepper <drepper@redhat.com>

* csu/elf-init.c (__libc_csu_irel): New function. Code to perform
irel relocations split out from...
(__libc_csu_init): ...here.
* csu/libc-start.c [!SHARED]: Call __libc_csu_irel early.

2009-11-22 Ulrich Drepper <drepper@redhat.com>

* sunrpc/create_xid.c (_create_xid): Reinitialize state after fork.
Expand Down
21 changes: 15 additions & 6 deletions csu/elf-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ extern void _fini (void);
/* These functions are passed to __libc_start_main by the startup code.
These get statically linked into each program. For dynamically linked
programs, this module will come from libc_nonshared.a and differs from
the libc.a module in that it doesn't call the preinit array. */
the libc.a module in that it doesn't call the preinit array and performs
explicit IREL{,A} relocations. */

void
__libc_csu_init (int argc, char **argv, char **envp)
{
/* For dynamically linked executables the preinit array is executed by
the dynamic linker (before initializing any shared object. */

#ifndef LIBC_NONSHARED
void
__libc_csu_irel (void)
{
# ifdef USE_MULTIARCH
# ifdef ELF_MACHINE_IRELA
{
Expand All @@ -98,7 +97,17 @@ __libc_csu_init (int argc, char **argv, char **envp)
}
# endif
# endif
}
#endif


void
__libc_csu_init (int argc, char **argv, char **envp)
{
/* For dynamically linked executables the preinit array is executed by
the dynamic linker (before initializing any shared object. */

#ifndef LIBC_NONSHARED
/* For static executables, preinit happens right before init. */
{
const size_t size = __preinit_array_end - __preinit_array_start;
Expand Down
6 changes: 6 additions & 0 deletions csu/libc-start.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <bp-sym.h>

extern void __libc_init_first (int argc, char **argv, char **envp);
#ifndef SHARED
extern void __libc_csu_irel (void);
#endif

extern int __libc_multiple_libcs;

Expand Down Expand Up @@ -134,6 +137,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
}
# endif

/* Performe IREL{,A} relocations. */
__libc_csu_irel ();

/* Initialize the thread library at least a bit since the libgcc
functions are using thread functions if these are available and
we need to setup errno. */
Expand Down

0 comments on commit 4f9d265

Please sign in to comment.