Page MenuHomeFreeBSD

linker: Prevent UB on malformed ELF
Needs ReviewPublic

Authored by code_fedang.net on Tue, Sep 15, 4:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 18, 8:12 PM
Unknown Object (File)
Thu, Sep 17, 6:48 AM
Unknown Object (File)
Thu, Sep 17, 6:43 AM
Unknown Object (File)
Wed, Sep 16, 9:42 PM
Unknown Object (File)
Wed, Sep 16, 11:38 AM
Unknown Object (File)
Tue, Sep 15, 10:57 PM
Subscribers

Details

Reviewers
bnovkov

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76938
Build 73821: arc lint + arc unit

Event Timeline

sys/kern/link_elf.c
1110–1112

I think we should enforce this assumption (i.e., return EINVAL or something similar) instead of sorting the segments.

Thinking about this from a user's standpoint, a kldload triggering this assertion almost certainly means that something went wrong during linking or that somebody is trying to mess with the kernel.
It would make more sense to have the operation fail and let the user know that something's up instead of silently correcting the error.

sys/kern/link_elf.c
1110–1112

Reading through the ELF specification this is not actually a requirement.
Putting them in order is the de facto standard, but I can see some obscure compiler doing whatever they want.
What would the error message say since the file is technically in-spec?

sys/kern/link_elf.c
1110–1112

An ENOEXEC with something along the lines of "Improperly sorted segments " is fine.