Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1631418

Re: [PATCH] driver core: platform: fix race condition with driver_override

From Greg KH <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH] driver core: platform: fix race condition with driver_override
Date 2017-04-26 14:00 +0200
Message-ID <tAtLX-1LU-9@gated-at.bofh.it> (permalink)
References <tAixb-2Vi-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Apr 25, 2017 at 04:55:26PM -0700, Adrian Salido wrote:
> The driver_override implementation is susceptible to race condition when
> different threads are reading vs storing a different driver override.
> Add locking to avoid race condition.
> 
> Fixes: 3d713e0e382e ("driver core: platform: add device binding path 'driver_override'")
> Cc: stable@vger.kernel.org
> Signed-off-by: Adrian Salido <salidoa@google.com>
> ---
>  drivers/base/platform.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index c2456839214a..493e03fa0e07 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -866,7 +866,7 @@ static ssize_t driver_override_store(struct device *dev,
>  				     const char *buf, size_t count)
>  {
>  	struct platform_device *pdev = to_platform_device(dev);
> -	char *driver_override, *old = pdev->driver_override, *cp;
> +	char *driver_override, *old, *cp;
>  
>  	if (count > PATH_MAX)
>  		return -EINVAL;
> @@ -879,12 +879,15 @@ static ssize_t driver_override_store(struct device *dev,
>  	if (cp)
>  		*cp = '\0';
>  
> +	device_lock(dev);
> +	old = pdev->driver_override;
>  	if (strlen(driver_override)) {
>  		pdev->driver_override = driver_override;
>  	} else {
>  		kfree(driver_override);
>  		pdev->driver_override = NULL;
>  	}
> +	device_unlock(dev);
>  
>  	kfree(old);

Shouldn't you move the lock until after the kfree()?  Or am I missing
what the lock is trying to protect here?

>  
> @@ -895,8 +898,12 @@ static ssize_t driver_override_show(struct device *dev,
>  				    struct device_attribute *attr, char *buf)
>  {
>  	struct platform_device *pdev = to_platform_device(dev);
> +	ssize_t len;
>  
> -	return sprintf(buf, "%s\n", pdev->driver_override);
> +	device_lock(dev);
> +	len = sprintf(buf, "%s\n", pdev->driver_override);
> +	device_unlock(dev);
> +	return len;

Why does the show function need to be changed at all?  How can anything
"race" here?

thanks,

greg k-h

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] driver core: platform: fix race condition with  driver_override Adrian Salido <salidoa@google.com> - 2017-04-26 02:00 +0200
  Re: [PATCH] driver core: platform: fix race condition with  driver_override Greg KH <gregkh@linuxfoundation.org> - 2017-04-26 14:00 +0200
    Re: [PATCH] driver core: platform: fix race condition with driver_override Adrian Salido <salidoa@google.com> - 2017-04-26 17:00 +0200
      Re: [PATCH] driver core: platform: fix race condition with  driver_override Greg KH <gregkh@linuxfoundation.org> - 2017-04-26 17:50 +0200

csiph-web