devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/device: Prevent buffer overflow in of_device_modalias()
@ 2017-08-24  1:04 Bjorn Andersson
       [not found] ` <20170824010404.9145-1-bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Bjorn Andersson @ 2017-08-24  1:04 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand; +Cc: devicetree, linux-kernel, stable, Rob Herring

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] of/device: Prevent buffer overflow in of_device_modalias()
       [not found] ` <20170824010404.9145-1-bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2017-08-24 16:24   ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2017-08-24 16:24 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable

On Wed, Aug 23, 2017 at 8:04 PM, Bjorn Andersson
<bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-24 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-24  1:04 [PATCH] of/device: Prevent buffer overflow in of_device_modalias() Bjorn Andersson
     [not found] ` <20170824010404.9145-1-bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-08-24 16:24   ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).