* [PATCH] hda_hwdep: Fix possible buffer overflow
@ 2011-10-26 7:48 Alexander Stein
2011-10-26 12:58 ` Takashi Iwai
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Stein @ 2011-10-26 7:48 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: alsa-devel, linux-kernel, Alexander Stein
If a line in the firmware file is larger than the given buffer size (and
so the firmware file size), size is set to a value larger than the actual
buffer size. This results in an overflow in the buffer passed.
Fix this by copying only up to 127 chars per line.
Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
sound/pci/hda/hda_hwdep.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index bf3ced5..61da08d 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -745,6 +745,7 @@ static int parse_line_mode(char *buf, struct hda_bus *bus)
* if successfully copied a line
*
* the spaces at the beginning and the end of the line are stripped
+ * lines read are clamped to 127 chars
*/
static int get_line_from_fw(char *buf, int size, struct firmware *fw)
{
@@ -756,8 +757,6 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
}
if (!fw->size)
return 0;
- if (size < fw->size)
- size = fw->size;
for (len = 0; len < fw->size; len++) {
if (!*p)
@@ -768,7 +767,8 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
break;
}
if (len < size)
- *buf++ = *p++;
+ *buf++ = *p;
+ p++;
}
*buf = 0;
fw->size -= len;
--
1.7.3.4
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hda_hwdep: Fix possible buffer overflow
2011-10-26 7:48 [PATCH] hda_hwdep: Fix possible buffer overflow Alexander Stein
@ 2011-10-26 12:58 ` Takashi Iwai
2011-10-26 13:15 ` Alexander Stein
0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2011-10-26 12:58 UTC (permalink / raw)
To: Alexander Stein; +Cc: Jaroslav Kysela, alsa-devel, linux-kernel
At Wed, 26 Oct 2011 09:48:12 +0200,
Alexander Stein wrote:
>
> If a line in the firmware file is larger than the given buffer size (and
> so the firmware file size), size is set to a value larger than the actual
> buffer size. This results in an overflow in the buffer passed.
> Fix this by copying only up to 127 chars per line.
Actually this check should have been
if (size > fw->size)
size = fw->size;
Otherwise it doesn't make sense.
If the change is OK, could you resend the patch with it?
thanks,
Takashi
> Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
> ---
> sound/pci/hda/hda_hwdep.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
> index bf3ced5..61da08d 100644
> --- a/sound/pci/hda/hda_hwdep.c
> +++ b/sound/pci/hda/hda_hwdep.c
> @@ -745,6 +745,7 @@ static int parse_line_mode(char *buf, struct hda_bus *bus)
> * if successfully copied a line
> *
> * the spaces at the beginning and the end of the line are stripped
> + * lines read are clamped to 127 chars
> */
> static int get_line_from_fw(char *buf, int size, struct firmware *fw)
> {
> @@ -756,8 +757,6 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
> }
> if (!fw->size)
> return 0;
> - if (size < fw->size)
> - size = fw->size;
>
> for (len = 0; len < fw->size; len++) {
> if (!*p)
> @@ -768,7 +767,8 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
> break;
> }
> if (len < size)
> - *buf++ = *p++;
> + *buf++ = *p;
> + p++;
> }
> *buf = 0;
> fw->size -= len;
> --
> 1.7.3.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hda_hwdep: Fix possible buffer overflow
2011-10-26 12:58 ` Takashi Iwai
@ 2011-10-26 13:15 ` Alexander Stein
2011-10-26 13:20 ` Takashi Iwai
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Stein @ 2011-10-26 13:15 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Jaroslav Kysela, alsa-devel, linux-kernel
Hello,
On Wednesday 26 October 2011 14:58:43 Takashi Iwai wrote:
> At Wed, 26 Oct 2011 09:48:12 +0200,
>
> Alexander Stein wrote:
> > If a line in the firmware file is larger than the given buffer size (and
> > so the firmware file size), size is set to a value larger than the actual
> > buffer size. This results in an overflow in the buffer passed.
> > Fix this by copying only up to 127 chars per line.
>
> Actually this check should have been
>
> if (size > fw->size)
> size = fw->size;
>
> Otherwise it doesn't make sense.
> If the change is OK, could you resend the patch with it?
IMO this check isn't even needed. This case should be catched by this check
for (len = 0; len < fw->size; len++) {
already.
Opinions?
Alexader
> > Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
> > ---
> >
> > sound/pci/hda/hda_hwdep.c | 6 +++---
> > 1 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
> > index bf3ced5..61da08d 100644
> > --- a/sound/pci/hda/hda_hwdep.c
> > +++ b/sound/pci/hda/hda_hwdep.c
> > @@ -745,6 +745,7 @@ static int parse_line_mode(char *buf, struct hda_bus
> > *bus)
> >
> > * if successfully copied a line
> > *
> > * the spaces at the beginning and the end of the line are stripped
> >
> > + * lines read are clamped to 127 chars
> >
> > */
> >
> > static int get_line_from_fw(char *buf, int size, struct firmware *fw)
> > {
> >
> > @@ -756,8 +757,6 @@ static int get_line_from_fw(char *buf, int size,
> > struct firmware *fw)
> >
> > }
> > if (!fw->size)
> >
> > return 0;
> >
> > - if (size < fw->size)
> > - size = fw->size;
> >
> > for (len = 0; len < fw->size; len++) {
> >
> > if (!*p)
> >
> > @@ -768,7 +767,8 @@ static int get_line_from_fw(char *buf, int size,
> > struct firmware *fw)
> >
> > break;
> >
> > }
> > if (len < size)
> >
> > - *buf++ = *p++;
> > + *buf++ = *p;
> > + p++;
> >
> > }
> > *buf = 0;
> > fw->size -= len;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hda_hwdep: Fix possible buffer overflow
2011-10-26 13:15 ` Alexander Stein
@ 2011-10-26 13:20 ` Takashi Iwai
2011-11-01 8:40 ` [PATCH v2] " Alexander Stein
0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2011-10-26 13:20 UTC (permalink / raw)
To: Alexander Stein; +Cc: Jaroslav Kysela, alsa-devel, linux-kernel
At Wed, 26 Oct 2011 15:15:24 +0200,
Alexander Stein wrote:
>
> Hello,
>
> On Wednesday 26 October 2011 14:58:43 Takashi Iwai wrote:
> > At Wed, 26 Oct 2011 09:48:12 +0200,
> >
> > Alexander Stein wrote:
> > > If a line in the firmware file is larger than the given buffer size (and
> > > so the firmware file size), size is set to a value larger than the actual
> > > buffer size. This results in an overflow in the buffer passed.
> > > Fix this by copying only up to 127 chars per line.
> >
> > Actually this check should have been
> >
> > if (size > fw->size)
> > size = fw->size;
> >
> > Otherwise it doesn't make sense.
> > If the change is OK, could you resend the patch with it?
>
> IMO this check isn't even needed. This case should be catched by this check
>
> for (len = 0; len < fw->size; len++) {
>
> already.
> Opinions?
Right, it's superfluous. Let's get rid of it.
Takashi
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2] hda_hwdep: Fix possible buffer overflow
2011-10-26 13:20 ` Takashi Iwai
@ 2011-11-01 8:40 ` Alexander Stein
2011-11-01 8:47 ` Takashi Iwai
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Stein @ 2011-11-01 8:40 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Jaroslav Kysela, alsa-devel, linux-kernel, Alexander Stein
If a line in the firmware file is larger than the given buffer size (and
so the firmware file size), size is set to a value larger than the actual
buffer size. This results in an overflow in the buffer passed.
Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
Changes in v2:
* Just remove the erroneous check
sound/pci/hda/hda_hwdep.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 72e5885..7e7d078 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -756,8 +756,6 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
}
if (!fw->size)
return 0;
- if (size < fw->size)
- size = fw->size;
for (len = 0; len < fw->size; len++) {
if (!*p)
--
1.7.3.4
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] hda_hwdep: Fix possible buffer overflow
2011-11-01 8:40 ` [PATCH v2] " Alexander Stein
@ 2011-11-01 8:47 ` Takashi Iwai
0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2011-11-01 8:47 UTC (permalink / raw)
To: Alexander Stein; +Cc: Jaroslav Kysela, alsa-devel, linux-kernel
At Tue, 1 Nov 2011 09:40:07 +0100,
Alexander Stein wrote:
>
> If a line in the firmware file is larger than the given buffer size (and
> so the firmware file size), size is set to a value larger than the actual
> buffer size. This results in an overflow in the buffer passed.
>
> Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
> ---
> Changes in v2:
> * Just remove the erroneous check
Thanks, applied now.
Takashi
>
> sound/pci/hda/hda_hwdep.c | 2 --
> 1 files changed, 0 insertions(+), 2 deletions(-)
>
> diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
> index 72e5885..7e7d078 100644
> --- a/sound/pci/hda/hda_hwdep.c
> +++ b/sound/pci/hda/hda_hwdep.c
> @@ -756,8 +756,6 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
> }
> if (!fw->size)
> return 0;
> - if (size < fw->size)
> - size = fw->size;
>
> for (len = 0; len < fw->size; len++) {
> if (!*p)
> --
> 1.7.3.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-11-01 8:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-26 7:48 [PATCH] hda_hwdep: Fix possible buffer overflow Alexander Stein
2011-10-26 12:58 ` Takashi Iwai
2011-10-26 13:15 ` Alexander Stein
2011-10-26 13:20 ` Takashi Iwai
2011-11-01 8:40 ` [PATCH v2] " Alexander Stein
2011-11-01 8:47 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®