Skip to content

Commit 2b91a52

Browse files
nicstangegregkh
authored andcommitted
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 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'") Signed-off-by: Nicolai Stange <nstange@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6d1bc9e commit 2b91a52

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
@@ -809,7 +809,8 @@ static ssize_t driver_override_store(struct device *dev,
809809
struct platform_device *pdev = to_platform_device(dev);
810810
char *driver_override, *old, *cp;
811811

812-
if (count > PATH_MAX)
812+
/* We need to keep extra room for a newline */
813+
if (count >= (PAGE_SIZE - 1))
813814
return -EINVAL;
814815

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

0 commit comments

Comments
 (0)