* [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section
@ 2020-04-14 13:28 H.J. Lu
2020-04-14 13:28 ` [PATCH 2/2] readelf: Warn if DT_XXX don't match .dynsym/.dynstr sections H.J. Lu
2020-04-14 13:53 ` [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section Jan Beulich
0 siblings, 2 replies; 4+ messages in thread
From: H.J. Lu @ 2020-04-14 13:28 UTC (permalink / raw)
To: binutils
The PT_DYNAMIC segment, which is used by the run-time loader, must
exactly match the .dynamic section.
PR binutils/25809
* readelf.c (process_program_headers): Warn if the PT_DYNAMIC
segment doesn't match the .dynamic section.
---
binutils/readelf.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 535d47a58e..91e47887e7 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -5337,13 +5337,12 @@ process_program_headers (Filedata * filedata)
dynamic_addr = sec->sh_offset;
dynamic_size = sec->sh_size;
- if (dynamic_addr < segment->p_offset
- || dynamic_addr > segment->p_offset + segment->p_filesz)
- warn (_("the .dynamic section is not contained"
- " within the dynamic segment\n"));
- else if (dynamic_addr > segment->p_offset)
- warn (_("the .dynamic section is not the first section"
- " in the dynamic segment.\n"));
+ /* The PT_DYNAMIC segment, which is used by the run-time
+ loader, must exactly match the .dynamic section. */
+ if (dynamic_addr != segment->p_offset
+ || dynamic_size != segment->p_filesz)
+ warn (_("the .dynamic section doesn't match the "
+ "dynamic segment\n"));
}
/* PR binutils/17512: Avoid corrupt dynamic section info in the
--
2.25.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] readelf: Warn if DT_XXX don't match .dynsym/.dynstr sections
2020-04-14 13:28 [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section H.J. Lu
@ 2020-04-14 13:28 ` H.J. Lu
2020-04-14 13:53 ` [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section Jan Beulich
1 sibling, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2020-04-14 13:28 UTC (permalink / raw)
To: binutils
DT_SYMTAB, DT_SYMENT, DT_STRTAB and DT_STRSZ, which are used by the
run-time loader, must match the .dynsym and .dynstr sections.
PR binutils/25809
* readelf.c (dynamic_symtab_section): New.
(dynamic_strtab_section): Likewise.
(process_section_headers): Set dynamic_symtab_section to the
.dynsym section. Set dynamic_strtab_section to the .dynstr
section.
(process_dynamic_section): Warn if the .dynsym section doesn't
match DT_SYMTAB and DT_SYMENT or the .dynstr section doesn't
DT_STRTAB and DT_STRSZ.
---
binutils/readelf.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 91e47887e7..fc1749e862 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -246,6 +246,8 @@ static bfd_vma dynamic_info_DT_GNU_HASH;
static bfd_vma dynamic_info_DT_MIPS_XHASH;
static bfd_vma version_info[16];
static Elf_Internal_Dyn * dynamic_section;
+static Elf_Internal_Shdr * dynamic_symtab_section;
+static Elf_Internal_Shdr * dynamic_strtab_section;
static elf_section_list * symtab_shndx_list;
static bfd_boolean show_name = FALSE;
static bfd_boolean do_dynamic = FALSE;
@@ -6286,6 +6288,7 @@ process_section_headers (Filedata * filedata)
CHECK_ENTSIZE (section, i, Sym);
dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms);
+ dynamic_symtab_section = section;
}
else if (section->sh_type == SHT_STRTAB
&& streq (name, ".dynstr"))
@@ -6300,6 +6303,7 @@ process_section_headers (Filedata * filedata)
1, section->sh_size,
_("dynamic strings"));
dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
+ dynamic_strtab_section = section;
}
else if (section->sh_type == SHT_SYMTAB_SHNDX)
{
@@ -10291,6 +10295,15 @@ process_dynamic_section (Filedata * filedata)
section.sh_size = (num_of_syms
* dynamic_info[DT_SYMENT]);
section.sh_entsize = dynamic_info[DT_SYMENT];
+ if (dynamic_symtab_section
+ && ((dynamic_symtab_section->sh_offset
+ != section.sh_offset)
+ || (dynamic_symtab_section->sh_size
+ != section.sh_size)
+ || (dynamic_symtab_section->sh_entsize
+ != section.sh_entsize)))
+ warn (_("the .dynsym section doesn't match "
+ "DT_SYMTAB and DT_SYMENT\n"));
section.sh_name = filedata->string_table_length;
dynamic_symbols = GET_ELF_SYMBOLS (filedata,
§ion,
@@ -10326,6 +10339,13 @@ process_dynamic_section (Filedata * filedata)
offset = offset_from_vma (filedata,
dynamic_info[DT_STRTAB],
str_tab_len);
+ if (dynamic_strtab_section
+ && ((dynamic_strtab_section->sh_offset
+ != (file_ptr) offset)
+ || (dynamic_strtab_section->sh_size
+ != str_tab_len)))
+ warn (_("the .dynstr section doesn't match DT_STRTAB "
+ "and DT_STRSZ\n"));
dynamic_strings = (char *) get_data (NULL, filedata, offset, 1,
str_tab_len,
_("dynamic string table"));
--
2.25.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section
2020-04-14 13:28 [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section H.J. Lu
2020-04-14 13:28 ` [PATCH 2/2] readelf: Warn if DT_XXX don't match .dynsym/.dynstr sections H.J. Lu
@ 2020-04-14 13:53 ` Jan Beulich
2020-04-14 13:57 ` H.J. Lu
1 sibling, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2020-04-14 13:53 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On 14.04.2020 15:28, H.J. Lu via Binutils wrote:
> The PT_DYNAMIC segment, which is used by the run-time loader, must
> exactly match the .dynamic section.
Here as well as in patch 2 I'd say "should" instead of "must", and
again I don't think such warnings should be issued by default.
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section
2020-04-14 13:53 ` [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section Jan Beulich
@ 2020-04-14 13:57 ` H.J. Lu
0 siblings, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2020-04-14 13:57 UTC (permalink / raw)
To: Jan Beulich; +Cc: Binutils
On Tue, Apr 14, 2020 at 6:53 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 14.04.2020 15:28, H.J. Lu via Binutils wrote:
> > The PT_DYNAMIC segment, which is used by the run-time loader, must
> > exactly match the .dynamic section.
>
> Here as well as in patch 2 I'd say "should" instead of "must", and
> again I don't think such warnings should be issued by default.
I will change the wording. When they do mismatch, it is an indication
of corrupt binary. I think users should know about it.
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-14 13:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14 13:28 [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section H.J. Lu
2020-04-14 13:28 ` [PATCH 2/2] readelf: Warn if DT_XXX don't match .dynsym/.dynstr sections H.J. Lu
2020-04-14 13:53 ` [PATCH 1/2] readelf: Warn if PT_DYNAMIC segment doesn't match .dynamic section Jan Beulich
2020-04-14 13:57 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).