Skip to content

Bypass macOS' max_protection using mach_vm_protect(VM_PROT_COPY)#31

Merged
Snaipe merged 1 commit intoSnaipe:masterfrom
MrAnno:fix-macos-maxprot
Nov 17, 2021
Merged

Bypass macOS' max_protection using mach_vm_protect(VM_PROT_COPY)#31
Snaipe merged 1 commit intoSnaipe:masterfrom
MrAnno:fix-macos-maxprot

Conversation

@MrAnno
Copy link
Collaborator

@MrAnno MrAnno commented Nov 11, 2021

max_prot disallows injecting the BoxFort trampoline into main()'s location.

This PR replaces the mprotect() call with vm_protect(VM_PROT_COPY), which gets (COW) a writable page.

https://stackoverflow.com/questions/60654834/using-mprotect-to-make-text-segment-writable-on-macos

Note: mprotect() would still work in cases when the library is dynamically linked to the executable.

@MrAnno MrAnno mentioned this pull request Nov 11, 2021
Copy link
Owner

@Snaipe Snaipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one nit.

@MrAnno
Copy link
Collaborator Author

MrAnno commented Nov 16, 2021

I'm investigating an issue with the new patch (I'm afraid mprotect() reports success but fails to do its job).

Update: Nope, I just messed up the vm_protect detection. :)

@MrAnno MrAnno marked this pull request as draft November 16, 2021 18:59
max_prot disallows injecting the BoxFort trampoline into main()'s location.

This commit replaces the mprotect() call with vm_protect(VM_PROT_COPY),
which gets (COW) a writable page.
@MrAnno MrAnno marked this pull request as ready for review November 16, 2021 20:05
@MrAnno
Copy link
Collaborator Author

MrAnno commented Nov 16, 2021

Okay, I think everything is fine now.

Copy link
Owner

@Snaipe Snaipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

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