Make gelf_getphdr more robust?
by Florian Weimer
readelf does this:
GElf_Phdr *phdr = gelf_getphdr (ebl->elf, cnt, &mem);
…
if (phdr->p_type == PT_INTERP)
{
/* We can show the user the name of the interpreter. */
size_t maxsize;
char *filedata = elf_rawfile (ebl->elf, &maxsize);
if (filedata != NULL && phdr->p_offset < maxsize)
printf (gettext ("\t[Requesting program interpreter: %s]\n"),
filedata + phdr->p_offset);
}
The check against maxsize is insufficient, it's also required to check
that phdr->p_filesz <= maxsize - phdr->p_offset. Would it make sense to
do both checks inside gelf_getphdr?
And the printf call can leak data or crash if filedata + phdr->p_offset
is not NUL terminated (which obviously needs a crafted ELF file). This
can't be fixed in gelf_getphdr, alas.
--
Florian Weimer / Red Hat Product Security Team
10 years, 2 months
incorrect signed data
by Josh Stone
Hi,
I was just investigating some signed-value inconsistencies I found
between libdwarf and libdw, while working on a little experiment[1]. I
think elfutils is actually handling dwarf_formsdata incorrectly.
Libdwarf doesn't have dwarf_decl_line et al., so I was coding that bit
manually, but I got some negative values from dwarf_formsdata. An
example raw attr is data1 0xb5, which gave me -75.
DWARF4 section 7.5.4 states that values of data1/2/4/8 may be signed or
unsigned integers, or anything else depending on context. So when
libdwarf's dwarf_formsdata treats 0xb5 as signed for -75, I think that's
the proper interpretation of context. On the other hand, libdw's
dwarf_formsdata does "*return_sval = *attr->valp", which in C's
promotion rules will not sign-extend! (from unsigned char to int64_t)
So libdw's dwarf_formsdata reads 0xb5 as 179. The rest of data2/4/8 are
using read_2/4/8ubyte_unaligned, which is also wrong IMO.
DWARF4 section 2.14 states that DW_AT_decl_file/line/column are all
unsigned constants, but dwarf_decl_line/column (and _file internally)
are treating these as signed values, using dwarf_formsdata. I think
they're just lucky that this isn't getting sign-extended, but really
these functions should be using dwarf_formudata.
So:
- dwarf_formsdata ought to sign-extend small data.
- dwarf_decl_file/line/column should use dwarf_formudata.
Thoughts?
Josh
[1] https://github.com/cuviper/nontrivial-param
10 years, 2 months
[PATCH] configure: add a --disable-werror option
by Mike Frysinger
Building with -Werror makes a lot of sense for development, but not a lot
for distro deployments. Changes in default flag settings, versions of the
compiler or C library, or 3rd party libraries can easily trigger harmless
warnings that are a waste of time to track down. Especially when elfutils
itself enables many extra -W flags. So add a configure flag for distros
to utilize when building.
Signed-off-by: Mike Frysinger <vapier(a)gentoo.org>
---
ChangeLog | 5 +++++
config/eu.am | 2 +-
configure.ac | 8 ++++++++
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index a0ce570..3ccd2a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-02 Mike Frysinger <vapier(a)gentoo.org>
+
+ * configure.ac: Add --disable-werror flag. Export WERROR.
+ * config/eu.am (AM_CFLAGS): Change -Werror to $(WERROR).
+
2013-12-20 Mark Wielaard <mjw(a)redhat.com>
* NEWS (libdwfl): Add dwfl_getthread_frames.
diff --git a/config/eu.am b/config/eu.am
index 38718c7..220c843 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -32,7 +32,7 @@
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"'
AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I..
AM_CFLAGS = -std=gnu99 -Wall -Wshadow \
- $(if $($(*F)_no_Werror),,-Werror) \
+ $(if $($(*F)_no_Werror),,$(WERROR)) \
$(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
$(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) \
$($(*F)_CFLAGS)
diff --git a/configure.ac b/configure.ac
index 72fb3e8..f0fe890 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,14 @@ AC_CONFIG_FILES([elfutils.spec:config/elfutils.spec.in])
AC_CANONICAL_HOST
+AC_ARG_ENABLE(werror,
+[AS_HELP_STRING([--disable-werror],
+ [turn off -Werror @<:@default=enabled@:>@])])
+if test "x$enable_werror" != "xno"; then
+ WERROR="-Werror"
+fi
+AC_SUBST(WERROR)
+
AC_ARG_ENABLE(deterministic-archives,
[AS_HELP_STRING([--enable-deterministic-archives],
[ar and ranlib default to -D behavior])], [
--
1.8.4.3
10 years, 2 months
Some stuff for 0.159+
by Mark Wielaard
Hi,
The last release had lots of new features. I don't have any grand plans
for the next release. I was mostly going to spend time on bug fixing and
cleanups. The following items is just what I personally wanted to spend
some time on. I don't think everything below makes it for the next
release (0.159 lets say somewhere in March). And I might have forgotten
stuff. But it is probably what I will spend some time on next.
- Bugs, there are more, but these two were what I wanted to at least
look at:
https://bugzilla.redhat.com/show_bug.cgi?id=1037051
elfutils FTBFS if "-Werror=format-security" flag is used
Currently we just remove that flag, but if we can rewrite the code to
enable it by default for all files that would be nice. Dunno if that
is really possible in all cases though.
https://bugzilla.redhat.com/show_bug.cgi?id=1020842
libelf: segment fault on x86-64
while file's bss offset have a large
number
This slipped through the cracks, there has even been a patch proposed
on the list:
http://thread.gmane.org/gmane.comp.sysutils.elfutils.devel/3181
And lets see what else people report.
https://bugzilla.redhat.com/buglist.cgi?bug_status=NEW&component=elfutils
- Merge robustify commits to master if they make sense.
And look at the portable branch patches suggested by Mike Frysinger
https://lists.fedorahosted.org/pipermail/elfutils-devel/2014-January/0036...
- Move .gnu_debugaltlink handling from libdw to libdwfl and make
ENABLE_DWZ the default. As discussed before:
https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-December/003...
- string functions (this would be a new feature). I abandoned this since
it was a lot of work for such a small feature and we were right before
a release. But I keep writing code that would be much easier if we had
string functions for the common DWARF constants. This would resurrect:
https://git.fedorahosted.org/cgit/elfutils.git/log/?h=mjw/dwarfstrings
- speedup/cache __libdwfl_addrsym. This is the main reason eu-readelf
(without -N) and to a lesser extend eu-stack (without -q) is so slow.
They do address lookups without any caching, so they potentially need
to search through all of them each time. It has been discussed before.
https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-July/003126....
Needs lots of testing to make sure the results returned are equal.
- Jan's idea to use /proc/PID/map_files when available seems very
attractive:
https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-December/003...
As an alternative fallback we can try to reuse the technique we are
already using in dwfl_linux_proc_find_elf for extracting the vdso
through getting the in-memory ELF image from the target process.
I got this working through some ugly hacks. elf_from_remote_memory
does work for the vdso, but not always for other images. That code
needs to be cleaned up and we need to find a way to pass information
about the target pid from the dwfl_linux_proc_report callback to the
dwfl_linux_proc_find_elf callback (or maybe introduce new report and
find_elf callbacks for this functionality).
- unwinder backends for aarch64 and arm7hl
- aarch64 is mostly there on my branch
https://git.fedorahosted.org/cgit/elfutils.git/log/?h=mjw/aarch64-unwind
But needs actual testing and last time I played with it glibc didn't
seem to properly mark _start and _clone causing the link register to
point to the current pc and gcc didn't always seem to
produce .eh_frame for all functions. So might need some interaction
with the rest of the toolchain to make sure everything is correct.
- arm32 might be a bit tricky. When there is a .debug_frame it should
be simple. If not, then we might just give up for now. Or add a
EXIDX to CFI translator fallback to the backend.
- Maybe tweak the defaults for eu-stack based on feedback.
Maybe use more debug information than just the line numbers if
available (e.g. use the subprogram or inlined_subroutine names for the
addresses found).
Not all the above might make it before 0.159, and maybe some other stuff
that I forgot about pops up, but it is a start and should keep me busy
till March. And of course we can push out a new release earlier if some
really nasty regressions/bugs are found and fixed before that.
Cheers,
Mark
10 years, 2 months