media: dvb-usb: fix memory leak in cinergyt2_frontend_attach
PATCH 1/1 media: dvb-usb: fix memory leak in cinergyt2_frontend_attach
My local syzbot instance hit a memory leak incinergyt2_frontend_attach() [1].
The problem was in non-freed dvb_frontend in case of error. If dvb_usb_generic_rw() call fails, an error will be returned from cinergyt2_frontend_attach() [1] and num_adapters_initialized of dvb_usb_device won't be incremented. That means dvb usb library won't take care of freeing allocated frontend.
Fail log:
BUG: memory leak
unreferenced object 0xffff88801d9c6000 (size 2048):
comm "kworker/1:3", pid 2960, jiffies 4295150569 (age 17.150s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 54 65 72 72 61 54 65 63 ........TerraTec
2f 71 61 6e 75 20 55 53 42 32 2e 30 20 48 69 67 /qanu USB2.0 Hig
backtrace:
[<ffffffff85e169f0>] kmalloc include/linux/slab.h:556 [inline]
[<ffffffff85e169f0>] kzalloc include/linux/slab.h:686 [inline]
[<ffffffff85e169f0>] cinergyt2_fe_attach+0x40/0x110 drivers/media/usb/dvb-usb/cinergyT2-fe.c:271
[<ffffffff85e15b31>] cinergyt2_frontend_attach+0x61/0x140 drivers/media/usb/dvb-usb/cinergyT2-core.c:74 [1]
[<ffffffff85dcd71e>] dvb_usb_adapter_frontend_init+0x35e/0x5b0 drivers/media/usb/dvb-usb/dvb-usb-dvb.c:290
[<ffffffff88f98e83>] dvb_usb_adapter_init drivers/media/usb/dvb-usb/dvb-usb-init.c:90 [inline]
[<ffffffff88f98e83>] dvb_usb_init drivers/media/usb/dvb-usb/dvb-usb-init.c:184 [inline]driver")
--- drivers/media/usb/dvb-usb/cinergyT2-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/usb/dvb-usb/cinergyT2-core.c +1 -0
@@ -79,6 +79,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) ret =dvb_usb_generic_rw (d, st->data,1 , st->data,3 ,0 );if (ret <0 ) {deb_rc ("cinergyt2_power_ctrl() Failed to retrieve sleep state info\n" ); +kfree (adap->fe_adap[0 ].fe); }mutex_unlock (&d->data_mutex);
Signature · 1 line
2.32.0
Quoted 8 lines · Pavel Skripkin
My local syzbot instance hit a memory leak in
cinergyt2_frontend_attach()[1].The problem was in non-freed
dvb_frontendin case of error. Ifdvb_usb_generic_rw()call fails, an error will be returned fromcinergyt2_frontend_attach()[1] andnum_adapters_initializedofdvb_usb_devicewon't be incremented. That means dvb usb library won't take care of freeing allocated frontend.
This issue is already fixed by:
9ad1efee086e0 media: dvd_usb: memory leak in cinergyt2_fe_attach
Thanks for reporting and making a patch though.
Sean
Quoted 38 lines
Fail log:
BUG: memory leak unreferenced object 0xffff88801d9c6000 (size 2048): comm "kworker/1:3", pid 2960, jiffies 4295150569 (age 17.150s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 54 65 72 72 61 54 65 63 ........TerraTec 2f 71 61 6e 75 20 55 53 42 32 2e 30 20 48 69 67 /qanu USB2.0 Hig backtrace: [<ffffffff85e169f0>] kmalloc include/linux/slab.h:556 [inline] [<ffffffff85e169f0>] kzalloc include/linux/slab.h:686 [inline] [<ffffffff85e169f0>] cinergyt2_fe_attach+0x40/0x110 drivers/media/usb/dvb-usb/cinergyT2-fe.c:271 [<ffffffff85e15b31>] cinergyt2_frontend_attach+0x61/0x140 drivers/media/usb/dvb-usb/cinergyT2-core.c:74 [1] [<ffffffff85dcd71e>] dvb_usb_adapter_frontend_init+0x35e/0x5b0 drivers/media/usb/dvb-usb/dvb-usb-dvb.c:290 [<ffffffff88f98e83>] dvb_usb_adapter_init drivers/media/usb/dvb-usb/dvb-usb-init.c:90 [inline] [<ffffffff88f98e83>] dvb_usb_init drivers/media/usb/dvb-usb/dvb-usb-init.c:184 [inline]Fixes 986bd1e58b18 ("V4L/DVB (9107): Alternative version of Terratec Cinergy T2driver")
Signed-off-by Pavel Skripkin <[email protected]>--- drivers/media/usb/dvb-usb/cinergyT2-core.c | 1 + 1 file changed, 1 insertion(+)drivers/media/usb/dvb-usb/cinergyT2-core.c +1
-0@@ -79,6 +79,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) ret =dvb_usb_generic_rw (d, st->data,1 , st->data,3 ,0 );if (ret <0 ) {deb_rc ("cinergyt2_power_ctrl() Failed to retrieve sleep state info\n" ); +kfree (adap->fe_adap[0 ].fe); }mutex_unlock (&d->data_mutex);Signature · 1 line
2.32.0