public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] V4L/DVB: potential leak in dvb-bt8xx
@ 2006-10-14 17:39 Florin Malita
  2006-10-15  0:33 ` [v4l-dvb-maintainer] " Trent Piepho
  0 siblings, 1 reply; 6+ messages in thread
From: Florin Malita @ 2006-10-14 17:39 UTC (permalink / raw)
  To: mchehab, v4l-dvb-maintainer; +Cc: linux-kernel

If dvb_attach
<http://www.coverity.com:7448/display-error.cgi?user=fmalita&magic=8997c91336813f372812011c89e0e75e&source=2693a21be69533084392e43c4f3c5220&runid=86&table=file&line=107>(dst_attach,
...) fails in *frontend_init*(), the previously allocated 'state' is
leaked (Coverity ID 1437).

Also, when allocating 'state' the result of kmalloc() needs to be checked.

Signed-off-by: Florin Malita <fmalita@gmail.com>
---

 drivers/media/dvb/bt8xx/dvb-bt8xx.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index fb6c4cc..d22ba4e 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -665,6 +665,9 @@ static void frontend_init(struct dvb_bt8
 	case BTTV_BOARD_TWINHAN_DST:
 		/*	DST is not a frontend driver !!!		*/
 		state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
+		if (!state)
+			break;
+
 		/*	Setup the Card					*/
 		state->config = &dst_config;
 		state->i2c = card->i2c_adapter;
@@ -673,6 +676,7 @@ static void frontend_init(struct dvb_bt8
 		/*	DST is not a frontend, attaching the ASIC	*/
 		if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) {
 			printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__);
+			kfree(state);
 			break;
 		}
 		/*	Attach other DST peripherals if any		*/



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [v4l-dvb-maintainer] [PATCH] V4L/DVB: potential leak in dvb-bt8xx
  2006-10-14 17:39 [PATCH] V4L/DVB: potential leak in dvb-bt8xx Florin Malita
@ 2006-10-15  0:33 ` Trent Piepho
  2006-10-15 16:02   ` Florin Malita
  0 siblings, 1 reply; 6+ messages in thread
From: Trent Piepho @ 2006-10-15  0:33 UTC (permalink / raw)
  To: Florin Malita
  Cc: Mauro Carvalho Chehab, v4l-dvb maintainer list, linux-kernel

On Sat, 14 Oct 2006, Florin Malita wrote:
> If dvb_attach
> <http://www.coverity.com:7448/display-error.cgi?user=fmalita&magic=8997c91336813f372812011c89e0e75e&source=2693a21be69533084392e43c4f3c5220&runid=86&table=file&line=107>(dst_attach,
> ...) fails in *frontend_init*(), the previously allocated 'state' is
> leaked (Coverity ID 1437).

I believe that 'state' will be kfree'd by the dst_attach() function if there
is a failure.  Not what you would expect, to have it allocated in the bt8xx
driver (why do is there??) and freed on error in a different function.

You know, I had a patch to fix all these dst problems two months ago....

>
> Also, when allocating 'state' the result of kmalloc() needs to be checked.
>
> Signed-off-by: Florin Malita <fmalita@gmail.com>
> ---
>
>  drivers/media/dvb/bt8xx/dvb-bt8xx.c |    4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> index fb6c4cc..d22ba4e 100644
> --- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> @@ -665,6 +665,9 @@ static void frontend_init(struct dvb_bt8
>  	case BTTV_BOARD_TWINHAN_DST:
>  		/*	DST is not a frontend driver !!!		*/
>  		state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
> +		if (!state)
> +			break;
> +
>  		/*	Setup the Card					*/
>  		state->config = &dst_config;
>  		state->i2c = card->i2c_adapter;
> @@ -673,6 +676,7 @@ static void frontend_init(struct dvb_bt8
>  		/*	DST is not a frontend, attaching the ASIC	*/
>  		if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) {
>  			printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__);
> +			kfree(state);
>  			break;
>  		}
>  		/*	Attach other DST peripherals if any		*/
>
>
>
> _______________________________________________
> v4l-dvb-maintainer mailing list
> v4l-dvb-maintainer@linuxtv.org
> http://www.linuxtv.org/cgi-bin/mailman/listinfo/v4l-dvb-maintainer
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [v4l-dvb-maintainer] [PATCH] V4L/DVB: potential leak in dvb-bt8xx
  2006-10-15  0:33 ` [v4l-dvb-maintainer] " Trent Piepho
@ 2006-10-15 16:02   ` Florin Malita
  2006-10-15 16:35     ` Manu Abraham
  0 siblings, 1 reply; 6+ messages in thread
From: Florin Malita @ 2006-10-15 16:02 UTC (permalink / raw)
  To: Trent Piepho; +Cc: Mauro Carvalho Chehab, v4l-dvb maintainer list, linux-kernel

Trent Piepho wrote:
> I believe that 'state' will be kfree'd by the dst_attach() function if there
> is a failure.  Not what you would expect, to have it allocated in the bt8xx
> driver (why do is there??) and freed on error in a different function.
>   

Hm, you're right - it is kfreed in dst_attach(). But we're still missing
the kmalloc result check...

Signed-off-by: Florin Malita <fmalita@gmail.com>
---

 dvb-bt8xx.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index fb6c4cc..d22ba4e 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -665,6 +665,9 @@ static void frontend_init(struct dvb_bt8
 	case BTTV_BOARD_TWINHAN_DST:
 		/*	DST is not a frontend driver !!!		*/
 		state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
+		if (!state)
+			break;
+
 		/*	Setup the Card					*/
 		state->config = &dst_config;
 		state->i2c = card->i2c_adapter;



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [v4l-dvb-maintainer] [PATCH] V4L/DVB: potential leak in dvb-bt8xx
  2006-10-15 16:02   ` Florin Malita
@ 2006-10-15 16:35     ` Manu Abraham
  2006-10-15 17:18       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 6+ messages in thread
From: Manu Abraham @ 2006-10-15 16:35 UTC (permalink / raw)
  To: Florin Malita
  Cc: Trent Piepho, v4l-dvb maintainer list, linux-kernel,
	Mauro Carvalho Chehab

Florin Malita wrote:
> Trent Piepho wrote:
>> I believe that 'state' will be kfree'd by the dst_attach() function if there
>> is a failure.  Not what you would expect, to have it allocated in the bt8xx
>> driver (why do is there??) and freed on error in a different function.
>>   
> 
> Hm, you're right - it is kfreed in dst_attach(). But we're still missing
> the kmalloc result check...
> 
> Signed-off-by: Florin Malita <fmalita@gmail.com>
> ---
> 
>  dvb-bt8xx.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> index fb6c4cc..d22ba4e 100644
> --- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
> @@ -665,6 +665,9 @@ static void frontend_init(struct dvb_bt8
>  	case BTTV_BOARD_TWINHAN_DST:
>  		/*	DST is not a frontend driver !!!		*/
>  		state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
> +		if (!state)
> +			break;
> +
>  		/*	Setup the Card					*/
>  		state->config = &dst_config;
>  		state->i2c = card->i2c_adapter;
> 



This patch was applied a few days back

Manu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [v4l-dvb-maintainer] [PATCH] V4L/DVB: potential leak in dvb-bt8xx
  2006-10-15 16:35     ` Manu Abraham
@ 2006-10-15 17:18       ` Mauro Carvalho Chehab
  2006-10-15 17:39         ` Manu Abraham
  0 siblings, 1 reply; 6+ messages in thread
From: Mauro Carvalho Chehab @ 2006-10-15 17:18 UTC (permalink / raw)
  To: Manu Abraham
  Cc: Florin Malita, Trent Piepho, v4l-dvb maintainer list,
	linux-kernel

Em Dom, 2006-10-15 às 20:35 +0400, Manu Abraham escreveu:
> Florin Malita wrote:
> > Trent Piepho wrote:
> >> I believe that 'state' will be kfree'd by the dst_attach() function if there
> >> is a failure.  Not what you would expect, to have it allocated in the bt8xx
> >> driver (why do is there??) and freed on error in a different function.
> >>   
> > 
> > Hm, you're right - it is kfreed in dst_attach(). But we're still missing
> > the kmalloc result check...
> > 
> 
> This patch was applied a few days back

Yes. 

It is at:
http://www.kernel.org/git/?p=linux/kernel/git/mchehab/v4l-dvb.git;a=commit;h=626ae83bb24927ca015503448f0199842ae2e8da

I've already asked Linus to pull it, together with other 17 fixes, to
Mainstream.
> 
> Manu
Cheers, 
Mauro.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [v4l-dvb-maintainer] [PATCH] V4L/DVB: potential leak in dvb-bt8xx
  2006-10-15 17:18       ` Mauro Carvalho Chehab
@ 2006-10-15 17:39         ` Manu Abraham
  0 siblings, 0 replies; 6+ messages in thread
From: Manu Abraham @ 2006-10-15 17:39 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Florin Malita, Trent Piepho, v4l-dvb maintainer list,
	linux-kernel

Mauro Carvalho Chehab wrote:
> Em Dom, 2006-10-15 às 20:35 +0400, Manu Abraham escreveu:
>> Florin Malita wrote:
>>> Trent Piepho wrote:
>>>> I believe that 'state' will be kfree'd by the dst_attach() function if there
>>>> is a failure.  Not what you would expect, to have it allocated in the bt8xx
>>>> driver (why do is there??) and freed on error in a different function.
>>>>   
>>> Hm, you're right - it is kfreed in dst_attach(). But we're still missing
>>> the kmalloc result check...
>>>
>> This patch was applied a few days back
> 
> Yes. 
> 
> It is at:
> http://www.kernel.org/git/?p=linux/kernel/git/mchehab/v4l-dvb.git;a=commit;h=626ae83bb24927ca015503448f0199842ae2e8da

Ok.

> 
> I've already asked Linus to pull it, together with other 17 fixes, to
> Mainstream.
>> Manu
> Cheers, 
> Mauro.


Thanks,
Manu




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-10-15 17:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-14 17:39 [PATCH] V4L/DVB: potential leak in dvb-bt8xx Florin Malita
2006-10-15  0:33 ` [v4l-dvb-maintainer] " Trent Piepho
2006-10-15 16:02   ` Florin Malita
2006-10-15 16:35     ` Manu Abraham
2006-10-15 17:18       ` Mauro Carvalho Chehab
2006-10-15 17:39         ` Manu Abraham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox