Commit 5c387e92 authored by Adrian Salido's avatar Adrian Salido Committed by Sasha Levin

driver core: platform: fix race condition with driver_override

[ Upstream commit 62655397 ]

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: 3d713e0e ("driver core: platform: add device binding path 'driver_override'")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarAdrian Salido <salidoa@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
parent 59724793
...@@ -729,7 +729,7 @@ static ssize_t driver_override_store(struct device *dev, ...@@ -729,7 +729,7 @@ static ssize_t driver_override_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct platform_device *pdev = to_platform_device(dev); 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) if (count > PATH_MAX)
return -EINVAL; return -EINVAL;
...@@ -742,12 +742,15 @@ static ssize_t driver_override_store(struct device *dev, ...@@ -742,12 +742,15 @@ static ssize_t driver_override_store(struct device *dev,
if (cp) if (cp)
*cp = '\0'; *cp = '\0';
device_lock(dev);
old = pdev->driver_override;
if (strlen(driver_override)) { if (strlen(driver_override)) {
pdev->driver_override = driver_override; pdev->driver_override = driver_override;
} else { } else {
kfree(driver_override); kfree(driver_override);
pdev->driver_override = NULL; pdev->driver_override = NULL;
} }
device_unlock(dev);
kfree(old); kfree(old);
...@@ -758,8 +761,12 @@ static ssize_t driver_override_show(struct device *dev, ...@@ -758,8 +761,12 @@ static ssize_t driver_override_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct platform_device *pdev = to_platform_device(dev); 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;
} }
static DEVICE_ATTR_RW(driver_override); static DEVICE_ATTR_RW(driver_override);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment