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

[Feature Request] Enable preload mode on macOS with SIP disabled #558

Open
ZeppLu opened this issue Jan 3, 2024 · 2 comments
Open

[Feature Request] Enable preload mode on macOS with SIP disabled #558

ZeppLu opened this issue Jan 3, 2024 · 2 comments

Comments

@ZeppLu
Copy link

ZeppLu commented Jan 3, 2024

Describe the bug

Currently bear silently enforces wrapper mode on macOS. This behavior causes cross compilers (eg mingw) fail to be recognized.

However, if SIP is disabled, we can actually use DYLD_INSERT_LIBRARIES without any problem. Here is a minimal example:

~/Documents/preload-test cat main.c 
#include <stdio.h>

void impossible() {
        printf("hijack succ\n");
}

int main() {
        return 0;
}
~/Documents/preload-test clang main.c -O0 -o main                                  
~/Documents/preload-test cat preload.c 
extern void impossible();

__attribute__((destructor)) void deinit() {
        impossible();
}
~/Documents/preload-test clang preload.c -O0 -shared -Wl,-U,_impossible -o preload.dylib 
~/Documents/preload-test DYLD_INSERT_LIBRARIES=preload.dylib ./main                     
hijack succ

Expected behavior

On macOS, dynamically check for SIP status at runtime, to determine whether we can use preload mode.

Additionally, a warning log when wrapper mode is being enforced would be helpful

Environment:

  • OS name: macOS
  • OS version: Sonoma 14.1.2
  • OS architecture: x86_64
  • Bear version: 3.1.3
  • Bear install method: macports
@rizsotto
Copy link
Owner

rizsotto commented Jan 4, 2024

Yes, the previous version of Bear was doing this. The SIP enabled just become so dominant that had to come up with the compiler wrappers. But it's feasible to enable it again.

@ZeppLu
Copy link
Author

ZeppLu commented Feb 2, 2024

Notes after some investigation (currently too busy to work on it):

csrutil enable --without debug is sufficient for DYLD_* environment variables to work

This gist can check SIP status programatically, and the above configuration corresponds to CSR_ALLOW_TASK_FOR_PID bit

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

No branches or pull requests

2 participants