Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codesign): pad LINKEDIT to multiple of page size when reading #66

Merged

Conversation

jkt-signal
Copy link
Contributor

When we are creating a new CodeSignature, we align its offset up to a multiple of the page size; we then read the existing LINKEDIT section (and the entire beginning of the file, for signing) based on the location of that code signature. If the existing LINKEDIT section's end was not page-aligned, we get an EOF when attempting to read up to the page-aligned flie size, causing signing to fail.

This change limits our read to the actual size of the file (or LINKEDIT section, at least), while keeping the buffer we read into the correct size (and therefore implicitly padding it with zeroes, which will get written out when we rewrite the LINKEDIT section and new signature).

I had never encountered this bug before because we'd never seen a MachO whose LINKEDIT section didn't end on a page boundary, but the newest Electron release (which includes a compiler change) seems to end 4 bytes short of a page boundary.

When we are creating a new CodeSignature, we align its offset up to a multiple
of the page size; we then read the existing LINKEDIT section (and the entire
beginning of the file, for signing) based on the location of that code
signature. If the existing LINKEDIT section's end was not page-aligned, we get
an EOF when attempting to read up to the page-aligned flie size, causing
signing to fail.

This change limits our read to the actual size of the file (or LINKEDIT
section, at least), while keeping the buffer we read into the correct
size (and therefore implicitly padding it with zeroes, which will get written
out when we rewrite the LINKEDIT section and new signature).
@blacktop
Copy link
Owner

apologies for letting this slip through the cracks, it's been a pretty crappy few months :(

thanks again for contributing ❤️

@blacktop blacktop merged commit 6e27af0 into blacktop:master Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants