summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolai Stange <nstange@suse.de>2017-09-11 09:45:42 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-10-12 09:18:03 +0200
commit389721fabce2457414c4f128bc0b3a7d77c8f833 (patch)
treea531a42aef9198d3c79c6d0d5f93871111cfd472
parente29b6128817a06e6b12e5fad724ff23f6d43c62d (diff)
downloadlinux-stable-389721fabce2457414c4f128bc0b3a7d77c8f833.tar.gz
linux-stable-389721fabce2457414c4f128bc0b3a7d77c8f833.tar.bz2
linux-stable-389721fabce2457414c4f128bc0b3a7d77c8f833.zip
driver core: platform: Don't read past the end of "driver_override" buffer
commit bf563b01c2895a4bfd1a29cc5abc67fe706ecffd upstream. When printing the driver_override parameter when it is 4095 and 4094 bytes long, the printing code would access invalid memory because we need count+1 bytes for printing. Reject driver_override values of these lengths in driver_override_store(). This is in close analogy to commit 4efe874aace5 ("PCI: Don't read past the end of sysfs "driver_override" buffer") from Sasha Levin. Fixes: 3d713e0e382e ("driver core: platform: add device binding path 'driver_override'") Signed-off-by: Nicolai Stange <nstange@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/base/platform.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ef1d816090c3..a33ae377728f 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -729,7 +729,8 @@ static ssize_t driver_override_store(struct device *dev,
struct platform_device *pdev = to_platform_device(dev);
char *driver_override, *old, *cp;
- if (count > PATH_MAX)
+ /* We need to keep extra room for a newline */
+ if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);