platform/x86: wmi: Do not register driver with invalid GUID
RFC PATCH 1/1 platform/x86: wmi: Do not register driver with invalid GUID
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since 028e6e204ace1f080cfeacd72c50397eb8ae8883).
So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
--- drivers/platform/x86/wmi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/platform/x86/wmi.c +13 -0
@@ -1513,6 +1513,19 @@ static int acpi_wmi_probe(struct platform_device *device)int __must_check __wmi_driver_register (struct wmi_driver *driver,struct module *owner) { +bool any_id_invalid = false; + +for (const struct wmi_device_id *id = driver->id_table; *id->guid_string; id++) { +if (!uuid_is_valid (id->guid_string)) { +pr_err ("driver '%s' has invalid GUID: %s" , + driver->driver.name, id->guid_string); + any_id_invalid = true; + } + } + +if (any_id_invalid) +return -EINVAL ; + driver->driver.owner = owner; driver->driver.bus = &wmi_bus_type;
Signature · 1 line
2.41.0
Quoted 8 lines · Barnabás Pőcze
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Besides using wrong API (uuid_*() vs. guid_*() one), I don't think we need to validate it here. Why not in file2alias.c?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi
2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <[email protected]> írta:
Quoted 10 lines · Barnabás Pőcze
Quoted 8 lines
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Besides using wrong API (uuid_*() vs. guid_*() one), I don't
As far as I can see guid_parse() also uses uuid_is_valid(), the format is the same.
Quoted 2 lines
think we need to validate it here. Why not in
file2alias.c? [...]
1) that seems like a more complicated change (duplicating uuid_is_valid()?);
2) that will only check the GUIDs specified by MODULE_DEVICE_TABLE().
Arguably the second point is not that significant since most users will indeed use MODULE_DEVICE_TABLE(). But I think the first point has some merit. And furthermore, I think this check should be here regardless of whether file2alias.c also contains an equivalent/similar check.
Regards,
Barnabás Pőcze
Quoted 7 lines · Barnabás Pőcze
2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <[email protected]> írta:
Quoted 5 lines · Barnabás Pőcze
Quoted 5 lines
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Besides using wrong API (uuid_*() vs. guid_*() one), I don't
As far as I can see
guid_parse()also usesuuid_is_valid(), the format is the same.
Then add guid_is_valid() to complete the API. Perhaps with the renaming the common part to something else.
Quoted 10 lines
Quoted 2 lines
think we need to validate it here. Why not in
file2alias.c? [...]1) that seems like a more complicated change (duplicating
uuid_is_valid()?);
2) that will only check the GUIDs specified byMODULE_DEVICE_TABLE().Arguably the second point is not that significant since most users will indeed use
MODULE_DEVICE_TABLE(). But I think the first point has some merit. And furthermore, I think this check should be here regardless of whetherfile2alias.calso contains an equivalent/similar check.
Why do we need it? We never match against wrong GUID from ACPI, since it would be very weird ACPI table.
For file2alias what we would need is to split uuid.c in the kernel to something like uuid.c and libuuid.c where the latter will be used as a C module in both kernel and user space (i.o.w. to be compiled twice and linked accordingly).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi
2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta:
Quoted 12 lines · Barnabás Pőcze
Quoted 11 lines
2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <[email protected]> írta:
Quoted 9 lines · Barnabás Pőcze
Quoted 8 lines
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Besides using wrong API (uuid_*() vs. guid_*() one), I don't
As far as I can see
guid_parse()also usesuuid_is_valid(), the format is the same.Then add
guid_is_valid()to complete the API. Perhaps with the renaming the common part to something else.
But that would be the exact same function. GUIDs are UUIDs, aren't they?
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
think we need to validate it here. Why not in
file2alias.c? [...]1) that seems like a more complicated change (duplicating
uuid_is_valid()?);
2) that will only check the GUIDs specified byMODULE_DEVICE_TABLE().
Quoted 8 lines
Quoted 4 lines
Arguably the second point is not that significant since most users will indeed use
MODULE_DEVICE_TABLE(). But I think the first point has some merit. And furthermore, I think this check should be here regardless of whetherfile2alias.calso contains an equivalent/similar check.Why do we need it? We never match against wrong GUID from ACPI, since it would be very weird ACPI table.
[...]
The point is to catch typos in drivers' WMI ID tables.
Regards,
Barnabás Pőcze
Quoted 4 lines · Barnabás Pőcze
2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta:
Quoted 3 lines · Barnabás Pőcze
Quoted 2 lines
2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <[email protected]> írta:
On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote:
...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Besides using wrong API (uuid_*() vs. guid_*() one), I don't
As far as I can see
guid_parse()also usesuuid_is_valid(), the format is the same.Then add
guid_is_valid()to complete the API. Perhaps with the renaming the common part to something else.But that would be the exact same function. GUIDs are UUIDs, aren't they?
Yes and no. If we want to validate the respective bit for GUID vs. UUID, they will be different. Currently they are the same as validation is relaxed in the kernel.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
think we need to validate it here. Why not in
file2alias.c? [...]1) that seems like a more complicated change (duplicating
uuid_is_valid()?);
2) that will only check the GUIDs specified byMODULE_DEVICE_TABLE().Arguably the second point is not that significant since most users will indeed use
MODULE_DEVICE_TABLE(). But I think the first point has some merit. And furthermore, I think this check should be here regardless of whetherfile2alias.calso contains an equivalent/similar check.
Quoted 5 lines
Quoted 3 lines
Why do we need it? We never match against wrong GUID from ACPI, since it would be very weird ACPI table.
[...]The point is to catch typos in drivers' WMI ID tables.
Yes, that's what file2alias is for. We trust modules we build, right? If you don't trust, then we have much bigger problem than this patch tries to address.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi
2023. július 20., csütörtök 10:36 keltezéssel, Andy Shevchenko írta:
Quoted 12 lines · Barnabás Pőcze
Quoted 4 lines
2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta:
Quoted 3 lines · Barnabás Pőcze
Quoted 2 lines
2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <[email protected]> írta:
On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote:...
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Besides using wrong API (uuid_*() vs. guid_*() one), I don't
As far as I can see
guid_parse()also usesuuid_is_valid(), the format is the same.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Then add
guid_is_valid()to complete the API. Perhaps with the renaming the common part to something else.But that would be the exact same function. GUIDs are UUIDs, aren't they?
Yes and no. If we want to validate the respective bit for GUID vs. UUID, they will be different. Currently they are the same as validation is relaxed in the kernel.
I see. Regardless, that is the only check guid_parse() does, so I don't think it is unreasonable to have only that check for the time being.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines
Quoted 3 lines
think we need to validate it here. Why not in
file2alias.c? [...]1) that seems like a more complicated change (duplicating
uuid_is_valid()?);
2) that will only check the GUIDs specified byMODULE_DEVICE_TABLE().Arguably the second point is not that significant since most users will indeed use
MODULE_DEVICE_TABLE(). But I think the first point has some merit. And furthermore, I think this check should be here regardless of whetherfile2alias.calso contains an equivalent/similar check.Why do we need it? We never match against wrong GUID from ACPI, since it would be very weird ACPI table.
[...]
Quoted 6 lines
Quoted 1 line
The point is to catch typos in drivers' WMI ID tables.
Yes, that's what file2alias is for. We trust modules we build, right? If you don't trust, then we have much bigger problem than this patch tries to address.
[...]
It seems we have to agree to disagree then.
Regards,
Barnabás Pőcze
Quoted 2 lines · Barnabás Pőcze
2023. július 20., csütörtök 10:36 keltezéssel, Andy Shevchenko írta:
Quoted 1 line · Barnabás Pőcze
...
Quoted 5 lines
Quoted 3 lines
Yes, that's what file2alias is for. We trust modules we build, right? If you don't trust, then we have much bigger problem than this patch tries to address.
It seems we have to agree to disagree then.
I am confused. The parts are related to each other, you can't disagree on both.
You mean we have much bigger problem in the kernel or file2alias is the proper place? I.o.w. which part you agree with and respectively disagree?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Barnabás,
Quoted 10 lines · Barnabás Pőcze
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Signed-off-by Barnabás Pőcze <[email protected]>
Thank you for working on this!
About the do this here, vs do this in file2alias.c discussion, we have many old style WMI drivers which are not covered by the check you are adding for the new style WMI bus driver.
So I think having a check in file2alias.c would be a very good thing to have. AFAICT that would also cause compile time failures rather then the run-time errors your current approach results in.
I think that having an additional check like the one which you propose has some value too, even if it is just to cover drivers which for some reason don't use MODULE_DEVICE_TABLE(), but IMHO the most important check to have is a check in file2alias.c .
Regards,
Hans
Quoted 28 lines
--- drivers/platform/x86/wmi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/platform/x86/wmi.c +13
-0@@ -1513,6 +1513,19 @@ static int acpi_wmi_probe(struct platform_device *device)int __must_check __wmi_driver_register (struct wmi_driver *driver,struct module *owner) { +bool any_id_invalid = false; + +for (const struct wmi_device_id *id = driver->id_table; *id->guid_string; id++) { +if (!uuid_is_valid (id->guid_string)) { +pr_err ("driver '%s' has invalid GUID: %s" , + driver->driver.name, id->guid_string); + any_id_invalid = true; + } + } + +if (any_id_invalid) +return -EINVAL ; + driver->driver.owner = owner; driver->driver.bus = &wmi_bus_type;
Hi
2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <[email protected]> írta:
Quoted 24 lines
[...]
Quoted 10 lines · Barnabás Pőcze
Since a WMI driver's ID table contains strings it is relatively easy to make mistakes. At the moment, there is no feedback if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).So check if the GUIDs in the driver's ID table are valid, print all invalid ones, and refuse to register the driver if any of the GUIDs are invalid.
Signed-off-by Barnabás Pőcze <[email protected]>Thank you for working on this!
About the do this here, vs do this in
file2alias.cdiscussion, we have many old style WMI drivers which are not covered by the check you are adding for the new style WMI bus driver.So I think having a check in
file2alias.cwould be a very good thing to have. AFAICT that would also cause compile time failures rather then the run-time errors your current approach results in.
Quoted 4 lines
I think that having an additional check like the one which you propose has some value too, even if it is just to cover drivers which for some reason don't use
MODULE_DEVICE_TABLE(), but IMHO the most important check to have is a check infile2alias.c.
Okay... any tips on how to avoid copying uuid_is_valid()?
Another idea I had was that maybe struct wmi_device_id::guid_string needs to be changed to be guid_t and then GUID_INIT() or something similar could be used to initialize it. That way it is impossible to mess up the format. The only downside I can see is that guid is no longer "grep-able".
Regards,
Barnabás Pőcze
Quoted 2 lines · Barnabás Pőcze
2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <[email protected]> írta:
Quoted 1 line · Barnabás Pőcze
...
Quoted 6 lines
Quoted 4 lines
I think that having an additional check like the one which you propose has some value too, even if it is just to cover drivers which for some reason don't use
MODULE_DEVICE_TABLE(), but IMHO the most important check to have is a check infile2alias.c.Okay... any tips on how to avoid copying
uuid_is_valid()?
I think I already told the rough design: we need to split uuid.c to three
files: libuuid.h, libuuid.c uuid.c and libuuid.c should be built twice:
once for uuid.c and once for file2alias.c. libuuid.h should contain the definitions file2alias.c is using. Something like that.
Quoted 4 lines
Another idea I had was that maybe
struct wmi_device_id::guid_stringneeds to be changed to beguid_tand thenGUID_INIT()or something similar could be used to initialize it. That way it is impossible to mess up the format. The only downside I can see is that guid is no longer "grep-able".
Strictly speaking you may not do that because it's a (semi-)ABI.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi
2023. július 28., péntek 12:02 keltezéssel, Andy Shevchenko <[email protected]> írta:
Quoted 11 lines · Barnabás Pőcze
Quoted 2 lines
2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <[email protected]> írta:
Quoted 1 line · Barnabás Pőcze
...
Quoted 5 lines
Quoted 4 lines
I think that having an additional check like the one which you propose has some value too, even if it is just to cover drivers which for some reason don't use
MODULE_DEVICE_TABLE(), but IMHO the most important check to have is a check infile2alias.c.
Quoted 6 lines
Quoted 1 line
Okay... any tips on how to avoid copying
uuid_is_valid()?I think I already told the rough design: we need to split
uuid.cto three
files:libuuid.h,libuuid.cuuid.candlibuuid.cshould be built twice:
once foruuid.cand once forfile2alias.c.libuuid.hshould contain the definitionsfile2alias.cis using. Something like that.
What is not clear at all to me is how includes should be handled. uuid_is_valid() uses isxdigit(), which is found in different header files based on whether it is a kernel or user space build.
Quoted 7 lines
Quoted 5 lines
Another idea I had was that maybe
struct wmi_device_id::guid_stringneeds to be changed to beguid_tand thenGUID_INIT()or something similar could be used to initialize it. That way it is impossible to mess up the format. The only downside I can see is that guid is no longer "grep-able".Strictly speaking you may not do that because it's a (semi-)ABI.
Why is that the case?
Regards,
Barnabás Pőcze
Quoted 4 lines · Barnabás Pőcze
2023. július 28., péntek 12:02 keltezéssel, Andy Shevchenko <[email protected]> írta:
Quoted 3 lines · Barnabás Pőcze
Quoted 2 lines
2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <[email protected]> írta:
Quoted 1 line · Barnabás Pőcze
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
I think that having an additional check like the one which you propose has some value too, even if it is just to cover drivers which for some reason don't use
MODULE_DEVICE_TABLE(), but IMHO the most important check to have is a check infile2alias.c.Okay... any tips on how to avoid copying
uuid_is_valid()?
Quoted 8 lines
Quoted 4 lines
I think I already told the rough design: we need to split
uuid.cto three
files:libuuid.h,libuuid.cuuid.candlibuuid.cshould be built twice:
once foruuid.cand once forfile2alias.c.libuuid.hshould contain the definitionsfile2alias.cis using. Something like that.What is not clear at all to me is how includes should be handled.
uuid_is_valid()usesisxdigit(), which is found in different header files based on whether it is a kernel or user space build.
It may be conditional build or some other tricks (I haven't investigated myself, though). Alternatively libuuid.c can be included in the other C-file.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Another idea I had was that maybe
struct wmi_device_id::guid_stringneeds to be changed to beguid_tand thenGUID_INIT()or something similar could be used to initialize it. That way it is impossible to mess up the format. The only downside I can see is that guid is no longer "grep-able".Strictly speaking you may not do that because it's a (semi-)ABI.
Why is that the case?
As a developer of that idea you should prove that it won't break any of all possible user configurations (for example, first that comes to my mind is multi-version modules: when kernel is not signed, but it might be not the case, you need to research and convince us that there will be no breakage).
Signature · 2 lines
With Best Regards, Andy Shevchenko