]> granicus.if.org Git - intel_nuc_led/commitdiff
Allow setting the UID, GID and permissions of /proc/acpi/nuc_led
authorFrederik Carlier <frederik.carlier@quamotion.mobi>
Wed, 5 Jul 2017 23:13:40 +0000 (01:13 +0200)
committerFrederik Carlier <frederik.carlier@quamotion.mobi>
Wed, 5 Jul 2017 23:15:41 +0000 (01:15 +0200)
README.md
nuc_led.c

index e0368ffeebaa7ed097501526cb7f6446b0b7d1c3..7842093d07f9ff1e34d083b3ad764aa6630fdd87 100644 (file)
--- a/README.md
+++ b/README.md
@@ -63,3 +63,9 @@ Example execution to cause the ring LED blink green at a medium rate at partial
     echo 'ring,80,blink_medium,green' | sudo tee /proc/acpi/nuc_led > /dev/null
     
 Errors in passing parameters will appear as warnings in dmesg.
+
+You can change the owner, group and permissions of `/proc/acpi/nuc_led` by passing parameters to the nuc_led kernel module. Use:
+
+* `nuc_led_uid` to set the owner (default is 0, root)
+* `nuc_led_gid` to set the owning group (default is 0, root)
+* `nuc_led_perms` to set the file permissions (default is r+w for group and user and r for others)
index edd98d998cd6e5ca8756b0ff4c83d60b37bf46ad..296fe1fca24a66f1d0a4f412b2d49637f6899d28 100644 (file)
--- a/nuc_led.c
+++ b/nuc_led.c
@@ -42,6 +42,18 @@ MODULE_AUTHOR("Miles Peterson");
 MODULE_DESCRIPTION("Intel NUC LED Control WMI Driver");
 MODULE_LICENSE("GPL");
 
+static unsigned int nuc_led_perms __read_mostly = S_IRUGO | S_IWUSR | S_IWGRP;
+static unsigned int nuc_led_uid __read_mostly;
+static unsigned int nuc_led_gid __read_mostly;
+
+module_param(nuc_led_perms, uint, S_IRUGO | S_IWUSR | S_IWGRP);
+module_param(nuc_led_uid, uint, 0);
+module_param(nuc_led_gid, uint, 0);
+
+MODULE_PARM_DESC(nuc_led_perms, "permissions on /proc/acpi/nuc_led");
+MODULE_PARM_DESC(nuc_led_uid, "default owner of /proc/acpi/nuc_led");
+MODULE_PARM_DESC(nuc_led_gid, "default owning group of /proc/acpi/nuc_led");
+
 /* Intel NUC WMI GUID */
 #define NUCLED_WMI_MGMT_GUID            "8C5DA44C-CDC3-46b3-8619-4E26D34390B7"
 MODULE_ALIAS("wmi:" NUCLED_WMI_MGMT_GUID);
@@ -431,6 +443,8 @@ static struct file_operations proc_acpi_operations = {
 static int __init init_nuc_led(void)
 {
         struct proc_dir_entry *acpi_entry;
+       kuid_t uid;
+       kgid_t gid;
 
         // Make sure LED control WMI GUID exists
         if (!wmi_has_guid(NUCLED_WMI_MGMT_GUID)) {
@@ -438,14 +452,25 @@ static int __init init_nuc_led(void)
                 return -ENODEV;
         }
 
+        // Verify the user parameters
+       uid = make_kuid(&init_user_ns, nuc_led_uid);
+       gid = make_kgid(&init_user_ns, nuc_led_gid);
+
+       if (!uid_valid(uid) || !gid_valid(gid)) {
+                pr_warn("Intel NUC LED control driver got an invalid UID or GID\n");
+               return -EINVAL;
+       }
+
         // Create nuc_led ACPI proc entry
-        acpi_entry = proc_create("nuc_led", 0664, acpi_root_dir, &proc_acpi_operations);
+        acpi_entry = proc_create("nuc_led", nuc_led_perms, acpi_root_dir, &proc_acpi_operations);
 
         if (acpi_entry == NULL) {
                 pr_warn("Intel NUC LED control driver could not create proc entry\n");
                 return -ENOMEM;
         }
 
+        proc_set_user(acpi_entry, uid, gid);
+
         pr_info("Intel NUC LED control driver loaded\n");
 
         return 0;