lkml.org 
[lkml]   [2022]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] driver core: fix driver_set_override() issue with empty strings
On Thu,  1 Sep 2022 18:37:34 +0200
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:

> Python likes to send an empty string for some sysfs files, including the
> driver_override field. When commit 23d99baf9d72 ("PCI: Use
> driver_set_override() instead of open-coding") moved the PCI core to use
> the driver core function instead of hand-rolling their own handler, this
> showed up as a regression from some userspace tools, like DPDK.
>
> Fix this up by actually looking at the length of the string first
> instead of trusting that userspace got it correct.
>
> Reported-by: Stephen Hemminger <stephen@networkplumber.org>
> Fixes: 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding")
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
> Cc: stable <stable@kernel.org>
> Tested-by: Huisong Li <lihuisong@huawei.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
> drivers/base/driver.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 15a75afe6b84..676b6275d5b5 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override,
> if (len >= (PAGE_SIZE - 1))
> return -EINVAL;
>
> + /*
> + * Compute the real length of the string in case userspace sends us a
> + * bunch of \0 characters like python likes to do.
> + */
> + len = strlen(s);
> +
> if (!len) {
> /* Empty string passed - clear override */
> device_lock(dev);

Thanks for addressing this.

Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>

\
 
 \ /
  Last update: 2022-09-01 18:57    [W:0.099 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site