Skip to content

Commit

Permalink
Future safety in checking ELF header.
Browse files Browse the repository at this point in the history
If we should use further fields in the e_ident array in the ELF header
of files we want zero to mean the default.  Enforce zero for now so
that non-optional features indicated by nonzero values are not go
unnoticed when using an old dynamic linker.
  • Loading branch information
Ulrich Drepper committed Mar 18, 2010
1 parent b170ff0 commit 04f2902
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-03-18 Ulrich Drepper <drepper@redhat.com>

* elf/dl-load.c (open_verify): Extend expected to the full size of the
e_ident array. When loading, check that the fields in e_ident we don't
know are zero to allow future extensions.

2010-03-18 H.J. Lu <hongjiu.lu@intel.com>

* sysdeps/i386/i686/multiarch/memcmp-ssse3.S: Update %xmm3
Expand Down
10 changes: 8 additions & 2 deletions elf/dl-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ open_verify (const char *name, struct filebuf *fbp, struct link_map *loader,
#elif defined MORE_ELF_HEADER_DATA
MORE_ELF_HEADER_DATA;
#endif
static const unsigned char expected[EI_PAD] =
static const unsigned char expected[EI_NIDENT] =
{
[EI_MAG0] = ELFMAG0,
[EI_MAG1] = ELFMAG1,
Expand Down Expand Up @@ -1657,7 +1657,10 @@ open_verify (const char *name, struct filebuf *fbp, struct link_map *loader,
if (__builtin_expect (! VALID_ELF_HEADER (ehdr->e_ident, expected,
EI_ABIVERSION)
|| !VALID_ELF_ABIVERSION (ehdr->e_ident[EI_OSABI],
ehdr->e_ident[EI_ABIVERSION]),
ehdr->e_ident[EI_ABIVERSION])
|| memcmp (&ehdr->e_ident[EI_PAD],
&expected[EI_PAD],
EI_NIDENT - EI_PAD) != 0,
0))
{
/* Something is wrong. */
Expand Down Expand Up @@ -1701,6 +1704,9 @@ open_verify (const char *name, struct filebuf *fbp, struct link_map *loader,
else if (!VALID_ELF_ABIVERSION (ehdr->e_ident[EI_OSABI],
ehdr->e_ident[EI_ABIVERSION]))
errstring = N_("ELF file ABI version invalid");
else if (memcmp (&ehdr->e_ident[EI_PAD], &expected[EI_PAD],
EI_NIDENT - EI_PAD) != 0)
errstring = N_("nonzero padding in e_ident");
else
/* Otherwise we don't know what went wrong. */
errstring = N_("internal error");
Expand Down

0 comments on commit 04f2902

Please sign in to comment.