Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2017-08-23 18:04:04 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-09-09 17:39:35 +0200
commit3ef5220bdba723f80b0654e58f5a8c05b739d34e (patch)
treea13fc3c1f0fdc18e9e845d216427ffbc63c534f6
parentaee0b37b710e8de6497bad31556750f6c02f0e26 (diff)
of/device: Prevent buffer overflow in of_device_modalias()
commit 08ab58d9de3eb8498ae0585001d0975e46217a39 upstream. As of_device_get_modalias() returns the number of bytes that would have been written to the target string, regardless of how much did fit in the buffer, it's possible that the returned index points beyond the buffer passed to of_device_modalias() - causing memory beyond the buffer to be null terminated. Fixes: 0634c2958927 ("of: Add function for generating a DT modalias with a newline") Cc: Rob Herring <robh@kernel.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/of/device.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 28c38c756f92..9af44f6dc17b 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -274,6 +274,8 @@ ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)
ssize_t sl = of_device_get_modalias(dev, str, len - 2);
if (sl < 0)
return sl;
+ if (sl > len - 2)
+ return -ENOMEM;
str[sl++] = '\n';
str[sl] = 0;