of/device: Prevent buffer overflow in of_device_modalias()
authorBjorn Andersson <bjorn.andersson@linaro.org>
Thu, 24 Aug 2017 01:04:04 +0000 (18:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 Sep 2017 15:39:28 +0000 (17:39 +0200)
commitd29e6c2a62cfa53e131e4e669d7fa0492c200b04
treee1bfeda3a0a3e10d47b229f81e9779cd967c1a43
parent9cbbaf10840410f4bf40d4e3a10a03fa8d3878ce
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>
drivers/of/device.c