This is the mail archive of the mailing list for the elfutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] libelf: Fix elf_newdata when raw data has been read, but not converted.

On Tue, Jan 20, 2015 at 10:31:55PM +0100, Mark Wielaard wrote:
> When ELF data for a section has been read by elf_rawdata, data_read
> and rawdata_base are set, but data_list_rear will not be set until the
> data will be converted (by elf_getdata). elf_newdata would overwrite
> the existing data in that case.

This was still not completely correct. Unlike what the comment in the
elf_newdata code (and the description of struct Elf_Scn in libelfP.h)
imply both elf_getdata and elf_update rely on the fact that when
data_list_rear is set they don't have to read/convert and data from
the ELF image anymore. That means we do have to make sure that is
done when adding new data to the section with elf_newdata. Otherwise
elf_getdata might return the wrong data contents and elf_update might
write garbage (or randomly write fill characters).

I updated the patch to more proactively read the existing data when
needed in elf_newdata and updated the testcase to also check the contents
of the section data (and not just the size).

I have another test for this (for related bug in elf_strptr). Once those
tests are in we could look at making the code more lazy in this case by
changing elf_getdata and elf_update to take unread/converted raw data
into account.

Attachment: 0001-libelf-Fix-elf_newdata-when-raw-ELF-file-image-data-.patch
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]