diff options
author | Bjorn Andersson <bjorn.andersson@linaro.org> | 2017-08-24 04:04:04 +0300 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2017-08-24 19:52:38 +0300 |
commit | 08ab58d9de3eb8498ae0585001d0975e46217a39 (patch) | |
tree | 1c2ce257d07973ec01dc87aa4764f1a0cce18bf0 | |
parent | 3cffda2575168054c6c7871fd076f415b49bb547 (diff) | |
download | linux-08ab58d9de3eb8498ae0585001d0975e46217a39.tar.xz |
of/device: Prevent buffer overflow in of_device_modalias()
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>
Cc: stable@vger.kernel.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/device.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/of/device.c b/drivers/of/device.c index 9d0895fb53b5..c5c06997fdd2 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -257,6 +257,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; |