Page MenuHomeFreeBSD

link_elf: Guard against subtraction underflow
AbandonedPublic

Authored by jhb on Jun 23 2026, 8:30 PM.
Tags
None
Referenced Files
F166350629: D57785.diff
Thu, Aug 13, 1:41 AM
Unknown Object (File)
Mon, Aug 10, 1:05 PM
Unknown Object (File)
Sun, Aug 9, 3:38 AM
Unknown Object (File)
Sat, Aug 8, 10:23 PM
Unknown Object (File)
Sat, Aug 8, 5:43 PM
Unknown Object (File)
Sat, Aug 8, 11:41 AM
Unknown Object (File)
Sat, Aug 8, 5:30 AM
Unknown Object (File)
Fri, Aug 7, 11: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.