Page MenuHomeFreeBSD

link_elf: Guard against subtraction underflow
AbandonedPublic

Authored by jhb on Jun 23 2026, 8:30 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Sep 17, 9:47 AM
Unknown Object (File)
Wed, Sep 16, 3:13 PM
Unknown Object (File)
Sat, Sep 5, 7:32 PM
Unknown Object (File)
Sat, Sep 5, 7:32 PM
Unknown Object (File)
Fri, Sep 4, 7:03 PM
Unknown Object (File)
Tue, Sep 1, 6:42 PM
Unknown Object (File)
Sat, Aug 29, 10:53 PM
Unknown Object (File)
Aug 13 2026, 1:41 AM
Subscribers

Details

Summary

If a malformed program header has p_filesz > p_memsz, the subtraction underflows.
Introduced guard to validate before zeroing.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

For this case, I would rather abort the link attempt and treat this as a corrupt file. In fact, several other things break here before we even get to the bzero if filesz > memsz. Rather than this change, I'll be fixing various ELF loaders in the tree to reject files where filesz > memsz.

See D58542 (and related commits in that stack)

jhb abandoned this revision.
jhb added a reviewer: thebugfixers_pm.me.