public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libelf: Correct ELF64 section offset check in file_read_elf.
@ 2014-12-11 15:37 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2014-12-11 15:37 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

The ELF64 case didn't check for overflow and accidentially used the 32bit
Shdr size.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libelf/ChangeLog   | 4 ++++
 libelf/elf_begin.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index e4c5849..cf168e7 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,9 @@
 2014-12-11  Mark Wielaard  <mjw@redhat.com>
 
+	* elf_begin.c (file_read_elf): Correct ELF64 section offset check.
+
+2014-12-11  Mark Wielaard  <mjw@redhat.com>
+
 	* elf_begin.c (read_long_names): Check for offset overflow.
 	(__libelf_next_arhdr_wrlock): Likewise. Sanity check the ar_size.
 	Don't allow it to go beyond end of file.
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 99a9c0a..7fb5fa5 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -412,8 +412,8 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
 	  elf->state.elf64.ehdr = ehdr;
 
 	  if (unlikely (ehdr->e_shoff >= maxsize)
-	      || unlikely (ehdr->e_shoff
-			   + scncnt * sizeof (Elf32_Shdr) > maxsize))
+	      || unlikely (maxsize - ehdr->e_shoff
+			   < scncnt * sizeof (Elf64_Shdr)))
 	    goto free_and_out;
 	  elf->state.elf64.shdr
 	    = (Elf64_Shdr *) ((char *) ehdr + ehdr->e_shoff);
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libelf: Correct ELF64 section offset check in file_read_elf.
@ 2014-12-15  9:05 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2014-12-15  9:05 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 304 bytes --]

On Thu, 2014-12-11 at 16:37 +0100, Mark Wielaard wrote:
> The ELF64 case didn't check for overflow and accidentially used the 32bit
> Shdr size.
>
>  2014-12-11  Mark Wielaard  <mjw@redhat.com>
>  
> +	* elf_begin.c (file_read_elf): Correct ELF64 section offset check.

I pushed this to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-15  9:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-11 15:37 [PATCH] libelf: Correct ELF64 section offset check in file_read_elf Mark Wielaard
2014-12-15  9:05 Mark Wielaard

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).