-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Artificial MachO binary processed by llvm-objcopy/strip is not accepted by codesign #117723
Comments
@llvm/issue-subscribers-bug Author: Richard Dzenis (RIscRIpt)
## Symptom
Artificial MachO binary processed by llvm-objcopy/strip is not accepted by codesign. codesign fails with error: > main executable failed strict validation InvestigationAccording to Darling/libsecurity_utilities/lib/macho++.cpp
According to
According to
Relevant requirementFrom the above there should be no data in MachO past contents of a load command with the largest Problem description
This clearly violates one of the checks mentioned above (there are zero-bytes filled past
|
@llvm/issue-subscribers-tools-llvm-objcopy-strip Author: Richard Dzenis (RIscRIpt)
## Symptom
Artificial MachO binary processed by llvm-objcopy/strip is not accepted by codesign. codesign fails with error: > main executable failed strict validation InvestigationAccording to Darling/libsecurity_utilities/lib/macho++.cpp
According to
According to
Relevant requirementFrom the above there should be no data in MachO past contents of a load command with the largest Problem description
This clearly violates one of the checks mentioned above (there are zero-bytes filled past
|
Let's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore. Then according to previous code we would not update indirectsymoff field. This would lead to `MachOWriter::totalSize()` report size that is larger than the new MachO. As a result we would get MachO that has zero bytes past contents of the very last load command. Codesign has a strict check that size of MachO file must be equal to lastLoadCommand.offset + lastLoadCommand.size If this is not satisfied codesign reports the following error main executable failed strict validation Fixes llvm#117723
Let's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore. Then according to previous code we would not update indirectsymoff field. This would lead to `MachOWriter::totalSize()` report size that is larger than the new MachO. As a result we would get MachO that has zero bytes past contents of the very last load command. Codesign has a strict check that size of MachO file must be equal to lastLoadCommand.offset + lastLoadCommand.size If this is not satisfied codesign reports the following error main executable failed strict validation Fixes #117723
Symptom
Artificial MachO binary processed by llvm-objcopy/strip is not accepted by codesign.
codesign fails with error:
Investigation
According to Darling/libsecurity_utilities/lib/macho++.cpp
According to
MachO::validateStructure
LoadCommand
and its size must equal to the total size of "fat" component,which sometimes corresponds to the end of file.
According to
Universal::Universal
Relevant requirement
From the above there should be no data in MachO past contents of a load command with the largest
offset+size
.Problem description
llvm-objcopy
does not updateindirectsymoff
field if the resultingIndirectSymTable
(after stripping) is empty [1]. As a resultindirectsymoff
keeps old value, which is garbage, and can point pastoffset+size
of the last load command. As a resulttotalSize()
returns size that is larger than the actual stripped MachO [2].This clearly violates one of the checks mentioned above (there are zero-bytes filled past
offset+size
of the last load command.llvm-project/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
Lines 364 to 368 in ec41462
llvm-project/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
Lines 92 to 94 in ec41462
The text was updated successfully, but these errors were encountered: