-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Mach-O with __TEXT
segment having non 0x0 start offset results in invalid signature
#91
Comments
Which version of rcodesign is this? We had some bugs in this area in earlier releases that should now be fixed. Steps to reproduce would be greatly appreciated. You can email/dropbox/gdrive a binary to me at gregory.szorc@gmail.com. |
the version is 0.22.0. |
I received the binary and can reproduce the failure. Thank you so much! |
OK I see what is happening. Here are the initial Mach-O segments in your binary:
What's happening is that when we finish writing out the Mach-O header and load commands, we're at 0x1060 / 4192. But the __TEXT segments begins at 0x1000 and that is tripping up our code validating that segments don't overlap. Most Mach-O binaries I've seen have __TEXT begin at 0x0 and they leave plenty of space for an additional LC_CODE_SIGNATURE if needed. Yours leaves enough space before the __text section but the __TEXT segment begins at 0x1000. I suppose we need to tweak the logic to look at the section offsets. Out of curiosity, can you share details on how this binary was built/linked? I'm just curious what tools in the wild are emitting __TEXT segments in this manner. |
I‘m using osxcross (https://github.com/tpoechtrager/osxcross.git) with clang 17.0.2 with centos as the host, which is specified as the linker in the rust toolchain. |
…nt start offset We add functionality to our crude Mach-O writer for customizing the start offset of the __TEXT segment. This allows us to implement a failing test for #91 which reproduces the bug.
I added a failing test reproducing the failure then made a code change to hopefully fix this. I confirmed the binary you sent me now appears to sign correctly. However, |
__TEXT
segment having non 0x0 start offset results in invalid signature
it's the cargo strip option causing the issue. Macos refuse to run the binary complaining it's malformed, though the codesign can sign the binary without error. |
@cstkingkey I recently encountered an issue using rust's built-in strip when cross-compiling from linux to macos: rust-lang/rust#114411 . I believe you're encountering the same issue. Essentially, cargo will simply run When cross-compiling from linux to macos, it's safer to strip the binary yourself, outside of the cargo command. |
Oh interesting. So you are saying the Mach-O binary is already corrupted in the email you sent me? If so, should we close this issue? |
today I run into this error:
Error: error writing Mach-O: Mach-O segment corruption: cursor at 0x1060 but segment begins at 0x1000 (please report this bug)
The text was updated successfully, but these errors were encountered: