OSDN Git Service

greybus: interface: fix potential attribute-buffer overflow
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 1 Sep 2015 10:25:27 +0000 (12:25 +0200)
committerJohan Hovold <johan@hovoldconsulting.com>
Wed, 2 Sep 2015 08:47:55 +0000 (10:47 +0200)
Use scnprintf in the generic attribute helper, which does not currently
check for buffer overflow.

The attribute helper is used to print generic strings, which could
potentially overflow the buffer. Note that the only strings currently
exported are taken from greybus string descriptors and should therefore
be limited to 255 chars.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
drivers/staging/greybus/interface.c

index c5211a3..0c3613e 100644 (file)
@@ -16,7 +16,7 @@ static ssize_t field##_show(struct device *dev,                               \
                            char *buf)                                  \
 {                                                                      \
        struct gb_interface *intf = to_gb_interface(dev);               \
-       return sprintf(buf, "%"#type"\n", intf->field);                 \
+       return scnprintf(buf, PAGE_SIZE, "%"#type"\n", intf->field);    \
 }                                                                      \
 static DEVICE_ATTR_RO(field)