cx231xx: card->driver "Conexant cx231xx Audio" too long
Subsystems (2)
PATCH 1/1 cx231xx: card->driver "Conexant cx231xx Audio" too long
card->driver is 15 characters and a NULL, the original code could cause a buffer overflow.
drivers/media/video/cx231xx/cx231xx-audio.c +1 -1
@@ -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" );
At Fri, 19 Mar 2010 14:49:57 +0300,
Quoted 5 lines · Dan Carpenter
card->driveris 15 characters and a NULL, the original code could cause a buffer overflow.Signed-off-by Dan Carpenter <[email protected]>
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
Quoted 20 lines
drivers/media/video/cx231xx/cx231xx-audio.c +1
-2@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
PATCH v2 1/1 cx231xx: card->driver "Conexant cx231xx Audio" too long
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.
drivers/media/video/cx231xx/cx231xx-audio.c +1 -1
@@ -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" );
Quoted 4 lines · Dan Carpenter
card->driveris 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.
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 8 lines · Joe Perches
Quoted 4 lines · Dan Carpenter
card->driveris 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"); // OKCOPY_STRING(x.foo, "1234567890"); // NG
Takashi
Quoted 25 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 8 lines · Joe Perches
Quoted 4 lines · Dan Carpenter
card->driveris 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)
Quoted 9 lines
and used like:
struct foo { char foo[5]; } x;
COPY_STRING(x.foo, "OK"); // OKCOPY_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
Quoted 2 lines
Takashi
At Mon, 22 Mar 2010 19:54:30 +0300,
Quoted 40 lines · Dan Carpenter
Quoted 25 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 8 lines · Joe Perches
Quoted 4 lines · Dan Carpenter
card->driveris 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)Quoted 9 lines
and used like:
struct foo { char foo[5]; } x;
COPY_STRING(x.foo, "OK"); // OKCOPY_STRING(x.foo, "1234567890"); // NGI can do the same thing with Smatch. The smatch check can also find bugs like this:
Quoted 6 lines
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.
Quoted 2 lines
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
Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too
In reply to Dan CarpenterQuoted 28 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 5 lines · Joe Perches
Quoted 3 lines · Dan Carpenter
card->driveris 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;
Quoted 6 lines
COPY_STRING(x.foo, "OK"); // OKCOPY_STRING(x.foo, "1234567890"); // NGTakashi
--
did i miss something ?
why not change card->driver int char * ? a simple card->driver="name" would solve the problem.
re,
wh
At Mon, 22 Mar 2010 18:18:04 +0100,
Quoted 36 lines · walter harms
Quoted 32 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 5 lines · Joe Perches
Quoted 3 lines · Dan Carpenter
card->driveris 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"); // OKCOPY_STRING(x.foo, "1234567890"); // NG
Quoted 5 lines
Quoted 2 lines
Takashi
--did i miss something ?
Yes :)
Quoted 2 lines
why not change
card->driverint char * ? a simple card->driver="name" would solve the problem.
The length is fixed because it's used for ioctl.
Takashi
Re: [patch v2] cx231xx: card->driver "Conexant cx231xx Audio" too
In reply to Dan CarpenterQuoted 39 lines · Takashi Iwai
At Mon, 22 Mar 2010 18:18:04 +0100,
Quoted 37 lines · walter harms
Quoted 33 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 5 lines · Joe Perches
Quoted 3 lines · Dan Carpenter
card->driveris 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"); // OKCOPY_STRING(x.foo, "1234567890"); // NGTakashi
--
Quoted 10 lines
Quoted 1 line
did i miss something ?
Yes :)
Quoted 2 lines
why not change
card->driverint char * ? a simple card->driver="name" would solve the problem.The length is fixed because it's used for ioctl.
I am not sure that i understand that, users can change the name ? ok who do you prevent an overflow there ? (I could not find the code) Perhaps you will simply cut the user string ? if you do that you can simply use strncpy here.
thx for fast answer,
ntl i will go offline for the next weeks
re,
wh
At Mon, 22 Mar 2010 18:39:09 +0300,
Quoted 7 lines · Dan Carpenter
card->driveris 15 characters and a NULL, the original code could cause a buffer overflow.Signed-off-by Dan Carpenter <[email protected]>---
In version 2, I used a better name that Takashi Iwai suggested.
Could you fix em28xx in the same way, too?
thanks,
Takashi
Quoted 19 lines
drivers/media/video/cx231xx/cx231xx-audio.c +1
-2@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 25 lines · Takashi Iwai
At Mon, 22 Mar 2010 08:43:47 -0700,
Quoted 8 lines · Joe Perches
Quoted 4 lines · Dan Carpenter
card->driveris 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)
Quoted 8 lines
and used like:
struct foo { char foo[5]; } x;
COPY_STRING(x.foo, "OK"); // OKCOPY_STRING(x.foo, "1234567890"); // NG
why not define strcpy this way?
Marcin