I want to write a driver to pass some info to a device, and to do so I've made a sysfs entry. It works fine, but the problem is that I don't have the permissions to write to it unless I am logged in as admin. I'd like it to have open read and write permissions.
The way I was advised to write the driver, I used the following macro to set up the sysfs attribute:
__ATTR(status_vector,0660,status_vector_is_read,status_vector_is_written);
The problem is obvious, I've used 660 as the permission instead of 666.
However, when I try putting the permission as 666, or using the defined S_IWUGO | S_IRUGO, I get an error. I am able to set open read permissions, but not write. Apparently this person had the same problem, but I don't see any answer given on that thread.
I could always just set the permissions using chmod, but that seems clunky and annoying of a solution, Id rather learn how to actually write a driver properly. Why am I not allowed to set S_IWUGO?
o+w
and reconsider your design. In the very worst case, you could introduce a simple suid root program that non-privileged users could use to write the file. – Andy Dalton Nov 14 '17 at 14:35