Skip to content

Commit

Permalink
libdwfl: Sanity check partial core file data reads.
Browse files Browse the repository at this point in the history
There were two issues when reading note data from a core file.
We didn't check if the data we already had in a buffer was big
enough. And if we did get the data, we should check if we got
everything, or just a part of the data.

https://sourceware.org/bugzilla/show_bug.cgi?id=23752

Signed-off-by: Mark Wielaard <[email protected]>
  • Loading branch information
Mark Wielaard committed Oct 19, 2018
1 parent 2f4a040 commit 20f9de9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions libdwfl/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2018-10-14 Mark Wielaard <[email protected]>

* dwfl_segment_report_module.c (read_portion): Check requested
filesz isn't larger than buffer_available.
(dwfl_segment_report_module): Check data_size vs filesz after
read_portion call.

2018-10-02 Andreas Schwab <[email protected]>

* relocate.c (relocate): Handle ADD/SUB relocations.
Expand Down
13 changes: 11 additions & 2 deletions libdwfl/dwfl_segment_report_module.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Sniff out modules from ELF headers visible in memory segments.
Copyright (C) 2008-2012, 2014, 2015 Red Hat, Inc.
Copyright (C) 2008-2012, 2014, 2015, 2018 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -301,7 +301,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
inline bool read_portion (void **data, size_t *data_size,
GElf_Addr vaddr, size_t filesz)
{
if (vaddr - start + filesz > buffer_available
/* Check whether we will have to read the segment data, or if it
can be returned from the existing buffer. */
if (filesz > buffer_available
|| vaddr - start > buffer_available - filesz
/* If we're in string mode, then don't consider the buffer we have
sufficient unless it contains the terminator of the string. */
|| (filesz == 0 && memchr (vaddr - start + buffer, '\0',
Expand Down Expand Up @@ -459,6 +462,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
if (read_portion (&data, &data_size, vaddr, filesz))
return;

/* 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 (data_size != 0)
filesz = data_size;

assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));

void *notes;
Expand Down

0 comments on commit 20f9de9

Please sign in to comment.