fix(kernelcache): detect enosys syscalls by instruction pattern matching#1178
Open
ThePraeceps wants to merge 1 commit intoblacktop:masterfrom
Open
fix(kernelcache): detect enosys syscalls by instruction pattern matching#1178ThePraeceps wants to merge 1 commit intoblacktop:masterfrom
ThePraeceps wants to merge 1 commit intoblacktop:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ipsw kernel syscallhas several failure modes relating to enosys:int syscall(void);are invalidly set to enosys stub429 AUE_NULL ALL { int audit_session_join(mach_port_name_t port); }429 0xfffffff00a26bea8: enosys munge=0xfffffff009f72adc ret=int narg=1 bytes=4 int enosys(mach_port_name_t port);This code currently only supports ARM64 / AMD64 - I am uncertain what level of support you set for armv7 / i386 / ppc so have omitted these for now. These would still be processed but fall back to whatever the built in JSON declares.
I have went with byte matching as I expect the implementation to be stable. An alternative would be to leverage emulation similar to kernel cpp but that seemed a bit heavy for this use case.
I have speculatively left the BTI/ENDBR64 hardening from AI in the code but I suspect as a leaf function the compiler would never emit those here and I'm skeptical Apple would backport ENDBR64 within Tahoe.
Testing
I have tested the new processing against several x86 and arm64 kernels:
I manually verified the cases mentioned above in the x86 and iPhone 13 kernels to confirm they are enosys. Example difference in output:
I have ran the test suite and all the kernel tests continued to pass.
AI Assistance
Initial code written by Claude Opus 4.6 then tested and bug fixed by hand.