linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* phy-rcar-gen3-usb2: wrong parsing of role in role_store?
@ 2019-07-30  9:51 Pavel Machek
  2019-07-30 10:08 ` Yoshihiro Shimoda
  2019-08-01 18:51 ` [cip-dev] " Ben Hutchings
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Machek @ 2019-07-30  9:51 UTC (permalink / raw)
  To: yoshihiro.shimoda.uh, kishon, linux-renesas-soc, linux-kernel; +Cc: cip-dev

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]

Hi!

Code does strcmps, but does not actually check count. So AFAICT
writing "host-I-don't-want-I-need-peripheral" into the file will
succeed and turn it into host mode.

Also data beyond count in buf are going to be accessed.

Best regards,
								Pavel

static ssize_t role_store(struct device *dev, struct device_attribute *attr,
                          const char *buf, size_t count)
{
        struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
        bool is_b_device;
        enum phy_mode cur_mode, new_mode;

        if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
                return -EIO;

        /* FIXME, this is wrong */
        if (!strncmp(buf, "host", strlen("host")))
                new_mode = PHY_MODE_USB_HOST;
        else if (!strncmp(buf, "peripheral", strlen("peripheral")))
                new_mode = PHY_MODE_USB_DEVICE;
        else
                return -EINVAL;


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* RE: phy-rcar-gen3-usb2: wrong parsing of role in role_store?
  2019-07-30  9:51 phy-rcar-gen3-usb2: wrong parsing of role in role_store? Pavel Machek
@ 2019-07-30 10:08 ` Yoshihiro Shimoda
  2019-08-01 18:51 ` [cip-dev] " Ben Hutchings
  1 sibling, 0 replies; 3+ messages in thread
From: Yoshihiro Shimoda @ 2019-07-30 10:08 UTC (permalink / raw)
  To: Pavel Machek, kishon, linux-renesas-soc, linux-kernel; +Cc: cip-dev

Hi Pavel,

> From: Pavel Machek, Sent: Tuesday, July 30, 2019 6:52 PM
> 
> Hi!
> 
> Code does strcmps, but does not actually check count. So AFAICT
> writing "host-I-don't-want-I-need-peripheral" into the file will
> succeed and turn it into host mode.
> 
> Also data beyond count in buf are going to be accessed.

Thank you for the report. I think the driver should use sysfs_streq() helper
instead of strncmp() on the sysfs function. So, I'll submit such a patch later.

Best regards,
Yoshihiro Shimoda

> Best regards,
> 								Pavel
> 
> static ssize_t role_store(struct device *dev, struct device_attribute *attr,
>                           const char *buf, size_t count)
> {
>         struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
>         bool is_b_device;
>         enum phy_mode cur_mode, new_mode;
> 
>         if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
>                 return -EIO;
> 
>         /* FIXME, this is wrong */
>         if (!strncmp(buf, "host", strlen("host")))
>                 new_mode = PHY_MODE_USB_HOST;
>         else if (!strncmp(buf, "peripheral", strlen("peripheral")))
>                 new_mode = PHY_MODE_USB_DEVICE;
>         else
>                 return -EINVAL;
> 
> 
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [cip-dev] phy-rcar-gen3-usb2: wrong parsing of role in role_store?
  2019-07-30  9:51 phy-rcar-gen3-usb2: wrong parsing of role in role_store? Pavel Machek
  2019-07-30 10:08 ` Yoshihiro Shimoda
@ 2019-08-01 18:51 ` Ben Hutchings
  1 sibling, 0 replies; 3+ messages in thread
From: Ben Hutchings @ 2019-08-01 18:51 UTC (permalink / raw)
  To: Pavel Machek, yoshihiro.shimoda.uh, kishon, linux-renesas-soc,
	linux-kernel
  Cc: cip-dev

On Tue, 2019-07-30 at 11:51 +0200, Pavel Machek wrote:
> Hi!
> 
> Code does strcmps, but does not actually check count. So AFAICT
> writing "host-I-don't-want-I-need-peripheral" into the file will
> succeed and turn it into host mode.

I suspect the intent is to work without a trailing "\n", but you're
right that this parsing is rather lax.

> Also data beyond count in buf are going to be accessed.

All attribute writes should be going through kernfs_fop_write(), which
writes a null terminator at buf[count] before calling the write/store
function.  (I don't know where that'ss documented though.)  So I think
this is safe.

Ben.

> static ssize_t role_store(struct device *dev, struct device_attribute *attr,
>                           const char *buf, size_t count)
> {
>         struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
>         bool is_b_device;
>         enum phy_mode cur_mode, new_mode;
> 
>         if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
>                 return -EIO;
> 
>         /* FIXME, this is wrong */
>         if (!strncmp(buf, "host", strlen("host")))
>                 new_mode = PHY_MODE_USB_HOST;
>         else if (!strncmp(buf, "peripheral", strlen("peripheral")))
>                 new_mode = PHY_MODE_USB_DEVICE;
>         else
>                 return -EINVAL;
> 
> 
> _______________________________________________
> cip-dev mailing list
> cip-dev@lists.cip-project.org
> https://lists.cip-project.org/mailman/listinfo/cip-dev
-- 
Ben Hutchings, Software Developer                         Codethink Ltd
https://www.codethink.co.uk/                 Dale House, 35 Dale Street
                                     Manchester, M1 2HF, United Kingdom


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

end of thread, other threads:[~2019-08-01 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  9:51 phy-rcar-gen3-usb2: wrong parsing of role in role_store? Pavel Machek
2019-07-30 10:08 ` Yoshihiro Shimoda
2019-08-01 18:51 ` [cip-dev] " Ben Hutchings

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