Missing documentation for OSMappedFile

I am working on a DriverKit project and the new class OSMappedFile sounds like something I am looking for, at least from what I understood from the description in the header file. https://developer.apple.com/documentation/driverkit/osmappedfile

I've tried different combinations, however the method OSMappedFile::createFromPath always returns an error 0xe00002bc (general error), which is not helpful at all.

Could you please provide more details about the class and how to use it? Is it possible to open an arbitrary file in an arbitrary location? Does the owner of the file matter? Does the entitlements have to be modified somehow?

Thanks for reply

I am testing it on Monterey 12.3.1, my driver is linking DriverKit 21.0, no provisioning profile, SIP is off.

Accepted Reply

Pulling the conversation from the comments back out to an answer for clarity. Instead of using OSMappedFile::createFromPath, try getting the file from an OSBundle like so:

OSMappedFile* myMappedFile = nullptr;
OSBundle* myBundle = OSBundle::mainBundle();
myBundle->loadResources("configfile.conf", 0, IOVMPageSize * sizeToFit, &myMappedFile);

This should work without requiring any additional entitlements, and without having to know any GUIDs.

Replies

OSMappedFile can only be used to read files in the dext's bundle. Since you are getting kIOReturnError, that means that DriverKit couldn't find the file, likely due to you not having permissions to access it. You might try to open the plist of your dext first to make sure it's working for you, and then branch out from there.

I found an error log message which confirms this is really a permission related issue. Could you please suggest how to set the permissions to make this work? Adding the bundle path to com.apple.security.temporary-exception.files.absolute-path.read-only didn't help - this entitlement is missing in the built driver, so it must have been somehow stripped during the build.

  • This shouldn't require any additional entitlements. What error are you seeing?

  • The actual error seems to be hidden, and only "private" is displayed. I noticed that the same thing happens if a formatting string for string types is used in log messages, obviously due to security reasons.   2022-05-24 08:46:16.759215+0200 0xfff2   Default   0x0         0   0  kernel: (com.mycompany.mydriver) <private>     Another error is logged when the driver tries to access a file outside of the bundle path. But this is irrelevant, as you say that only files inside the bundle are accessible. 2022-05-24 08:46:16.759301+0200 0xfff2   Error    0x0         0   0  kernel: (Sandbox) Sandbox: com.mycompany.mydriver(5517) deny(1) file-read-data /Library/Application Support/mycompany/cooldriver/configfile.conf

    Opening the Info.plist doesn't work for me. Should be specified a full or a relative path? Passing a full path is a bit tricky, as I do not have control over the path from which the driver runs (according to Activity monitor: /Library/SystemExtensions//com.mycompany.mydriver.dext/com.mycompany.mydriver) after it is installed.

  • EDIT: the path should have been (according to Activity monitor: /Library/SystemExtensions/RANDOM_GUID/com.mycompany.mydriver.dext/com.mycompany.mydriver)

Pulling the conversation from the comments back out to an answer for clarity. Instead of using OSMappedFile::createFromPath, try getting the file from an OSBundle like so:

OSMappedFile* myMappedFile = nullptr;
OSBundle* myBundle = OSBundle::mainBundle();
myBundle->loadResources("configfile.conf", 0, IOVMPageSize * sizeToFit, &myMappedFile);

This should work without requiring any additional entitlements, and without having to know any GUIDs.