I would like to protect my character device,from application operations. I would like that only specific application can do operation on the device.
How can I do it?
Thanks
I would like to protect my character device,from application operations. I would like that only specific application can do operation on the device.
How can I do it?
Thanks
This may not be correct answer(Because I didn't test it). But I believe this will work.
I hope, you have idea about current field in task_struct
which will give you the current PID of the process. Please refer this thread. how does current->pid work for linux?
so instead of pid, you can use comm
field of task_struct.
http://lxr.free-electrons.com/source/include/linux/sched.h#L1180.
Keep an array of allowed application names in your driver. check comm
field against allowed list during /dev/<yourchardriver>
open() operation.
sample file operations structure.
struct file_operations fops = { /* these are the file operations provided by our driver */
.owner = THIS_MODULE, /*prevents unloading when operations are in use*/
.open = device_open, /*to open the device*/
.write = device_write, /*to write to the device*/
.read = device_read, /*to read the device*/
.release = device_close, /*to close the device*/
.llseek = device_lseek
};
when you call open("/dev/sampledrv") in user space, device_open() will be called in your driver. so these validation can be done here.