]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
modpost: Handle malformed WMI GUID strings
authorArmin Wolf <W_Armin@gmx.de>
Wed, 10 Jun 2026 20:34:53 +0000 (22:34 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 12 Jun 2026 13:01:55 +0000 (16:01 +0300)
Some WMI GUIDs found inside binary MOF files contain both
uppercase and lowercase characters. Blindly copying such
GUIDs will prevent the associated WMI driver from loading
automatically because the WMI GUID found inside WMI device ids
always contains uppercase characters.

Avoid this issue by always converting WMI GUID strings to
uppercase. Also verify that the WMI GUID string actually looks
like a valid GUID.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://patch.msgid.link/20260610203453.816254-10-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Documentation/wmi/driver-development-guide.rst
scripts/mod/file2alias.c

index 387f508d57ad8955602a3a608b78285e0a35227f..6290c448f5e79ae3239cf3cfa6ec2aa07f522956 100644 (file)
@@ -54,7 +54,7 @@ to matching WMI devices using a struct wmi_device_id table:
 ::
 
   static const struct wmi_device_id foo_id_table[] = {
-         /* Only use uppercase letters! */
+         /* Using only uppercase letters is recommended */
          { "936DA01F-9ABD-4D9D-80C7-02AF85C822A8", NULL },
          { }
   };
index 4e99393a35f152d7b95a6c1d2a2368dcb58875b1..20e542a888c49cd7bc73e064d93db2a806eb3fc2 100644 (file)
@@ -1253,6 +1253,8 @@ static void do_tee_entry(struct module *mod, void *symval)
 static void do_wmi_entry(struct module *mod, void *symval)
 {
        DEF_FIELD_ADDR(symval, wmi_device_id, guid_string);
+       char result[sizeof(*guid_string)];
+       int i;
 
        if (strlen(*guid_string) != UUID_STRING_LEN) {
                warn("Invalid WMI device id 'wmi:%s' in '%s'\n",
@@ -1260,7 +1262,31 @@ static void do_wmi_entry(struct module *mod, void *symval)
                return;
        }
 
-       module_alias_printf(mod, false, WMI_MODULE_PREFIX "%s", *guid_string);
+       for (i = 0; i < UUID_STRING_LEN; i++) {
+               char value = (*guid_string)[i];
+               bool valid = false;
+
+               if (i == 8 || i == 13 || i == 18 || i == 23) {
+                       if (value == '-')
+                               valid = true;
+               } else {
+                       if (isxdigit(value))
+                               valid = true;
+               }
+
+               if (!valid) {
+                       warn("Invalid character %c inside WMI GUID string '%s' in '%s'\n",
+                            value, *guid_string, mod->name);
+                       return;
+               }
+
+               /* Some GUIDs from BMOF definitions contain lowercase characters */
+               result[i] = toupper(value);
+       }
+
+       result[i] = '\0';
+
+       module_alias_printf(mod, false, WMI_MODULE_PREFIX "%s", result);
 }
 
 /* Looks like: mhi:S */