media: dvb-core: Fix ignored return value in dvb_register_frontend()
[ Upstream commita574359e2e
] 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:1da177e4c3
("Linux-2.6.12-rc2") Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
05be5d56f7
commit
e34cf6cacc
@ -2961,6 +2961,7 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
|
|||||||
.name = fe->ops.info.name,
|
.name = fe->ops.info.name,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
int ret;
|
||||||
|
|
||||||
dev_dbg(dvb->device, "%s:\n", __func__);
|
dev_dbg(dvb->device, "%s:\n", __func__);
|
||||||
|
|
||||||
@ -2994,8 +2995,13 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
|
|||||||
"DVB: registering adapter %i frontend %i (%s)...\n",
|
"DVB: registering adapter %i frontend %i (%s)...\n",
|
||||||
fe->dvb->num, fe->id, fe->ops.info.name);
|
fe->dvb->num, fe->id, fe->ops.info.name);
|
||||||
|
|
||||||
dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
|
ret = dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
|
||||||
fe, DVB_DEVICE_FRONTEND, 0);
|
fe, DVB_DEVICE_FRONTEND, 0);
|
||||||
|
if (ret) {
|
||||||
|
dvb_frontend_put(fe);
|
||||||
|
mutex_unlock(&frontend_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the cache to the proper values according with the
|
* Initialize the cache to the proper values according with the
|
||||||
|
Reference in New Issue
Block a user