Incorrect ELF might have PT_NOTE slightly larger than the needed to contain all notes, and the PT_NOTE size could be larger than one page. Then rtld mmaps just the notes bytes to parse. After the last note, we iterate past the mapped region trying to read the Elf_Note header. This was found in wild. Require full elf note to fit into the [start_note, end_note) region to continue the parsing. Check it in stages, first verifying the Elf_Note header structure fits, to be able to read the name and data length. After that, check the whole note against limit.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
I can confirm that this patch fixes the problem for me. Tested on stable/15-n285266-30211e66b989
| libexec/rtld-elf/rtld.c | ||
|---|---|---|
| 1792 | I personally find if statements that omit one of the components a bit confusing. No worries if you prefer it as is.. | |
| libexec/rtld-elf/rtld.c | ||
|---|---|---|
| 1792 | Perhaps you mean 'for'. But style is explicit about for (;;) {} e.g. Yes, I think this is fine there. | |
Can we have errata once the fix is merged to the stable branches? I'm currently pending update of Plasma ports. In principle I could exclude offending plugin from the package and push the update, but this seems dubious to me.
Perhaps you mean 'for'. But style is explicit about for (;;) {} e.g. Yes, I think this is fine there.
Err, yes I meant for, not sure how I made that mistake. We do specify for (;;) for forever loops, but don't really speak to for loops that omit some but not all components. But either way, doesn't really matter it's fine with me either way.
No idea how, but this is it:
https://gist.github.com/makc-fbsd/539d1781662a1cc01d40dc11f72463e7