treewide: correct misuses of strscpy/strlcpy
Subsystems (13)
cover treewide: correct misuses of strscpy/strlcpy
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(-)
Signature · 1 line
2.15.0
PATCH 1/8 Input: synaptics: Fix misuse of strlcpy
Probable cut&paste typo - use the correct field size.
--- drivers/input/mouse/synaptics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/mouse/synaptics.c +1 -1
@@ -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;
Signature · 1 line
2.15.0
Re: [PATCH 1/8] Input: synaptics: Fix misuse of strlcpy
Quoted 1 line · Joe Perches
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.
Quoted 22 lines
Signed-off-by Joe Perches <[email protected]>--- drivers/input/mouse/synaptics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/input/mouse/synaptics.c +1
-1@@ -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;Signature · 1 line
2.15.0
Signature · 1 line
Dmitry
PATCH 2/8 leds: as3645a: Fix misuse of strlcpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- drivers/leds/leds-as3645a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-as3645a.c +1 -1
@@ -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,
Signature · 1 line
2.15.0
Re: [PATCH 2/8] leds: as3645a: Fix misuse of strlcpy
Quoted 3 lines · Joe Perches
Probable cut&paste typo - use the correct field size.
Signed-off-by Joe Perches <[email protected]>
Thanks, Joe!
Quoted 17 lines
--- drivers/leds/leds-as3645a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/leds/leds-as3645a.c +1
-1@@ -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,
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH 2/8] leds: as3645a: Fix misuse of strlcpy
In reply to Joe PerchesQuoted 3 lines · Joe Perches
Probable cut&paste typo - use the correct field size.
Signed-off-by Joe Perches <[email protected]>
Ack.
Pavel
Quoted 17 lines
--- drivers/leds/leds-as3645a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/leds/leds-as3645a.c +1
-1@@ -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,
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Jacek Anaszewski
AppliedRe: [PATCH 2/8] leds: as3645a: Fix misuse of strlcpy
In reply to Joe PerchesHi Joe,
Thank you for the patch.
Quoted 13 lines · Joe Perches
Probable cut&paste typo - use the correct field size.
Signed-off-by Joe Perches <[email protected]>--- drivers/leds/leds-as3645a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/leds/leds-as3645a.c +0
-0
drivers/leds/leds-as3645a.c static int as3645a_v4l2_setup(struct as3645a *flash) · line 674
Quoted 8 lines
drivers/leds/leds-as3645a.c +1
-1@@ -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.
Signature · 2 lines
Best regards, Jacek Anaszewski
PATCH 3/8 media: m2m-deinterlace: Fix misuse of strscpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- drivers/media/platform/m2m-deinterlace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/m2m-deinterlace.c +1 -1
@@ -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
Signature · 1 line
2.15.0
PATCH 4/8 media: go7007: Fix misuse of strscpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- drivers/media/usb/go7007/snd-go7007.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/go7007/snd-go7007.c +1 -1
@@ -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));
Signature · 1 line
2.15.0
PATCH 5/8 net: ethernet: sun4i-emac: Fix misuse of strlcpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- drivers/net/ethernet/allwinner/sun4i-emac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/allwinner/sun4i-emac.c +2 -2
@@ -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)); }
Signature · 1 line
2.15.0
Re: [PATCH 5/8] net: ethernet: sun4i-emac: Fix misuse of strlcpy
From: Joe Perches <[email protected]>
Date: Thu, 4 Jul 2019 16:57:45 -0700
Quoted 3 lines
Probable cut&paste typo - use the correct field size.
Signed-off-by Joe Perches <[email protected]>
Applied.
PATCH 6/8 net: nixge: Fix misuse of strlcpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- drivers/net/ethernet/ni/nixge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ni/nixge.c +1 -1
@@ -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,
Signature · 1 line
2.15.0
Re: [PATCH 6/8] net: nixge: Fix misuse of strlcpy
From: Joe Perches <[email protected]>
Date: Thu, 4 Jul 2019 16:57:46 -0700
Quoted 3 lines
Probable cut&paste typo - use the correct field size.
Signed-off-by Joe Perches <[email protected]>
Applied.
PATCH 7/8 tty: hvcs: Fix odd use of strlcpy
In reply to Joe PerchesUse the typical style of array, not the equivalent &array[0].
--- drivers/tty/hvc/hvcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/hvc/hvcs.c +2 -2
@@ -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)); }/*
Signature · 1 line
2.15.0
PATCH 8/8 nfsd: Fix misuse of strlcpy
In reply to Joe PerchesProbable cut&paste typo - use the correct field size.
--- fs/nfsd/nfs4idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4idmap.c +1 -1
@@ -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
Signature · 1 line
2.15.0
Re: [PATCH 8/8] nfsd: Fix misuse of strlcpy
Quoted 1 line · Joe Perches
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.
Quoted 21 lines
Signed-off-by Joe Perches <[email protected]>--- fs/nfsd/nfs4idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4idmap.c +1
-1@@ -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 voidSignature · 1 line
2.15.0
Re: [PATCH 8/8] nfsd: Fix misuse of strlcpy
Quoted 10 lines · J. Bruce Fields
Quoted 1 line · Joe Perches
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(+)
include/linux/string.h +16 -0
@@ -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_STRCATextern char *strcat (char *,const char *);#endif
Re: [PATCH 8/8] nfsd: Fix misuse of strlcpy
Quoted 9 lines · Joe Perches
Quoted 8 lines · J. Bruce Fields
Quoted 1 line · Joe Perches
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.
Quoted 7 lines
Quoted 2 lines
(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.
Quoted 2 lines
Do you have an opinion on adding the stracpy macro which could avoid many of these defects?
I don't have an opinion.
--b.
Quoted 33 lines
--- include/linux/string.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)include/linux/string.h +16
-0@@ -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_STRCATextern char *strcat (char *,const char *);#endif