Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1718745 > unrolled thread

[PATCH] of/device: Prevent buffer overflow in of_device_modalias()

Started byBjorn Andersson <bjorn.andersson@linaro.org>
First post2017-08-24 03:10 +0200
Last post2017-08-24 18:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] of/device: Prevent buffer overflow in of_device_modalias() Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-24 03:10 +0200
    Re: [PATCH] of/device: Prevent buffer overflow in of_device_modalias() Rob Herring <robh+dt@kernel.org> - 2017-08-24 18:30 +0200

#1718745 — [PATCH] of/device: Prevent buffer overflow in of_device_modalias()

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-24 03:10 +0200
Subject[PATCH] of/device: Prevent buffer overflow in of_device_modalias()
Message-ID<uhOOK-81q-19@gated-at.bofh.it>
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>
---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 7cff599a9c6a..b58ca92934cb 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -262,6 +262,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;
-- 
2.12.0

[toc] | [next] | [standalone]


#1719393

FromRob Herring <robh+dt@kernel.org>
Date2017-08-24 18:30 +0200
Message-ID<ui3b4-tc-27@gated-at.bofh.it>
In reply to#1718745
On Wed, Aug 23, 2017 at 8:04 PM, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
> 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.

I guess ibmebus and macio had this bug for some time because I just
copied those implementations.

Applying both patches. Thanks.

Rob

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web