public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: gavin@matician.com
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>, Gavin Li <gavin@matician.com>
Subject: [PATCH] libdwfl: Read no more than required to parse dynamic sections
Date: Mon, 28 Nov 2022 22:26:53 -0800	[thread overview]
Message-ID: <20221129062653.298772-1-gavin@matician.com> (raw)

From: Gavin Li <gavin@matician.com>

Since size checking has been moved to dwfl_elf_phdr_memory_callback(),
there is no longer a need for dwfl_segment_report_module() to enforce
the same. Reading beyond the end of the dynamic section actually causes
issues when passing the data to elfXX_xlatetom() because it is possible
that src->d_size is not a multiple of recsize (for ELF_T_DYN, recsize is
16 while the minimum required alignment is 8), causing elfXX_xlatetom()
to return ELF_E_INVALID_DATA.

Signed-off-by: Gavin Li <gavin@matician.com>
---
 libdwfl/dwfl_segment_report_module.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 287fc002..08aca0eb 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -821,12 +821,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       && ! read_portion (&read_state, &dyn_data, &dyn_data_size,
 			 start, segment, dyn_vaddr, dyn_filesz))
     {
-      /* dyn_data_size will be zero if we got everything from the initial
-         buffer, otherwise it will be the size of the new buffer that
-         could be read.  */
-      if (dyn_data_size != 0)
-	dyn_filesz = dyn_data_size;
-
       if ((dyn_filesz / dyn_entsize) == 0
 	  || dyn_filesz > (SIZE_MAX / dyn_entsize))
 	goto out;
-- 
2.38.1


             reply	other threads:[~2022-11-29  6:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29  6:26 gavin [this message]
2022-11-29 15:25 ` Mark Wielaard
2022-11-29 21:48   ` Gavin Li
2022-11-30 23:14     ` Mark Wielaard
2022-12-01 21:13       ` Gavin Li
2022-12-13 16:49         ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221129062653.298772-1-gavin@matician.com \
    --to=gavin@matician.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).