[PATCH v1] ld: fix segfault when linker script is not found
Jan Beulich
jbeulich@suse.com
Wed Sep 10 09:37:45 GMT 2025
On 10.09.2025 11:26, Matthieu Longo wrote:
> On 2025-09-09 11:43, Jan Beulich wrote:
>> On 04.09.2025 17:19, Matthieu Longo wrote:
>>> ld previously crashed with a segmentation fault if the specified linker
>>> script could not be found. Surprisingly, ldfile_find_command_file() has
>>> never covered the very common case where an invalid filename was set.
>>
>> Imo that's not a correct way to put it. You may want to take a look at the
>> 2.40 variant of the function, where everything was still fine afaics. It
>> was a later addition which wasn't done as carefully as would have been
>> needed. (The same change also looks to have introduced a UBSAN issue, in
>> that struct script_name_list has an array-of-1-element field instead of a
>> flexible array member.)
>
> Indeed my statement was wrong. I should not have said "never".
> The issue seems to have been introduced recently by d048eee2910 [1].
>
> Regarding the UBSAN issue, I have run the sanitizer with the error case
> without the fix, and got an error about the NULL pointer. And once I
> reintroduced the fix, no error was triggered. Thus I am not sure if the
> UBSAN issue you mentioned is the same.
> What issue exactly do you reference regarding struct script_name_list.
> Please could you dump the sanitizer trace to give me more context ?
I haven't run any sanitizer, I've noticed this while looking that the
code. The 1-element array at the end of the struct is routinely overrun,
which is UB from all I know.
> Also, do you want me to fix this UBSAN issue as a part of this patch ?
No, that's a separate issue and hence wants a separate fix. Yet of course
if you want to ...
Jan
More information about the Binutils
mailing list