Message ID | 20230715211604.1272227-1-pobrn@protonmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp355873vqt; Sat, 15 Jul 2023 15:10:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnJqHihGoi7UMJRs9d7+CFGRLnlSHiUwDw1ACj7kPu5x1m4I0V9LcfzYsKFv+Sk3dYYXqN X-Received: by 2002:a17:903:455:b0:1b8:a4a9:6225 with SMTP id iw21-20020a170903045500b001b8a4a96225mr7538595plb.7.1689459047439; Sat, 15 Jul 2023 15:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689459047; cv=none; d=google.com; s=arc-20160816; b=qchM+Ih6BnPMMclA/gqm+71PUPWqW0buNftf3COAK1xl7Bmyd5r79qatsfgtkVKRKa rZO0A/S5lqVeQqzF2eXyEuy1QkdAAPuM5zB2ZFiIZRXyeFfMNytSMyjREujgW+yBMboZ ZnhmfX/YlpoVHKqcPV6wrHa94l8EAXZbxpJ6H/VwsxlAb7XvyoRRrwXTxJcfiGh2PcZp fZCU334vobjdAv4WJdgG8XH/v4WOpCingGfEBVsZ2HB0uXK76TH7dttnuNM1fXndRlIp fqU9diWhKFIN/UmMPp3ZWXfOCeUmmgfCWJTC6n6uQHkWHwe1vnHdpddXjG94GnrK5TW7 Ludw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:message-id:subject:from:to:dkim-signature:date; bh=D16/wC9ybg52jiDQV5+eLtWgvfFQ5TkNWX0NVbvr7UM=; fh=pr1skOTrBYO4iZl7wsLE0ZnNuTQDieJQFCBt9vHtbYw=; b=D4gWHqoSX5rP6HKS9WgKYdctYdFHvyiut0I2pl3tSRfbr+HKjTrgickgfBX+38pNud CLMqz+ZjQrIXxN5WXq45JalIOg6kgkSCuA587rbGx9pHw7iJM7/yXhEq+H9oFlClEEkC wdEvA/kdZA3huVwqfs083tyg7KtbUDTcQUr/0Pbey358VxhRdEhJKNKd6qaTarphqqBY lo9Y2T/NROyYR9NGPmXN46XOndKfynCNUztpvm1zf0in6ZeuXzfBf2ChFfqHCfRczlD4 2uBW+kD8BtPJgLSoX9bbMPW4S6IX6cT2u1o4SM7+nlSzqnow0TrWspGWEonumC3E6r2o HKEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=HEgOvr1g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a170902e54c00b001b8ba6a45d2si9692306plf.245.2023.07.15.15.10.20; Sat, 15 Jul 2023 15:10:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=HEgOvr1g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjGOVYd (ORCPT <rfc822;assdfgzxcv4@gmail.com> + 99 others); Sat, 15 Jul 2023 17:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjGOVYc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 15 Jul 2023 17:24:32 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C21E62738 for <linux-kernel@vger.kernel.org>; Sat, 15 Jul 2023 14:24:31 -0700 (PDT) Date: Sat, 15 Jul 2023 21:24:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1689456269; x=1689715469; bh=D16/wC9ybg52jiDQV5+eLtWgvfFQ5TkNWX0NVbvr7UM=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=HEgOvr1gXJfy3G3zyZiPwPxBdoD7tktehWXIfQl+Sm1e2Hm0s/k6GRcV8TV+XeZNz hh8E2Eq8rjgZURZ0ZRfjRfW072M6VW2tbTnwUmR68cifj5lxylUJ4SuXjdwjbtzp4j m6TA4hW/B4Qm7a7kCNlzCvAarU8o9HHaytB9V9zCCUOo/iBXBKSccN4t4deV7xOzig BZhJaXNO8bYWBO4lGuqrWPg1+ySeA2MC5iYBCsq9yDmYF218ldwWyH8bj4V7Z2Mh5b GB2iE57fDk0zm0nOV1dMfg4J7FiTD4WUwn7GeTo+TqAtbz0eo2NLOwFHVfCouI3faf ikSm1Ec7BpaIA== To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, Mark Gross <markgross@kernel.org>, Hans de Goede <hdegoede@redhat.com>, Armin Wolf <W_Armin@gmx.de>, Andy Shevchenko <andriy.shevchenko@linux.intel.com> From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com> Subject: [RFC PATCH v1] platform/x86: wmi: Do not register driver with invalid GUID Message-ID: <20230715211604.1272227-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771526210000244230 X-GMAIL-MSGID: 1771526210000244230 |
Series |
[RFC,v1] platform/x86: wmi: Do not register driver with invalid GUID
|
|
Commit Message
Barnabás Pőcze
July 15, 2023, 9:24 p.m. UTC
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 <pobrn@protonmail.com>
---
drivers/platform/x86/wmi.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: > 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?
Hi 2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: > > 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. > 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
On Mon, Jul 17, 2023 at 11:23:50AM +0000, Barnabás Pőcze wrote: > 2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: > > > 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. Then add guid_is_valid() to complete the API. Perhaps with the renaming the common part to something else. > > 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. 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).
Hi 2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta: > On Mon, Jul 17, 2023 at 11:23:50AM +0000, Barnabás Pőcze wrote: > > 2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > > On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: > > > > 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. > > 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? > > > > 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. > > 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
On Wed, Jul 19, 2023 at 07:23:37PM +0000, Barnabás Pőcze wrote: > 2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta: > > On Mon, Jul 17, 2023 at 11:23:50AM +0000, Barnabás Pőcze wrote: > > > 2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > > > On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: ... > > > > 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. > > > > 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. > > > > 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. > > > > 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.
Hi 2023. július 20., csütörtök 10:36 keltezéssel, Andy Shevchenko írta: > On Wed, Jul 19, 2023 at 07:23:37PM +0000, Barnabás Pőcze wrote: > > 2023. július 17., hétfő 13:31 keltezéssel, Andy Shevchenko írta: > > > On Mon, Jul 17, 2023 at 11:23:50AM +0000, Barnabás Pőcze wrote: > > > > 2023. július 17., hétfő 11:49 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > > > > On Sat, Jul 15, 2023 at 09:24:16PM +0000, Barnabás Pőcze wrote: > > ... > > > > > > 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. > > > > > > 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. > > > > > > 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. > > > > > > 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. > [...] It seems we have to agree to disagree then. Regards, Barnabás Pőcze
On Thu, Jul 20, 2023 at 10:42:29AM +0000, Barnabás Pőcze wrote: > 2023. július 20., csütörtök 10:36 keltezéssel, Andy Shevchenko írta: > > On Wed, Jul 19, 2023 at 07:23:37PM +0000, Barnabás Pőcze wrote: ... > > 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?
Hi Barnabás, On 7/15/23 23:24, Barnabás Pőcze wrote: > 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 <pobrn@protonmail.com> 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 > --- > drivers/platform/x86/wmi.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c > index a78ddd83cda0..bf0be40b418a 100644 > --- a/drivers/platform/x86/wmi.c > +++ b/drivers/platform/x86/wmi.c > @@ -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 <hdegoede@redhat.com> írta: > [...] > On 7/15/23 23:24, Barnabás Pőcze wrote: > > 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 <pobrn@protonmail.com> > > 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 . 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
On Thu, Jul 27, 2023 at 10:54:26PM +0000, Barnabás Pőcze wrote: > 2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <hdegoede@redhat.com> írta: > > On 7/15/23 23:24, Barnabás Pőcze wrote: ... > > 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 . > > 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. > 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". Strictly speaking you may not do that because it's a (semi-)ABI.
Hi 2023. július 28., péntek 12:02 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > On Thu, Jul 27, 2023 at 10:54:26PM +0000, Barnabás Pőcze wrote: > > 2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <hdegoede@redhat.com> írta: > > > On 7/15/23 23:24, Barnabás Pőcze wrote: > > ... > > > > 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 . > > > > 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. 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. > > > 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". > > Strictly speaking you may not do that because it's a (semi-)ABI. Why is that the case? Regards, Barnabás Pőcze
On Fri, Jul 28, 2023 at 02:39:07PM +0000, Barnabás Pőcze wrote: > 2023. július 28., péntek 12:02 keltezéssel, Andy Shevchenko <andriy.shevchenko@linux.intel.com> írta: > > On Thu, Jul 27, 2023 at 10:54:26PM +0000, Barnabás Pőcze wrote: > > > 2023. július 26., szerda 10:45 keltezéssel, Hans de Goede <hdegoede@redhat.com> írta: > > > > On 7/15/23 23:24, Barnabás Pőcze wrote: ... > > > > 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 . > > > > > > 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. > > 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. 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. > > > 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". > > > > 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).
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index a78ddd83cda0..bf0be40b418a 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -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;