Skip to content

Commit a574359

Browse files
Chen Zhongjinmchehab
authored andcommitted
media: dvb-core: Fix ignored return value in dvb_register_frontend()
In dvb_register_frontend(), dvb_register_device() is possible to fail but its return value is ignored. It will cause use-after-free when module is removed, because in dvb_unregister_frontend() it tries to unregister a not registered device. BUG: KASAN: use-after-free in dvb_remove_device+0x18b/0x1f0 [dvb_core] Read of size 4 at addr ffff88800dff4824 by task rmmod/428 CPU: 3 PID: 428 Comm: rmmod Call Trace: <TASK> ... dvb_remove_device+0x18b/0x1f0 [dvb_core] dvb_unregister_frontend+0x7b/0x130 [dvb_core] vidtv_bridge_remove+0x6e/0x160 [dvb_vidtv_bridge] ... Fix this by catching return value of dvb_register_device(). However the fe->refcount can't be put to zero immediately, because there are still modules calling dvb_frontend_detach() when dvb_register_frontend() fails. Link: https://lore.kernel.org/linux-media/20221108033005.169095-1-chenzhongjin@huawei.com Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 0f298a4 commit a574359

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/media/dvb-core/dvb_frontend.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,7 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
30073007
.name = fe->ops.info.name,
30083008
#endif
30093009
};
3010+
int ret;
30103011

30113012
dev_dbg(dvb->device, "%s:\n", __func__);
30123013

@@ -3040,8 +3041,13 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
30403041
"DVB: registering adapter %i frontend %i (%s)...\n",
30413042
fe->dvb->num, fe->id, fe->ops.info.name);
30423043

3043-
dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
3044+
ret = dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
30443045
fe, DVB_DEVICE_FRONTEND, 0);
3046+
if (ret) {
3047+
dvb_frontend_put(fe);
3048+
mutex_unlock(&frontend_mutex);
3049+
return ret;
3050+
}
30453051

30463052
/*
30473053
* Initialize the cache to the proper values according with the

0 commit comments

Comments
 (0)