chiark / gitweb /
do not allow kernel properties to be set by udev rules
[elogind.git] / udev / udev-rules.c
index d16c1f9454d322fa9ec25ee4317653fe894f9e9d..89d98248a1baf92c1956ccc05e78eb8ff83d4870 100644 (file)
@@ -1385,6 +1385,26 @@ static int add_rule(struct udev_rules *rules, char *line,
                                if (rule_add_key(&rule_tmp, TK_M_ENV, op, value, attr) != 0)
                                        goto invalid;
                        } else {
+                               static const char *blacklist[] = {
+                                       "ACTION",
+                                       "SUBSYSTEM",
+                                       "DEVTYPE",
+                                       "MAJOR",
+                                       "MINOR",
+                                       "DRIVER",
+                                       "IFINDEX",
+                                       "DEVNAME",
+                                       "DEVLINKS",
+                                       "DEVPATH",
+                                       "TAGS",
+                               };
+                               unsigned int i;
+
+                               for (i = 0; i < ARRAY_SIZE(blacklist); i++)
+                                       if (strcmp(attr, blacklist[i]) == 0) {
+                                               err(rules->udev, "invalid ENV attribute, '%s' can not be set %s:%u\n", attr, filename, lineno);
+                                               continue;
+                                       }
                                if (rule_add_key(&rule_tmp, TK_A_ENV, op, value, attr) != 0)
                                        goto invalid;
                        }
@@ -2721,7 +2741,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                        struct stat stats;
 
                        /* we assure, that the permissions tokens are sorted before the static token */
-                       if (uid == 0 && gid == 0)
+                       if (mode == 0 && uid == 0 && gid == 0)
                                goto next;
                        util_strscpyl(filename, sizeof(filename), udev_get_dev_path(rules->udev), "/",
                                      &rules->buf[cur->key.value_off], NULL);