Page 1 of 1

Taking reference on kext from user-space daemon

PostPosted: Sun Aug 20, 2017 7:53 am
by adam81
I've got Kext which give service to user-space client that is using iokit service communication.

I'd like that the client will take reference on the kext, so that it wouldn't be possible to unload the kext while the client is sill up, and when the client goes down, the kext should terminate as well.

according to the documentation I can use IOServiceOpen and IOConnectAddRef, but kextunload stills removes the driver.

kextstat also shows that no references are taken on the driver, those are references by other drivers as it mentioned in the documentation, but I thought that the above commands will do the trick.

    Index Refs Address Size Wired Name (Version) UUID <Linked Against>
    1 100 0xffffff7f80a46000 0x9d90 0x9d90 (16.7.0) 410B3B98-9DAB-4590-9086-7C57A5B3099A
    2 8 0xffffff7f80fc3000 0x3940 0x3940 (16.7.0) FA744B47-913C-4B5D-8C16-2F8005D85935
    3 127 0xffffff7f80a04000 0x21040 0x21040 (16.7.0) 80F2DA67-C67B-4583-9B09-082DB11F69FC
    170 0 0xffffff7f80a04000 0x21040 0x21040 (1.0.0) 53390CCD-55F0-315F-BBD7-21645800E4A0

what should I do in order to increase the #Refs from the above chart ?

Re: Taking reference on kext from user-space daemon

PostPosted: Tue Aug 22, 2017 10:33 pm
by morpheus
Rather than messing with the refs, you can refuse to unload and mark yourself in use from kernel space. That might be easier.

Re: Taking reference on kext from user-space daemon

PostPosted: Wed Aug 23, 2017 2:18 pm
by adam81
Thanks for the advice, but how exactly should I prevent the driver unloading from within the driver ? is there any particular kpi for this purpose ?

according to 'kextstat' official documentation, Refs defined as "The number of references to this kext by others. If nonzero, the kext cannot be unloaded.".

Not really sure what is "others"... is it other kexts, or also user-space entities.