Skip to contentSkip to conversation

V4L/DVB: potential leak in dvb-bt8xx

PATCH In review Florin Malita 4 participants 6 messages Oct 14, 2006 – Oct 15, 2006 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 V4L/DVB: potential leak in dvb-bt8xx

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.

---

 drivers/media/dvb/bt8xx/dvb-bt8xx.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/media/dvb/bt8xx/dvb-bt8xx.c +4 -0
index fb6c4cc..d22ba4e 100644
@@ -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		*/
#1 lore raw
Quoted 4 lines · Florin Malita

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....

Quoted 39 lines

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

---

 drivers/media/dvb/bt8xx/dvb-bt8xx.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/media/dvb/bt8xx/dvb-bt8xx.c +4 -0
index fb6c4cc..d22ba4e 100644
@@ -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
[email protected]
http://www.linuxtv.org/cgi-bin/mailman/listinfo/v4l-dvb-maintainer

#2 lore raw
Quoted 4 lines · Trent Piepho

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...

---

 dvb-bt8xx.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/media/dvb/bt8xx/dvb-bt8xx.c +3 -0
index fb6c4cc..d22ba4e 100644
@@ -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;
#3 lore raw
Quoted 21 lines · Florin Malita
Quoted 4 lines · Trent Piepho

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...

---

 dvb-bt8xx.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/media/dvb/bt8xx/dvb-bt8xx.c +0 -0
index fb6c4cc..d22ba4e 100644

drivers/media/dvb/bt8xx/dvb-bt8xx.c static void frontend_init(struct dvb_bt8 · line 673

Quoted 9 lines
drivers/media/dvb/bt8xx/dvb-bt8xx.c +3 -0
@@ -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

#4 lore raw

Em Dom, 2006-10-15 às 20:35 +0400, Manu Abraham escreveu:

Quoted 7 lines
Quoted 6 lines · Florin Malita
Quoted 4 lines · Trent Piepho

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.

Quoted 5 lines
Quoted 3 lines

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.

Quoted 2 lines

Manu

Cheers,
Mauro.

#5 lore raw
Quoted 10 lines · Mauro Carvalho Chehab

Em Dom, 2006-10-15 às 20:35 +0400, Manu Abraham escreveu:

Quoted 9 lines
Quoted 8 lines · Florin Malita
Quoted 4 lines · Trent Piepho

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...

Quoted 6 lines
Quoted 1 line

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.

Quoted 6 lines

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

Quoted 1 line

Manu

Cheers,
Mauro.

Thanks,
Manu