[PATCH 3/4] elf: Avoid linker crash on corrupt .eh_frame section
Jan Beulich
jbeulich@suse.com
Thu Sep 25 06:53:40 GMT 2025
On 25.09.2025 08:32, H.J. Lu wrote:
> On Thu, Sep 25, 2025 at 2:06 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 23.09.2025 22:46, H.J. Lu wrote:
>>> On Tue, Sep 23, 2025 at 10:50 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>
>>>> On 23.09.2025 04:23, H.J. Lu wrote:
>>>>> Return false on corrupt .eh_frame section. Cap the .eh_frame section
>>>>> alignment to the larger of the section size and the pointer size.
>>>>
>>>> Like for patch 2, I'm unconvinced of it being a good idea to build in
>>>> heuristics like this. What if someone feels a need to align .eh_frame
>>>> to, say, a page boundary?
>>>
>>> .eh_frame section is special:
>>>
>>> eh_alignment = ((1 << o->alignment_power)
>>> * bfd_octets_per_byte (output_bfd, o));
>>> /* Skip over zero terminator, and prevent empty sections from
>>> adding alignment padding at the end. */
>>> for (i = o->map_tail.s; i != NULL; i = i->map_tail.s)
>>> if (i->size == 0)
>>> i->flags |= SEC_EXCLUDE;
>>> else if (i->size > 4)
>>> break;
>>> /* The last non-empty eh_frame section doesn't need padding. */
>>> if (i != NULL)
>>> i = i->map_tail.s;
>>> /* Any prior sections must pad the last FDE out to the output
>>> section alignment. Otherwise we might have zero padding
>>> between sections, which would be seen as a terminator. */
>>> for (; i != NULL; i = i->map_tail.s)
>>> if (i->size == 4)
>>> /* All but the last zero terminator should have been removed. */
>>> BFD_FAIL ();
>>> else
>>> {
>>> bfd_size_type size
>>> = (i->size + eh_alignment - 1) & -eh_alignment;
>>>
>>> If .eh_frame section alignment is larger than the section size,
>>> we will get buffer overflow.
>>>
>>> if (i->size != size)
>>> {
>>> i->size = size;
>>> changed = 1;
>>> eh_changed = 1;
>>> }
>>> }
>>>
>>>> Also, please format unsigned long-s using %lu or (here) %lx. Especially
>>>> when values get large, imo printing them as decimal is unhelpful.
>>>
>>> Will do.
>>>
>>>> Finally - why would .eh_frame be special in this regard? What about,
>>>> say, .sframe?
>>>>
>>>
>>> .sframe section doesn't do the code above.
>>
>> I understand that, but I hoped you would also understand that I'm merely
>> trying to give examples. In all of your reply you didn't address my question
>> "What if someone feels a need to align .eh_frame to, say, a page boundary?"
>> If someone doing so resulted in a buffer overflow, that would indeed want
>> fixing. But not by preventing them to use that kind of alignment.
>
> So far, we don't have any request for large .eh_frame section alignment.
> My patch simply changes the linker crash to a linker error. If people
> do need large .eh_frame section alignments in the future, we can work
> with them to resolve their issues.
That's not how I look at things, sorry. If Alan or Nick want to approve this
patch, I'm not going to stand in the way, but I won't (and I object to you
putting it in without approval, ftaod).
Jan
More information about the Binutils
mailing list