* [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
* Re: [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"
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-08-14 8:21 ` Pavel Machek
1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 9:27 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Kishon Vijay Abraham I, Pavel Machek, Linux Kernel Mailing List,
Linux-Renesas, stable
Hi Shimoda-san,
On Wed, Jul 31, 2019 at 11:04 AM Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> 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>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> 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.
Is that wat you mean? sysfs_streq() doesn't seem to check for NULL pointers.
Isn't the real reason that sysfs (kernfs) guarantees that the passed buffer
is NUL-terminated?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"
2019-07-31 9:27 ` Geert Uytterhoeven
@ 2019-07-31 9:58 ` Yoshihiro Shimoda
2019-07-31 10:09 ` Geert Uytterhoeven
0 siblings, 1 reply; 5+ messages in thread
From: Yoshihiro Shimoda @ 2019-07-31 9:58 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Kishon Vijay Abraham I, Pavel Machek, Linux Kernel Mailing List,
Linux-Renesas, stable
Hi Geert-san,
> From: Geert Uytterhoeven, Sent: Wednesday, July 31, 2019 6:27 PM
>
> Hi Shimoda-san,
>
> On Wed, Jul 31, 2019 at 11:04 AM Yoshihiro Shimoda
> <yoshihiro.shimoda.uh@renesas.com> wrote:
> > 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>
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Thank you for your review!
> > ---
> > 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.
>
> Is that wat you mean? sysfs_streq() doesn't seem to check for NULL pointers.
Oops, sorry for unclear. I meant a NULL-terminated string, not NULL pointer.
> Isn't the real reason that sysfs (kernfs) guarantees that the passed buffer
> is NUL-terminated?
I doesn't check in detail, but I assume so.
Best regards,
Yoshihiro Shimoda
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"
2019-07-31 9:58 ` Yoshihiro Shimoda
@ 2019-07-31 10:09 ` Geert Uytterhoeven
0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 10:09 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Kishon Vijay Abraham I, Pavel Machek, Linux Kernel Mailing List,
Linux-Renesas, stable
Hi Shimoda-san,
On Wed, Jul 31, 2019 at 11:58 AM Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> > From: Geert Uytterhoeven, Sent: Wednesday, July 31, 2019 6:27 PM
> > On Wed, Jul 31, 2019 at 11:04 AM Yoshihiro Shimoda
> > <yoshihiro.shimoda.uh@renesas.com> wrote:
> > > 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>
> >
> > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Thank you for your review!
>
> > > ---
> > > 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.
> >
> > Is that wat you mean? sysfs_streq() doesn't seem to check for NULL pointers.
>
> Oops, sorry for unclear. I meant a NULL-terminated string, not NULL pointer.
OK.
> > Isn't the real reason that sysfs (kernfs) guarantees that the passed buffer
> > is NUL-terminated?
>
> I doesn't check in detail, but I assume so.
I have checked that recently, so it is OK.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] phy: renesas: rcar-gen3-usb2: Fix sysfs interface of "role"
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-08-14 8:21 ` Pavel Machek
1 sibling, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2019-08-14 8:21 UTC (permalink / raw)
To: Yoshihiro Shimoda; +Cc: kishon, pavel, linux-kernel, linux-renesas-soc, stable
[-- Attachment #1: Type: text/plain, Size: 687 bytes --]
On Wed 2019-07-31 18:01:29, Yoshihiro Shimoda wrote:
> 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>
Acked-by: Pavel Machek <pavel@denx.de>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.