* [patch] cx231xx: card->driver "Conexant cx231xx Audio" too long @ 2010-03-19 11:49 Dan Carpenter 2010-03-22 14:46 ` Takashi Iwai 0 siblings, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2010-03-19 11:49 UTC (permalink / raw) To: Mauro Carvalho Chehab Cc: Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors card->driver is 15 characters and a NULL, the original code could cause a buffer overflow. Signed-off-by: Dan Carpenter <error27@gmail.com> diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c index 7793d60..b3282ae 100644 --- a/drivers/media/video/cx231xx/cx231xx-audio.c +++ b/drivers/media/video/cx231xx/cx231xx-audio.c @@ -495,7 +495,7 @@ static int cx231xx_audio_init(struct cx231xx *dev) pcm->info_flags = 0; pcm->private_data = dev; strcpy(pcm->name, "Conexant cx231xx Capture"); - strcpy(card->driver, "Conexant cx231xx Audio"); + strcpy(card->driver, "Cx231xx Audio"); strcpy(card->shortname, "Cx231xx Audio"); strcpy(card->longname, "Conexant cx231xx Audio"); ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [patch] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-19 11:49 [patch] cx231xx: card->driver "Conexant cx231xx Audio" too long Dan Carpenter @ 2010-03-22 14:46 ` Takashi Iwai 2010-03-22 15:39 ` [patch v2] " Dan Carpenter 0 siblings, 1 reply; 9+ messages in thread From: Takashi Iwai @ 2010-03-22 14:46 UTC (permalink / raw) To: Dan Carpenter Cc: Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors At Fri, 19 Mar 2010 14:49:57 +0300, Dan Carpenter wrote: > > card->driver is 15 characters and a NULL, the original code could > cause a buffer overflow. > > Signed-off-by: Dan Carpenter <error27@gmail.com> This should rather a string without spaces because this string is used as an identifier in alsa-lib. Better to use "Cx231xx" or "Cx231xx-Audio". Takashi > > diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c > index 7793d60..b3282ae 100644 > --- a/drivers/media/video/cx231xx/cx231xx-audio.c > +++ b/drivers/media/video/cx231xx/cx231xx-audio.c > @@ -495,7 +495,7 @@ static int cx231xx_audio_init(struct cx231xx *dev) > pcm->info_flags = 0; > pcm->private_data = dev; > strcpy(pcm->name, "Conexant cx231xx Capture"); > - strcpy(card->driver, "Conexant cx231xx Audio"); > + strcpy(card->driver, "Cx231xx Audio"); > strcpy(card->shortname, "Cx231xx Audio"); > strcpy(card->longname, "Conexant cx231xx Audio"); > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > ^ permalink raw reply [flat|nested] 9+ messages in thread
* [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 14:46 ` Takashi Iwai @ 2010-03-22 15:39 ` Dan Carpenter 2010-03-22 15:43 ` Joe Perches 2010-03-23 6:59 ` Takashi Iwai 0 siblings, 2 replies; 9+ messages in thread From: Dan Carpenter @ 2010-03-22 15:39 UTC (permalink / raw) To: Takashi Iwai Cc: Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors card->driver is 15 characters and a NULL, the original code could cause a buffer overflow. Signed-off-by: Dan Carpenter <error27@gmail.com> --- In version 2, I used a better name that Takashi Iwai suggested. diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c index 7793d60..7cae95a 100644 --- a/drivers/media/video/cx231xx/cx231xx-audio.c +++ b/drivers/media/video/cx231xx/cx231xx-audio.c @@ -495,7 +495,7 @@ static int cx231xx_audio_init(struct cx231xx *dev) pcm->info_flags = 0; pcm->private_data = dev; strcpy(pcm->name, "Conexant cx231xx Capture"); - strcpy(card->driver, "Conexant cx231xx Audio"); + strcpy(card->driver, "Cx231xx-Audio"); strcpy(card->shortname, "Cx231xx Audio"); strcpy(card->longname, "Conexant cx231xx Audio"); ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 15:39 ` [patch v2] " Dan Carpenter @ 2010-03-22 15:43 ` Joe Perches 2010-03-22 16:04 ` Takashi Iwai 2010-03-23 6:59 ` Takashi Iwai 1 sibling, 1 reply; 9+ messages in thread From: Joe Perches @ 2010-03-22 15:43 UTC (permalink / raw) To: Dan Carpenter Cc: Takashi Iwai, Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors On Mon, 2010-03-22 at 18:39 +0300, Dan Carpenter wrote: > card->driver is 15 characters and a NULL, the original code could > cause a buffer overflow. > In version 2, I used a better name that Takashi Iwai suggested. Perhaps it's better to use strncpy as well. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 15:43 ` Joe Perches @ 2010-03-22 16:04 ` Takashi Iwai 2010-03-22 16:54 ` Dan Carpenter 2010-03-23 16:43 ` Marcin Slusarz 0 siblings, 2 replies; 9+ messages in thread From: Takashi Iwai @ 2010-03-22 16:04 UTC (permalink / raw) To: Joe Perches Cc: Dan Carpenter, Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors At Mon, 22 Mar 2010 08:43:47 -0700, Joe Perches wrote: > > On Mon, 2010-03-22 at 18:39 +0300, Dan Carpenter wrote: > > card->driver is 15 characters and a NULL, the original code could > > cause a buffer overflow. > > > In version 2, I used a better name that Takashi Iwai suggested. > > Perhaps it's better to use strncpy as well. strlcpy() would be safer :) But, in such a case, we want rather that the error is notified at build time. Maybe a macro like below would be helpful to catch such bugs? #define COPY_STRING(buf, src) \ do { \ if (__builtin_constant_p(src)) \ BUILD_BUG_ON(strlen(src) >= sizeof(buf)); \ strcpy(buf, src); \ } while (0) and used like: struct foo { char foo[5]; } x; COPY_STRING(x.foo, "OK"); // OK COPY_STRING(x.foo, "1234567890"); // NG Takashi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 16:04 ` Takashi Iwai @ 2010-03-22 16:54 ` Dan Carpenter 2010-03-22 16:57 ` Takashi Iwai 2010-03-23 16:43 ` Marcin Slusarz 1 sibling, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2010-03-22 16:54 UTC (permalink / raw) To: Takashi Iwai Cc: Joe Perches, Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors On Mon, Mar 22, 2010 at 05:04:55PM +0100, Takashi Iwai wrote: > At Mon, 22 Mar 2010 08:43:47 -0700, > Joe Perches wrote: > > > > On Mon, 2010-03-22 at 18:39 +0300, Dan Carpenter wrote: > > > card->driver is 15 characters and a NULL, the original code could > > > cause a buffer overflow. > > > > > In version 2, I used a better name that Takashi Iwai suggested. > > > > Perhaps it's better to use strncpy as well. > > strlcpy() would be safer :) > > But, in such a case, we want rather that the error is notified at > build time. > > Maybe a macro like below would be helpful to catch such bugs? > > #define COPY_STRING(buf, src) \ > do { \ > if (__builtin_constant_p(src)) \ > BUILD_BUG_ON(strlen(src) >= sizeof(buf)); \ > strcpy(buf, src); \ > } while (0) > > and used like: > > struct foo { > char foo[5]; > } x; > > COPY_STRING(x.foo, "OK"); // OK > COPY_STRING(x.foo, "1234567890"); // NG > I can do the same thing with Smatch. The smatch check can also find bugs like this: buf = kmalloc(10, GFP_KERNEL); strcpy(buf, "1234567890"); I used smatch to find this bug and 5 others on my allmodconfig w/ staging. I also found 19 other places that use strcpy() to copy from a large buffer into a smaller buffer. Your idea is nice, but I think anyone who deliberately uses the new macro is not going to have the bug in the first place. ;) regards, dan carpenter > > Takashi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 16:54 ` Dan Carpenter @ 2010-03-22 16:57 ` Takashi Iwai 0 siblings, 0 replies; 9+ messages in thread From: Takashi Iwai @ 2010-03-22 16:57 UTC (permalink / raw) To: Dan Carpenter Cc: Joe Perches, Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors At Mon, 22 Mar 2010 19:54:30 +0300, Dan Carpenter wrote: > > On Mon, Mar 22, 2010 at 05:04:55PM +0100, Takashi Iwai wrote: > > At Mon, 22 Mar 2010 08:43:47 -0700, > > Joe Perches wrote: > > > > > > On Mon, 2010-03-22 at 18:39 +0300, Dan Carpenter wrote: > > > > card->driver is 15 characters and a NULL, the original code could > > > > cause a buffer overflow. > > > > > > > In version 2, I used a better name that Takashi Iwai suggested. > > > > > > Perhaps it's better to use strncpy as well. > > > > strlcpy() would be safer :) > > > > But, in such a case, we want rather that the error is notified at > > build time. > > > > Maybe a macro like below would be helpful to catch such bugs? > > > > #define COPY_STRING(buf, src) \ > > do { \ > > if (__builtin_constant_p(src)) \ > > BUILD_BUG_ON(strlen(src) >= sizeof(buf)); \ > > strcpy(buf, src); \ > > } while (0) > > > > and used like: > > > > struct foo { > > char foo[5]; > > } x; > > > > COPY_STRING(x.foo, "OK"); // OK > > COPY_STRING(x.foo, "1234567890"); // NG > > > > I can do the same thing with Smatch. The smatch check can also find > bugs like this: > > buf = kmalloc(10, GFP_KERNEL); > strcpy(buf, "1234567890"); > > I used smatch to find this bug and 5 others on my allmodconfig w/ staging. > I also found 19 other places that use strcpy() to copy from a large buffer > into a smaller buffer. Ah, nice. > Your idea is nice, but I think anyone who deliberately uses the new > macro is not going to have the bug in the first place. ;) Yeah, in theory, such a code should be never committed because it can be caught at build time ;) Takashi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 16:04 ` Takashi Iwai 2010-03-22 16:54 ` Dan Carpenter @ 2010-03-23 16:43 ` Marcin Slusarz 1 sibling, 0 replies; 9+ messages in thread From: Marcin Slusarz @ 2010-03-23 16:43 UTC (permalink / raw) To: Takashi Iwai Cc: Joe Perches, Dan Carpenter, Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors On Mon, Mar 22, 2010 at 05:04:55PM +0100, Takashi Iwai wrote: > At Mon, 22 Mar 2010 08:43:47 -0700, > Joe Perches wrote: > > > > On Mon, 2010-03-22 at 18:39 +0300, Dan Carpenter wrote: > > > card->driver is 15 characters and a NULL, the original code could > > > cause a buffer overflow. > > > > > In version 2, I used a better name that Takashi Iwai suggested. > > > > Perhaps it's better to use strncpy as well. > > strlcpy() would be safer :) > > But, in such a case, we want rather that the error is notified at > build time. > > Maybe a macro like below would be helpful to catch such bugs? > > #define COPY_STRING(buf, src) \ > do { \ > if (__builtin_constant_p(src)) \ > BUILD_BUG_ON(strlen(src) >= sizeof(buf)); \ > strcpy(buf, src); \ > } while (0) > > and used like: > > struct foo { > char foo[5]; > } x; > > COPY_STRING(x.foo, "OK"); // OK > COPY_STRING(x.foo, "1234567890"); // NG why not define strcpy this way? Marcin ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too long 2010-03-22 15:39 ` [patch v2] " Dan Carpenter 2010-03-22 15:43 ` Joe Perches @ 2010-03-23 6:59 ` Takashi Iwai 1 sibling, 0 replies; 9+ messages in thread From: Takashi Iwai @ 2010-03-23 6:59 UTC (permalink / raw) To: Dan Carpenter Cc: Mauro Carvalho Chehab, Srinivasa Deevi, linux-media, linux-kernel, kernel-janitors At Mon, 22 Mar 2010 18:39:09 +0300, Dan Carpenter wrote: > > card->driver is 15 characters and a NULL, the original code could > cause a buffer overflow. > > Signed-off-by: Dan Carpenter <error27@gmail.com> > --- > In version 2, I used a better name that Takashi Iwai suggested. Acked-by: Takashi Iwai <tiwai@suse.de> Could you fix em28xx in the same way, too? thanks, Takashi > diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c > index 7793d60..7cae95a 100644 > --- a/drivers/media/video/cx231xx/cx231xx-audio.c > +++ b/drivers/media/video/cx231xx/cx231xx-audio.c > @@ -495,7 +495,7 @@ static int cx231xx_audio_init(struct cx231xx *dev) > pcm->info_flags = 0; > pcm->private_data = dev; > strcpy(pcm->name, "Conexant cx231xx Capture"); > - strcpy(card->driver, "Conexant cx231xx Audio"); > + strcpy(card->driver, "Cx231xx-Audio"); > strcpy(card->shortname, "Cx231xx Audio"); > strcpy(card->longname, "Conexant cx231xx Audio"); > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-03-23 16:46 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-03-19 11:49 [patch] cx231xx: card->driver "Conexant cx231xx Audio" too long Dan Carpenter 2010-03-22 14:46 ` Takashi Iwai 2010-03-22 15:39 ` [patch v2] " Dan Carpenter 2010-03-22 15:43 ` Joe Perches 2010-03-22 16:04 ` Takashi Iwai 2010-03-22 16:54 ` Dan Carpenter 2010-03-22 16:57 ` Takashi Iwai 2010-03-23 16:43 ` Marcin Slusarz 2010-03-23 6:59 ` Takashi Iwai
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox