Commit d29e6c2a authored by Bjorn Andersson's avatar Bjorn Andersson Committed by Greg Kroah-Hartman

of/device: Prevent buffer overflow in of_device_modalias()

commit 08ab58d9 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: 0634c295 ("of: Add function for generating a DT modalias with a newline")
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9cbbaf10
...@@ -274,6 +274,8 @@ ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) ...@@ -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); ssize_t sl = of_device_get_modalias(dev, str, len - 2);
if (sl < 0) if (sl < 0)
return sl; return sl;
if (sl > len - 2)
return -ENOMEM;
str[sl++] = '\n'; str[sl++] = '\n';
str[sl] = 0; str[sl] = 0;
......
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