The libelf file in base fails to perform elf_update when growing the file by adding new sections, because elf_getdata erroneously checks section boundaries against the old file size.
This can be fixed by omitting this check when doing elf_update.
Differential D10487
Bug 218861 - libelf elf_update fails when adding sections eric_metricspace.net on Apr 24 2017, 11:21 PM. Authored by Tags None Referenced Files
Details
The libelf file in base fails to perform elf_update when growing the file by adding new sections, because elf_getdata erroneously checks section boundaries against the old file size. This can be fixed by omitting this check when doing elf_update.
Diff Detail
Event TimelineComment Actions Do you have a straightforward testcase that can be used to reproduce the issue (and the one in D10486)?
Comment Actions Awaiting review; I pointed out a couple of minor nits to address on commit
Comment Actions I'm not sure why whatever updates the s_shdr doesn't also update e_rawsize to maintain the invariant. The rawdata change seems spurious. It isn't used, as far as I can tell. I don't see any other issues with the implementation here, other than that we're removing an invariant in the one case.
Comment Actions The changes from the former revision look good, modulo one nitpick/question below. My top-level questions still stand, though:
Comment Actions OK, I reverted the rawdata change. I'm not sure what you mean by the invariant. All this patch does is detect a violation and report an error in that case. Comment Actions From @jkoshy_users.sourceforge.net mail,
Comment Actions This change relaxes the error condition sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset to only apply if !updating. Could we instead correct e_rawsize when we are updating? Comment Actions I still don't understand what this change is attempting to do. The proposed changes seem to handle the case where:
However, this would be incorrect usage of the ELF(3) API: if a new section is added to an Elf descriptor and if the section falls outside the current object, then elf_newdata() would need to be called on the section to actually associate data with the new byte range. It could be that I have misunderstood this patch. A short, correct, compilable example (sscce.org) would help me understand the issue better. |