macOS 10.13 & Kernel Extensions > Kernel Events problem

Problem


In macOS 10.13, 3rd party kernel extensions are prevented from being loaded as long as the end user has not "trusted" them via the System Preferences > Securtiy & Privacy > General > Allow… dialog.


Before High Sierra, a launchd daemon calling kextload could reasonably expect the kernel extension to be actually loaded after the call as long as the .kext bundle was correcly located with approrpiate permissions.


Now in High Sierra, a launchd daemon would need to take into account that kextload can return a value specifying that the system policy blocked the loading (27?) and that the kext will be loaded eventually or not.


So adding asynchronism to the launchd daemon could be a good idea.


One possible solution would be for the launchd daemon to listen to kernel event posted by the kernel extension at the end of its start callback.


Unfortunately, there seems to be a chicken and egg problem:


  • for the launchd daemon to receive kernel events informing it that the kernel has been loaded ,the launchd daemon needs to be able to retrieve the vendor code via a ioctl call.
  • as far as I can tell, ioctl(_rawSystemSocket, SIOCGKEVVENDOR,&tVendorCode) fails if the vendor code has not been allocated at the kernel level.
  • as far as I can tell, to allocate the vendor code, the kernel extension needs to be loaded and have called kev_vendor_code_find().


Question


Am I missing something or kernel events are not a solution to properly address the problems introduced by the new system policy mechanism?


Is polling (*) the only (and stupid) solution available?



* for instance by trying to register a kext control socket periodically



Side note: is there any plan to fix the forum text editor. It's a nighmare.

Replies

*Bump* on this. If anybody has any ideas, I'm open. I'm not the original poster but we have a similar problem.


Our only solution is to introduce the terrible IOService APIs into our kernel extension just to allow us to be notified when the IOService gets published. It's a sledgehammer for a small problem, but it's the only thing I know of so far.

I have some ideas about how to do that but this stuff is just too complex to investigate in the time I have available for DevForums. I recommend that you open a DTS tech support incident here. While the need for this is driven by 10.13 changes, and DTS won’t officially support 10.13 until it is released, the actual mechanics are the same on 10.12, so I can’t see any reason why we wouldn’t accept your support request.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Solutions suggested by DTS included:


- IOService APIs


- creating a file via the kernel extension in a known location and observing vnode events to detect the creation of the file from userland.


- connecting to a userland AF_UNIX socket from the kernel extension.

Solutions suggested by DTS included:

You forget “file an enhancement request for a more direct way to resolve this issue” (-:

If you do file an ER, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"