[PATCH v2 1/8] bfd: add _bfd_elf_relax_delete_range_ok
Jan Beulich
jbeulich@suse.com
Fri Nov 6 13:43:49 GMT 2026
On 16.10.2026 14:36, Harshit Kumar wrote:
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -14237,6 +14237,32 @@ _bfd_elf_link_munmap_section_contents (asection *sec ATTRIBUTE_UNUSED)
> #endif
> }
>
> +/* Validate that deleting COUNT bytes starting at ADDR up to TOADDR
> + is within the section bounds of SEC.
This is ambiguous; as worded my first and second reading pass resulted in
"then ADDR + COUNT == TOADDR". TOADDR really looks to be an upper bound,
which wants expressing unambiguously.
Further, ADDR (also in TOADDR) isn't quite right here. There are section
offsets, so OFFS may be better. TOADDR (as said, apparently being an
upper bound) may want naming e.g. LIMIT (not just because TOOFFS wouldn't
look quite nice, at least to me).
> ADDR is derived from an
> + unvalidated relocation offset; without this check the subtraction
> + (TOADDR - ADDR - COUNT) wraps around, corrupting the heap buffer. */
> +
> +bool
> +_bfd_elf_relax_delete_range_ok (bfd *abfd,
> + asection *sec,
Both can be pointer-to-const, can't they?
> + bfd_vma addr,
> + bfd_vma count,
> + bfd_vma toaddr)
> +{
> + if (addr <= toaddr
> + && count <= toaddr - addr
> + && toaddr <= sec->size)
Is this last condition violated anywhere? If not, can it become an
assertion?
> + return true;
> +
> + _bfd_error_handler
> + /* xgettext:c-format */
> + (_("%pB: bad relaxation: cannot delete %" PRIu64 " bytes at %#" PRIx64
> + " in section `%pA' of size %#" PRIx64),
> + abfd, (uint64_t) count, (uint64_t) addr, sec, (uint64_t) sec->size);
This doesn't express at all the case addr > toaddr. Together with the
remark right above: You may want to log toaddr here instead, and then
re-word the message text accordingly.
Jan
More information about the Binutils
mailing list