From: Petr Machata <pmachata@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: out-of-bounds read / crash in elfutils tools (readelf, nm, ...) with malformed file
Date: Tue, 11 Nov 2014 14:30:32 +0100 [thread overview]
Message-ID: <m2d28tzwxz.fsf@redhat.com> (raw)
In-Reply-To: 20141111113130.6774958b@pc
[-- Attachment #1: Type: text/plain, Size: 3353 bytes --]
Hanno Böck <hanno@hboeck.de> writes:
> I can't build elfutils git head with -m32 right now at all (likely
> another bug? was possible a few days ago), so I can't test, but we can
> probably assume that it was due to the systemwide libs it used.
That would be my fault. Is the following fix acceptable?
Subject: [PATCH] Fix compilation on x86
GCC finds two problems when compiling in 32-bit mode.
- First, the function __libdw_getsrclines is marked as internal only
in the header, not in the C file, and in 32-bit mode, this is
actually reported as a change in prototype.
- Second, address size is passed as a four-byte unsigned quantity, and
GCC can't prove that it's safe to compare it with a four-byte signed
quantity that is the result of pointer subtraction. This is not a
problem in 64-bit mode, where the 4-byte unsigned quantity can be
losslessly converted to an 8-byte signed pointer difference. But
passing address size in a 4-byte type is overly generous, so revert
back to uint8_t, like what CU's actually store.
Signed-off-by: Petr Machata <pmachata@redhat.com>
---
libdw/ChangeLog | 7 +++++++
libdw/dwarf_getsrclines.c | 6 +++---
libdw/libdwP.h | 2 +-
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d5796e8..0752566 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-11 Petr Machata <pmachata@redhat.com>
+
+ * libdwP.h (__libdw_getsrclines): Pass address_size as uint8_t.
+ * dwarf_getsrclines.c (read_srclines): Likewise.
+ (__libdw_getsrclines): Likewise. Also mark function as internal
+ here as well.
+
2014-09-10 Petr Machata <pmachata@redhat.com>
* dwarf_macro_getparamcnt.c: New file.
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index 4bb19c2..959c460 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -70,7 +70,7 @@ compare_lines (const void *a, const void *b)
static int
read_srclines (Dwarf *dbg,
const unsigned char *linep, const unsigned char *lineendp,
- const char *comp_dir, unsigned address_size,
+ const char *comp_dir, uint8_t address_size,
Dwarf_Lines **linesp, Dwarf_Files **filesp)
{
int res = -1;
@@ -729,9 +729,9 @@ files_lines_compare (const void *p1, const void *p2)
return 0;
}
-int
+internal_function int
__libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset,
- const char *comp_dir, unsigned address_size,
+ const char *comp_dir, uint8_t address_size,
Dwarf_Lines **linesp, Dwarf_Files **filesp)
{
struct files_lines_s fake = { .debug_line_offset = debug_line_offset };
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 5ccb13c..d798737 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -716,7 +716,7 @@ void __libdw_empty_loc_attr (Dwarf_Attribute *attr, struct Dwarf_CU *cu)
NULL) with loaded information. Returns 0 for success or a negative
value for failure. */
int __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset,
- const char *comp_dir, unsigned address_size,
+ const char *comp_dir, uint8_t address_size,
Dwarf_Lines **linesp, Dwarf_Files **filesp)
internal_function
__nonnull_attribute__ (1);
--
2.1.0
next reply other threads:[~2014-11-11 13:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-11 13:30 Petr Machata [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-11-13 21:55
2014-11-13 21:51 Mark Wielaard
2014-11-13 19:39
2014-11-13 14:45 Mark Wielaard
2014-11-11 16:57 Mark Wielaard
2014-11-11 13:57
2014-11-11 13:53 Mark Wielaard
2014-11-11 13:49 Petr Machata
2014-11-11 13:40
2014-11-11 13:15 Mark Wielaard
2014-11-11 10:31
2014-11-10 20:58 Mark Wielaard
2014-11-09 21:59
2014-11-09 16:57 Mark Wielaard
2014-11-08 16:10
2014-11-08 15:32 Mark Wielaard
2014-11-08 14:04 Mark Wielaard
2014-11-07 16:13
2014-11-07 15:45 Mark Wielaard
2014-11-07 15:32
2014-11-07 11:58 Mark Wielaard
2014-11-07 11:51 Mark Wielaard
2014-11-07 0:27
2014-11-06 18:25 Roland McGrath
2014-11-06 16:05 Mark Wielaard
2014-11-06 15:11 Mark Wielaard
2014-10-31 16:13
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=m2d28tzwxz.fsf@redhat.com \
--to=pmachata@redhat.com \
--cc=elfutils-devel@lists.fedorahosted.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).