Skip to content

Commit 028e6e2

Browse files
andy-shevjwrdegoede
authored andcommitted
platform/x86: wmi: Break possible infinite loop when parsing GUID
The while-loop may break on one of the two conditions, either ID string is empty or GUID matches. The second one, may never be reached if the parsed string is not correct GUID. In such a case the loop will never advance to check the next ID. Break possible infinite loop by factoring out guid_parse_and_compare() helper which may be moved to the generic header for everyone later on and preventing from similar mistake in the future. Interestingly that firstly it appeared when WMI was turned into a bus driver, but later when duplicated GUIDs were checked, the while-loop has been replaced by for-loop and hence no mistake made again. Fixes: a48e233 ("platform/x86: wmi: add context pointer field to struct wmi_device_id") Fixes: 844af95 ("platform/x86: wmi: Turn WMI into a bus driver") Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Armin Wolf <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 06c2afb commit 028e6e2

File tree

1 file changed

+12
-10
lines changed
  • drivers/platform/x86

1 file changed

+12
-10
lines changed

drivers/platform/x86/wmi.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ static acpi_status find_guid(const char *guid_string, struct wmi_block **out)
136136
return AE_NOT_FOUND;
137137
}
138138

139+
static bool guid_parse_and_compare(const char *string, const guid_t *guid)
140+
{
141+
guid_t guid_input;
142+
143+
if (guid_parse(string, &guid_input))
144+
return false;
145+
146+
return guid_equal(&guid_input, guid);
147+
}
148+
139149
static const void *find_guid_context(struct wmi_block *wblock,
140150
struct wmi_driver *wdriver)
141151
{
@@ -146,11 +156,7 @@ static const void *find_guid_context(struct wmi_block *wblock,
146156
return NULL;
147157

148158
while (*id->guid_string) {
149-
guid_t guid_input;
150-
151-
if (guid_parse(id->guid_string, &guid_input))
152-
continue;
153-
if (guid_equal(&wblock->gblock.guid, &guid_input))
159+
if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
154160
return id->context;
155161
id++;
156162
}
@@ -895,11 +901,7 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
895901
return 0;
896902

897903
while (*id->guid_string) {
898-
guid_t driver_guid;
899-
900-
if (WARN_ON(guid_parse(id->guid_string, &driver_guid)))
901-
continue;
902-
if (guid_equal(&driver_guid, &wblock->gblock.guid))
904+
if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
903905
return 1;
904906

905907
id++;

0 commit comments

Comments
 (0)