'Custom macOS login Plugin crashes on Catalina ("not in immutable memory")

I am using the Apple NameAndPassword Xcode example to customize the macOS login experience. My goal is authenticate a user against Active Directory. I am using the NameAndPassword example as a jumping board to understanding the macOS login process. I don't particularly need a custom UI, but from looking at several threads, the example can also work with PAM authentication.

I am running the NameAndPassword plugin which I built on Catalina. I am performing local code signing. When I log out, the loginwindow app should call the invoke method of my plugin and show a custom SFAuthorizationView, which does not appear. I see the following error in the system.log...

Jan 24 11:20:48 Kolyas-Mac SecurityAgentHelper[890]: objc[890]: CLASS: class 'EXAuthorizationPlugin' 0x104fb7d58 small method list 0x104fb1ec8 is not in immutable memory
Jan 24 11:20:48 Kolyas-Mac com.apple.xpc.launchd[1] (com.apple.security.agent.login.00000000-0000-0000-0000-0000000186E3[883]): Service exited due to SIGILL | sent by exc handler[883]

and see that the SecurityAgentHelper crashes with the following...

Application Specific Information:
dyld3 mode
CLASS: class 'EXAuthorizationPlugin' 0x104fb7d58 small method list 0x104fb1ec8 is not in immutable memory

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff6d368ad6 __abort_with_payload + 10
1   libsystem_kernel.dylib          0x00007fff6d36a3df abort_with_payload_wrapper_internal + 80
2   libsystem_kernel.dylib          0x00007fff6d36a38f abort_with_reason + 19
3   libobjc.A.dylib                 0x00007fff6c070820 _objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) + 114
4   libobjc.A.dylib                 0x00007fff6c0707ae _objc_fatal(char const*, ...) + 135
5   libobjc.A.dylib                 0x00007fff6c063e13 realizeClassWithoutSwift(objc_class*, objc_class*) + 2184
6   libobjc.A.dylib                 0x00007fff6c0636a0 realizeClassWithoutSwift(objc_class*, objc_class*) + 277
7   libobjc.A.dylib                 0x00007fff6c0634bb realizeClassMaybeSwiftMaybeRelock(objc_class*, mutex_tt<false>&, bool) + 317
8   libobjc.A.dylib                 0x00007fff6c062ff4 initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool) + 104
9   libobjc.A.dylib                 0x00007fff6c053d45 lookUpImpOrForward + 1072
10  libobjc.A.dylib                 0x00007fff6c053399 _objc_msgSend_uncached + 73
11  com.apple.securityAgentPlugin.NameAndPassword   0x0000000104faee74 AuthorizationPluginCreate + 148 (main.m:66)

Any suggestions on how to resolve this error? Would this be a compiler issue? Maybe a directive for memory?

This is the offending code:

OSStatus AuthorizationPluginCreate(const AuthorizationCallbacks *callbacks,
                          AuthorizationPluginRef *outPlugin,
                          const AuthorizationPluginInterface **outPluginInterface)
{

    os_log_with_type(OS_LOG_DEFAULT, OS_LOG_TYPE_DEBUG, "AuthorizationPluginCreate");
    *outPlugin = [[EXAuthPlugin alloc] initWithCallbacks:callbacks pluginInterface:outPluginInterface];
    return noErr;
}


Solution 1:[1]

I got the same error when porting my iPad app to Mac using Catalyst. My app needed access to AppKit specific methods, and I added a bundle plugin following this guide. The program worked fin on my MacBook Air M1 running Monterey, but crashed on my 2012 MacBook Pro running Catalina with the error:

CLASS: class 'AppKitBridge.AppKitBridge' 0x11668c388 small method list 0x116687508 is not in immutable memory

After I changed the bundle identifier in the plugin bundle from $(PRODUCT_BUNDLE_IDENTIFIER).AppKitBridge to $(PRODUCT_BUNDLE_IDENTIFIER), and set the plugins deployment target to 10.15, the problem went away.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 torof