tags:

views:

41

answers:

1

Hello,

I have a device driver module which does a register_chardev(). In the driver open() function I wish to be able to determine the pid or pgid of the process which is attempting to open the device node. Is this possible? Does anyone have any ideas of where to begin?

I am assuming this should somewhat secure my device node to only allow my applications to use it, since you cannot migrate a process to a new process group unless they are in the same session.

+2  A: 

The kernel isn't the right place to make this kind of policy decision - the correct place to set the permissions on who can open the device node is by setting the usual ownership and permissions on the device node file in the filesystem.

If you really have your heart set on it, current->pid is the PID, current->tgid is the thread group id and current->group_leader->pid is the PGID.

caf
Thanks, is it guaranteed that the scheduler would not update current to a new process in the process queue while the driver's open function is executing. I suppose a root user could circumvent this by loading a modified driver module anyway. But I will use it along with permissions and ownership on the device node file.
Sean A.O. Harney
The open function executes in the context of the process that made the syscall - it can be preempted, but whenevery your code in the open function is executing `current` will point to the same process.
caf