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)
Sat, Sep 26, 5:02 AM
Unknown Object (File)
Thu, Sep 24, 9:25 AM
Unknown Object (File)
Wed, Sep 23, 2:35 PM
Unknown Object (File)
Tue, Sep 22, 12:48 PM
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
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.