From: Mark Wielaard <mark@klomp.org>
To: gavin@matician.com, elfutils-devel@sourceware.org
Subject: Re: [PATCH] libdwfl: Read no more than required to parse dynamic sections
Date: Tue, 29 Nov 2022 16:25:36 +0100 [thread overview]
Message-ID: <70c0b7df5c6b38492a0655c0ff552453d9dc1f5d.camel@klomp.org> (raw)
In-Reply-To: <20221129062653.298772-1-gavin@matician.com>
Hi Gavin,
On Mon, 2022-11-28 at 22:26 -0800, gavin@matician.com wrote:
> 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.
I don't fully follow this logic.
The code as written doesn't seem to guarantee that
dwfl_segment_report_module will always be called with
dwfl_elf_phdr_memory_callback as memory_callback. Although it probably
will be in practice.
So you are removing this check:
> && ! 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;
> -
Reading read_portion it shows dyn_data_size being set to zero if
read_state->buffer_available has everything (dyn_filesz) requested.
Otherwise memory_callback (we assume dwfl_elf_phdr_memory_callback) is
called with *data_size = dyn_filesz. Which will then be set to the
actual buffer size being read.
So dyn_data_size might be bigger than the dynfilesz we are requesting?
Or smaller I assume.
If you are protecting against it becoming bigger, should the check be
changed to:
if (dyn_data_size != 0 && dyn_data_size < dyn_filesz)
dyn_filesz = dyn_data_size;
?
Thanks,
Mark
next prev parent reply other threads:[~2022-11-29 15:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 6:26 gavin
2022-11-29 15:25 ` Mark Wielaard [this message]
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=70c0b7df5c6b38492a0655c0ff552453d9dc1f5d.camel@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
--cc=gavin@matician.com \
/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).