linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"
@ 2019-07-31  9:01 Yoshihiro Shimoda
  2019-07-31  9:27 ` Geert Uytterhoeven
  2019-08-14  8:21 ` Pavel Machek
  0 siblings, 2 replies; 5+ messages in thread
From: Yoshihiro Shimoda @ 2019-07-31  9:01 UTC (permalink / raw)
  To: kishon; +Cc: pavel, linux-kernel, linux-renesas-soc, stable, Yoshihiro Shimoda

Since the role_store() uses strncmp(), it's possible to refer
out-of-memory if the sysfs data size is smaller than strlen("host").
This patch fixes it by using sysfs_streq() instead of strncmp().

Reported-by: Pavel Machek <pavel@denx.de>
Fixes: 9bb86777fb71 ("phy: rcar-gen3-usb2: add sysfs for usb role swap")
Cc: <stable@vger.kernel.org> # v4.10+
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 Just a record. The role_store() doesn't need to check the count because
 the sysfs_streq() checks the first argument is NULL or not.

 On "if (sysfs_streq(buf, "host"))"
  Example 1: echo ho > role
  --> In this case, the count is 3 and the buf has "ho" + NULL.
      So, the third character differs between NULL and 's'.

  Example 2: echo host-is-not-used > role
  --> In this case, the count is 17 and the buf has "host-is-not-used" + NULL.
      So, the fifth character differs between '-' and NULL.

 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 1322185..cc18970 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/string.h>
 #include <linux/usb/of.h>
 #include <linux/workqueue.h>
 
@@ -317,9 +318,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
 	if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
 		return -EIO;
 
-	if (!strncmp(buf, "host", strlen("host")))
+	if (sysfs_streq(buf, "host"))
 		new_mode = PHY_MODE_USB_HOST;
-	else if (!strncmp(buf, "peripheral", strlen("peripheral")))
+	else if (sysfs_streq(buf, "peripheral"))
 		new_mode = PHY_MODE_USB_DEVICE;
 	else
 		return -EINVAL;
-- 
2.7.4


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

end of thread, other threads:[~2019-08-14  8:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31  9:01 [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role" Yoshihiro Shimoda
2019-07-31  9:27 ` Geert Uytterhoeven
2019-07-31  9:58   ` Yoshihiro Shimoda
2019-07-31 10:09     ` Geert Uytterhoeven
2019-08-14  8:21 ` Pavel Machek

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).