These are all likely copy/paste defects where the field size of the 'copied to' array is incorrect. Each patch in this series is independent. Joe Perches (8): Input: synaptics: Fix misuse of strlcpy leds: as3645a: Fix misuse of strlcpy media: m2m-deinterlace: Fix misuse of strscpy media: go7007: Fix misuse of strscpy net: ethernet: sun4i-emac: Fix misuse of strlcpy net: nixge: Fix misuse of strlcpy tty: hvcs: Fix odd use of strlcpy nfsd: Fix misuse of strlcpy drivers/input/mouse/synaptics.c | 2 +- drivers/leds/leds-as3645a.c | 2 +- drivers/media/platform/m2m-deinterlace.c | 2 +- drivers/media/usb/go7007/snd-go7007.c | 2 +- drivers/net/ethernet/allwinner/sun4i-emac.c | 4 ++-- drivers/net/ethernet/ni/nixge.c | 2 +- drivers/tty/hvc/hvcs.c | 4 ++-- fs/nfsd/nfs4idmap.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/input/mouse/synaptics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 1080c0c49815..00a0cf14f27f 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -705,7 +705,7 @@ static void synaptics_pt_create(struct psmouse *psmouse) serio->id.type = SERIO_PS_PSTHRU; strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); - strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); + strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->phys)); serio->write = synaptics_pt_write; serio->start = synaptics_pt_start; serio->stop = synaptics_pt_stop; -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/leds/leds-as3645a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c index 14ab6b0e4de9..050088dff8dd 100644 --- a/drivers/leds/leds-as3645a.c +++ b/drivers/leds/leds-as3645a.c @@ -668,7 +668,7 @@ static int as3645a_v4l2_setup(struct as3645a *flash) }; strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name)); - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); + strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfgind.dev_name)); flash->vf = v4l2_flash_init( &flash->client->dev, flash->flash_node, &flash->fled, NULL, -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/media/platform/m2m-deinterlace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c index beb7fd7442fb..dd573d23d0ce 100644 --- a/drivers/media/platform/m2m-deinterlace.c +++ b/drivers/media/platform/m2m-deinterlace.c @@ -436,7 +436,7 @@ static int vidioc_querycap(struct file *file, void *priv, { strscpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver)); strscpy(cap->card, MEM2MEM_NAME, sizeof(cap->card)); - strscpy(cap->bus_info, MEM2MEM_NAME, sizeof(cap->card)); + strscpy(cap->bus_info, MEM2MEM_NAME, sizeof(cap->bus_info)); /* * This is only a mem-to-mem video device. The capture and output * device capability flags are left only for backward compatibility -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/media/usb/go7007/snd-go7007.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/go7007/snd-go7007.c b/drivers/media/usb/go7007/snd-go7007.c index 4a449c62fc32..b05fa227ffb2 100644 --- a/drivers/media/usb/go7007/snd-go7007.c +++ b/drivers/media/usb/go7007/snd-go7007.c @@ -253,7 +253,7 @@ int go7007_snd_init(struct go7007 *go) return ret; } strscpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver)); - strscpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->driver)); + strscpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->shortname)); strscpy(gosnd->card->longname, gosnd->card->shortname, sizeof(gosnd->card->longname)); -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/net/ethernet/allwinner/sun4i-emac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c index 9e06dff619c3..40a359dd90b4 100644 --- a/drivers/net/ethernet/allwinner/sun4i-emac.c +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c @@ -224,8 +224,8 @@ static int emac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) static void emac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { - strlcpy(info->driver, DRV_NAME, sizeof(DRV_NAME)); - strlcpy(info->version, DRV_VERSION, sizeof(DRV_VERSION)); + strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); + strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strlcpy(info->bus_info, dev_name(&dev->dev), sizeof(info->bus_info)); } -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/net/ethernet/ni/nixge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c index 96f7a9818294..0b384f97d2fd 100644 --- a/drivers/net/ethernet/ni/nixge.c +++ b/drivers/net/ethernet/ni/nixge.c @@ -990,7 +990,7 @@ static void nixge_ethtools_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *ed) { strlcpy(ed->driver, "nixge", sizeof(ed->driver)); - strlcpy(ed->bus_info, "platform", sizeof(ed->driver)); + strlcpy(ed->bus_info, "platform", sizeof(ed->bus_info)); } static int nixge_ethtools_get_coalesce(struct net_device *ndev, -- 2.15.0
Use the typical style of array, not the equivalent &array[0]. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/tty/hvc/hvcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index cb4db1b3ca3c..b6c1c1be06f9 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -871,8 +871,8 @@ static void hvcs_set_pi(struct hvcs_partner_info *pi, struct hvcs_struct *hvcsd) hvcsd->p_partition_ID = pi->partition_ID; /* copy the null-term char too */ - strlcpy(&hvcsd->p_location_code[0], - &pi->location_code[0], sizeof(hvcsd->p_location_code)); + strlcpy(hvcsd->p_location_code, pi->location_code, + sizeof(hvcsd->p_location_code)); } /* -- 2.15.0
Probable cut&paste typo - use the correct field size. Signed-off-by: Joe Perches <joe@perches.com> --- fs/nfsd/nfs4idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index 2961016097ac..d1f285245af8 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c @@ -83,7 +83,7 @@ ent_init(struct cache_head *cnew, struct cache_head *citm) new->type = itm->type; strlcpy(new->name, itm->name, sizeof(new->name)); - strlcpy(new->authname, itm->authname, sizeof(new->name)); + strlcpy(new->authname, itm->authname, sizeof(new->authname)); } static void -- 2.15.0
On Thu, Jul 04, 2019 at 04:57:42PM -0700, Joe Perches wrote: > Probable cut&paste typo - use the correct field size. > > Signed-off-by: Joe Perches <joe@perches.com> Thanks, Joe! Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > drivers/leds/leds-as3645a.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c > index 14ab6b0e4de9..050088dff8dd 100644 > --- a/drivers/leds/leds-as3645a.c > +++ b/drivers/leds/leds-as3645a.c > @@ -668,7 +668,7 @@ static int as3645a_v4l2_setup(struct as3645a *flash) > }; > > strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name)); > - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); > + strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfgind.dev_name)); > > flash->vf = v4l2_flash_init( > &flash->client->dev, flash->flash_node, &flash->fled, NULL, -- Kind regards, Sakari Ailus
[-- Attachment #1: Type: text/plain, Size: 1023 bytes --] On Thu 2019-07-04 16:57:42, Joe Perches wrote: > Probable cut&paste typo - use the correct field size. > > Signed-off-by: Joe Perches <joe@perches.com> Ack. Pavel > --- > drivers/leds/leds-as3645a.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c > index 14ab6b0e4de9..050088dff8dd 100644 > --- a/drivers/leds/leds-as3645a.c > +++ b/drivers/leds/leds-as3645a.c > @@ -668,7 +668,7 @@ static int as3645a_v4l2_setup(struct as3645a *flash) > }; > > strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name)); > - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); > + strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfgind.dev_name)); > > flash->vf = v4l2_flash_init( > &flash->client->dev, flash->flash_node, &flash->fled, NULL, -- (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 --]
From: Joe Perches <joe@perches.com>
Date: Thu, 4 Jul 2019 16:57:45 -0700
> Probable cut&paste typo - use the correct field size.
>
> Signed-off-by: Joe Perches <joe@perches.com>
Applied.
From: Joe Perches <joe@perches.com>
Date: Thu, 4 Jul 2019 16:57:46 -0700
> Probable cut&paste typo - use the correct field size.
>
> Signed-off-by: Joe Perches <joe@perches.com>
Applied.
On Thu, Jul 04, 2019 at 04:57:48PM -0700, Joe Perches wrote: > Probable cut&paste typo - use the correct field size. Huh, that's been there forever, I wonder why we haven't seen crashes? Oh, I see, name and authname both have the same size. Anyway, makes sense, thanks. Will apply for 5.3. (Unless someone else is getting this; I didn't get copied on the rest of the series.) --b. > > Signed-off-by: Joe Perches <joe@perches.com> > --- > fs/nfsd/nfs4idmap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c > index 2961016097ac..d1f285245af8 100644 > --- a/fs/nfsd/nfs4idmap.c > +++ b/fs/nfsd/nfs4idmap.c > @@ -83,7 +83,7 @@ ent_init(struct cache_head *cnew, struct cache_head *citm) > new->type = itm->type; > > strlcpy(new->name, itm->name, sizeof(new->name)); > - strlcpy(new->authname, itm->authname, sizeof(new->name)); > + strlcpy(new->authname, itm->authname, sizeof(new->authname)); > } > > static void > -- > 2.15.0
On Mon, 2019-07-08 at 23:14 -0400, J. Bruce Fields wrote: > On Thu, Jul 04, 2019 at 04:57:48PM -0700, Joe Perches wrote: > > Probable cut&paste typo - use the correct field size. > > Huh, that's been there forever, I wonder why we haven't seen crashes? > Oh, I see, name and authname both have the same size. > > Anyway, makes sense, thanks. Will apply for 5.3. > > (Unless someone else is getting this; I didn't get copied on the rest of > the series.) It's generally hard to cc everyone on treewide fixes like this. There's no good mechanism I know of. vger mailing lists reject emails with too many addressees. Do you have an opinion on adding the stracpy macro which could avoid many of these defects? --- include/linux/string.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 4deb11f7976b..ef01bd6f19df 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -35,6 +35,22 @@ ssize_t strscpy(char *, const char *, size_t); /* Wraps calls to strscpy()/memset(), no arch specific code required */ ssize_t strscpy_pad(char *dest, const char *src, size_t count); +#define stracpy(to, from) \ +({ \ + size_t size = ARRAY_SIZE(to); \ + BUILD_BUG_ON(!__same_type(typeof(*to), char)); \ + \ + strscpy(to, from, size); \ +}) + +#define stracpy_pad(to, from) \ +({ \ + size_t size = ARRAY_SIZE(to); \ + BUILD_BUG_ON(!__same_type(typeof(*to), char)); \ + \ + strscpy_pad(to, from, size); \ +}) + #ifndef __HAVE_ARCH_STRCAT extern char * strcat(char *, const char *); #endif
On Mon, Jul 08, 2019 at 10:40:50PM -0700, Joe Perches wrote: > On Mon, 2019-07-08 at 23:14 -0400, J. Bruce Fields wrote: > > On Thu, Jul 04, 2019 at 04:57:48PM -0700, Joe Perches wrote: > > > Probable cut&paste typo - use the correct field size. > > > > Huh, that's been there forever, I wonder why we haven't seen crashes? > > Oh, I see, name and authname both have the same size. > > > > Anyway, makes sense, thanks. Will apply for 5.3. > > > > (Unless someone else is getting this; I didn't get copied on the rest of > > the series.) > > It's generally hard to cc everyone on treewide fixes like this. > > There's no good mechanism I know of. > vger mailing lists reject emails with too many addressees. Yeah. I guess what I don't understand is why this patch is part of a series at all. It makes me wonder if there's some dependency I missed or if the 0/8 mail actually asked somebody else to apply it. Whatever, I guess I'm being silly, it clearly stands alone. Applying for 5.3. > Do you have an opinion on adding the stracpy macro which > could avoid many of these defects? I don't have an opinion. --b. > --- > include/linux/string.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/string.h b/include/linux/string.h > index 4deb11f7976b..ef01bd6f19df 100644 > --- a/include/linux/string.h > +++ b/include/linux/string.h > @@ -35,6 +35,22 @@ ssize_t strscpy(char *, const char *, size_t); > /* Wraps calls to strscpy()/memset(), no arch specific code required */ > ssize_t strscpy_pad(char *dest, const char *src, size_t count); > > +#define stracpy(to, from) \ > +({ \ > + size_t size = ARRAY_SIZE(to); \ > + BUILD_BUG_ON(!__same_type(typeof(*to), char)); \ > + \ > + strscpy(to, from, size); \ > +}) > + > +#define stracpy_pad(to, from) \ > +({ \ > + size_t size = ARRAY_SIZE(to); \ > + BUILD_BUG_ON(!__same_type(typeof(*to), char)); \ > + \ > + strscpy_pad(to, from, size); \ > +}) > + > #ifndef __HAVE_ARCH_STRCAT > extern char * strcat(char *, const char *); > #endif > >
On Thu, Jul 04, 2019 at 04:57:41PM -0700, Joe Perches wrote: > Probable cut&paste typo - use the correct field size. Applied, thank you. Luckily both sizes (name and phys) are the same, so we need not to have this in any of the stables. > > Signed-off-by: Joe Perches <joe@perches.com> > --- > drivers/input/mouse/synaptics.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c > index 1080c0c49815..00a0cf14f27f 100644 > --- a/drivers/input/mouse/synaptics.c > +++ b/drivers/input/mouse/synaptics.c > @@ -705,7 +705,7 @@ static void synaptics_pt_create(struct psmouse *psmouse) > > serio->id.type = SERIO_PS_PSTHRU; > strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); > - strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); > + strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->phys)); > serio->write = synaptics_pt_write; > serio->start = synaptics_pt_start; > serio->stop = synaptics_pt_stop; > -- > 2.15.0 > -- Dmitry
Hi Joe,
Thank you for the patch.
On 7/5/19 1:57 AM, Joe Perches wrote:
> Probable cut&paste typo - use the correct field size.
>
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> drivers/leds/leds-as3645a.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c
> index 14ab6b0e4de9..050088dff8dd 100644
> --- a/drivers/leds/leds-as3645a.c
> +++ b/drivers/leds/leds-as3645a.c
> @@ -668,7 +668,7 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
> };
>
> strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name));
> - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name));
> + strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfgind.dev_name));
>
> flash->vf = v4l2_flash_init(
> &flash->client->dev, flash->flash_node, &flash->fled, NULL,
>
Applied to for-5.4 branch of linux-leds.git.
--
Best regards,
Jacek Anaszewski