Using Kauth API in MacOS kernel extension

こ雲淡風輕ζ 提交于 2019-12-02 15:42:47

问题


I'm trying to monitor file copying to external USB drives in a kext. This is how I implemented:

  1. Call kauth_listen_scope() to register a listener for KAUTH_SCOPE_VNODE.
  2. When I receive a KAUTH_VNODE_READ_DATA event on local drive, I will put the file information in a queue for record.
  3. When I receive a KAUTH_VNODE_WRITE_DATA event on external drives, I will search the queue in reverse order. If I found a matching, I will send this file information to a user space daemon for checking, then return KAUTH_RESULT_DENY if the file shouldn't be copied out.

Everything works fine based on individual files according to my test. But when I copy a directory with some files in it to USB drive, it doesn't work. Apple seems to ignore the KAUTH_RESULT_DENY code I return, although I'm pretty sure I catch this copying successfully based on logging.

By using the MAC policy API, I encountered the same issue. In a mpo_vnode_check_open callback function, I check the read/write flag. For individual files, it works great. But when I copy a folder of files, this function is never called with write flag. Does Apple deliberately skip the callback function when it comes to copying a folder?

Can anybody give me some suggestions? Thanks!

来源:https://stackoverflow.com/questions/57249719/using-kauth-api-in-macos-kernel-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!