How to disable rmmod for my own written kernel mod

2019-08-05 04:42发布

问题:

If a user process is working with kernel module, I want that another process can't fire rmmod for that module. How to achieve this type of functionality?

-beginner in Linux kernel programming.

回答1:

rmmod can only unload a module when the refcount is zero.

If the reference count is incremented when a user process is connected (and decremented when it disconnects), you'll be fine.

If the module exposes a device, or is mounted as a filesystem, this should be handled naturally - if not, I guess it'll depend on the userspace interface, but this where to start looking.

By the way, lsmod will show your module refcount. You can check whether it's incremented when the userspace process connects.