Skip to content

Commit bf563b0

Browse files
nicstangegregkh
authored andcommitted
driver core: platform: Don't read past the end of "driver_override" buffer
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 4efe874 ("PCI: Don't read past the end of sysfs "driver_override" buffer") from Sasha Levin. Fixes: 3d713e0 ("driver core: platform: add device binding path 'driver_override'") Cc: stable@vger.kernel.org # v3.17+ Signed-off-by: Nicolai Stange <nstange@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 452562a commit bf563b0

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/base/platform.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ static ssize_t driver_override_store(struct device *dev,
868868
struct platform_device *pdev = to_platform_device(dev);
869869
char *driver_override, *old, *cp;
870870

871-
if (count > PATH_MAX)
871+
/* We need to keep extra room for a newline */
872+
if (count >= (PAGE_SIZE - 1))
872873
return -EINVAL;
873874

874875
driver_override = kstrndup(buf, count, GFP_KERNEL);

0 commit comments

Comments
 (0)