Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should the permisson attrbute be specified for every variable declared in Kernel Module development?

Although we define these variables in the global namespace, why do we need to explicitly specify the permissions for every variable declared. Or is my way of thinking completely wrong?

int number = 100; module_param(number, int , 0); // module_param(variable_name, variable_type , permissions);

What does '0' in permission attribute actually mean?

like image 690
bittterbotter Avatar asked Dec 19 '22 08:12

bittterbotter


1 Answers

This permission flags value controls who can access the representation of the module parameter in sysfs. If perm is set to 0, there is no sysfs entry at all; otherwise, it appears under /sys/module with the given set of permissions.

Use S_IRUGO for a parameter that can be read by the world but cannot be changed;

S_IRUGO|S_IWUSR allows root to change the parameter. Note that if a parameter is changed by sysfs, the value of that parameter as seen by your module changes, but your module is not notified in any other way. You should probably not make module parameters writable, unless you are prepared to detect the change and react accordingly.

The only use of a parameter with perm = 0 will have is that you can set it at module load time, and that's it.

You need to explicitly specify the permissions for every variable if you want to override the default permissions which is 0 I think.

like image 167
RootPhoenix Avatar answered Dec 26 '22 10:12

RootPhoenix