Skip to content

Commit

Permalink
of/device: Prevent buffer overflow in of_device_modalias()
Browse files Browse the repository at this point in the history
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: 0634c29 ("of: Add function for generating a DT modalias with a newline")
Cc: Rob Herring <[email protected]>
Cc: [email protected]
Signed-off-by: Bjorn Andersson <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
andersson authored and robherring committed Aug 24, 2017
1 parent 3cffda2 commit 08ab58d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/of/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 08ab58d

Please sign in to comment.