media: dvb-core: Fix UAF due to refcount races at releasing
PATCH 1/1 media: dvb-core: Fix UAF due to refcount races at releasing
The dvb-core tries to sync the releases of opened files at dvb_dmxdev_release() with two refcounts: dvbdev->users and dvr_dvbdev->users. A problem is present in those two syncs: when yet another dvb_demux_open() is called during those sync waits, dvb_demux_open() continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount at dvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.
This patch addresses the problem by adding the check of dmxdev->exit flag at dvb_demux_open(), just like dvb_dvr_open() already does. With the exit flag check, the second call of dvb_demux_open() fails, hence the further corruption can be avoided.
Also for avoiding the races of the dmxdev->exit flag reference, this patch serializes the dmxdev->exit set up and the sync waits with the dmxdev->mutex lock at dvb_dmxdev_release(). Without the mutex lock, dvb_demux_open() (or dvb_dvr_open()) may run concurrently with dvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/dvb-core/dmxdev.c +8 -0
@@ -790,6 +790,11 @@ static int dvb_demux_open(struct inode *inode, struct file *file)if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;
@@ -1448,7 +1453,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );
Signature · 1 line
2.35.3
Quoted 24 lines · Takashi Iwai
The dvb-core tries to sync the releases of opened files at
dvb_dmxdev_release()with two refcounts:dvbdev->usersanddvr_dvbdev->users. A problem is present in those two syncs: when yet anotherdvb_demux_open()is called during those sync waits,dvb_demux_open()continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount atdvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.This patch addresses the problem by adding the check of
dmxdev->exitflag atdvb_demux_open(), just likedvb_dvr_open()already does. With the exit flag check, the second call ofdvb_demux_open()fails, hence the further corruption can be avoided.Also for avoiding the races of the
dmxdev->exitflag reference, this patch serializes thedmxdev->exitset up and the sync waits with thedmxdev->mutexlock atdvb_dmxdev_release(). Without the mutex lock,dvb_demux_open()(ordvb_dvr_open()) may run concurrently withdvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
Quoted 3 lines
Reported-by Hyunwoo Kim <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>
Any review on this?
FWIW, now CVE-2022-41218 is assigned for those bugs as a security issue.
thanks,
Takashi
Quoted 34 lines
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/dvb-core/dmxdev.c +8
-0@@ -790,6 +790,11 @@ static int dvb_demux_open(struct inode *inode, struct file *file)if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;@@ -1448,7 +1453,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );Signature · 1 line
2.35.3
Quoted 27 lines · Takashi Iwai
Quoted 24 lines · Takashi Iwai
The dvb-core tries to sync the releases of opened files at
dvb_dmxdev_release()with two refcounts:dvbdev->usersanddvr_dvbdev->users. A problem is present in those two syncs: when yet anotherdvb_demux_open()is called during those sync waits,dvb_demux_open()continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount atdvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.This patch addresses the problem by adding the check of
dmxdev->exitflag atdvb_demux_open(), just likedvb_dvr_open()already does. With the exit flag check, the second call ofdvb_demux_open()fails, hence the further corruption can be avoided.Also for avoiding the races of the
dmxdev->exitflag reference, this patch serializes thedmxdev->exitset up and the sync waits with thedmxdev->mutexlock atdvb_dmxdev_release(). Without the mutex lock,dvb_demux_open()(ordvb_dvr_open()) may run concurrently withdvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.
Quoted 8 lines
Quoted 3 lines
Reported-by Hyunwoo Kim <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>Any review on this?
FWIW, now CVE-2022-41218 is assigned for those bugs as a security issue.
A gentle ping again.
Or if any other fix for this security issue is already available, please let me know.
thanks,
Takashi
Quoted 40 lines
thanks,
Takashi
Quoted 34 lines
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/dvb-core/dmxdev.c +8
-0@@ -790,6 +790,11 @@ static int dvb_demux_open(struct inode *inode, struct file *file)if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;@@ -1448,7 +1453,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );Signature · 1 line
2.35.3
Hi,
Quoted 35 lines · Takashi Iwai
Quoted 33 lines · Takashi Iwai
Quoted 24 lines · Takashi Iwai
The dvb-core tries to sync the releases of opened files at
dvb_dmxdev_release()with two refcounts:dvbdev->usersanddvr_dvbdev->users. A problem is present in those two syncs: when yet anotherdvb_demux_open()is called during those sync waits,dvb_demux_open()continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount atdvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.This patch addresses the problem by adding the check of
dmxdev->exitflag atdvb_demux_open(), just likedvb_dvr_open()already does. With the exit flag check, the second call ofdvb_demux_open()fails, hence the further corruption can be avoided.Also for avoiding the races of the
dmxdev->exitflag reference, this patch serializes thedmxdev->exitset up and the sync waits with thedmxdev->mutexlock atdvb_dmxdev_release(). Without the mutex lock,dvb_demux_open()(ordvb_dvr_open()) may run concurrently withdvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.Quoted 3 lines
Reported-by Hyunwoo Kim <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>Any review on this?
Quoted 7 lines
Quoted 2 lines
FWIW, now CVE-2022-41218 is assigned for those bugs as a security issue.
A gentle ping again.
Or if any other fix for this security issue is already available, please let me know.
is this correct, the fix is yet missing (or was it fixed by other means?).
Regards,
Salvatore
Quoted 36 lines
Quoted 35 lines
Quoted 35 lines
--- drivers/media/dvb-core/dmxdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/dvb-core/dmxdev.c +8
-0@@ -790,6 +790,11 @@ static int dvb_demux_open(struct inode *inode, struct file *file)if (mutex_lock_interruptible (&dmxdev->mutex))return -ERESTARTSYS ; +if (dmxdev->exit) { +mutex_unlock (&dmxdev->mutex); +return -ENODEV ; + } +for (i =0 ; i < dmxdev->filternum; i++)if (dmxdev->filter[i].state ==DMXDEV_STATE_FREE )break ;@@ -1448,7 +1453,10 @@ EXPORT_SYMBOL(dvb_dmxdev_init);void dvb_dmxdev_release (struct dmxdev *dmxdev) { +mutex_lock (&dmxdev->mutex); dmxdev->exit =1 ; +mutex_unlock (&dmxdev->mutex); +if (dmxdev->dvbdev->users >1 ) {wait_event (dmxdev->dvbdev->wait_queue, dmxdev->dvbdev->users ==1 );Signature · 1 line
2.35.3
Hi,
Quoted 41 lines · Salvatore Bonaccorso
Hi,
Quoted 38 lines · Takashi Iwai
Quoted 35 lines · Takashi Iwai
Quoted 24 lines · Takashi Iwai
The dvb-core tries to sync the releases of opened files at
dvb_dmxdev_release()with two refcounts:dvbdev->usersanddvr_dvbdev->users. A problem is present in those two syncs: when yet anotherdvb_demux_open()is called during those sync waits,dvb_demux_open()continues to process even if the device is being closed. This includes the increment of the former refcount, resulting in the leftover refcount after the sync of the latter refcount atdvb_dmxdev_release(). It ends up with use-after-free, since the function believes that all usages were gone and releases the resources.This patch addresses the problem by adding the check of
dmxdev->exitflag atdvb_demux_open(), just likedvb_dvr_open()already does. With the exit flag check, the second call ofdvb_demux_open()fails, hence the further corruption can be avoided.Also for avoiding the races of the
dmxdev->exitflag reference, this patch serializes thedmxdev->exitset up and the sync waits with thedmxdev->mutexlock atdvb_dmxdev_release(). Without the mutex lock,dvb_demux_open()(ordvb_dvr_open()) may run concurrently withdvb_dmxdev_release(), which allows to skip the exit flag check and continue the open process that is being closed.Quoted 3 lines
Reported-by Hyunwoo Kim <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>Any review on this?
FWIW, now CVE-2022-41218 is assigned for those bugs as a security issue.
Quoted 7 lines
Quoted 4 lines
A gentle ping again.
Or if any other fix for this security issue is already available, please let me know.
is this correct, the fix is yet missing (or was it fixed by other means?).
This patch has been re-send and has been missing for a long time:
https://lore.kernel.org/linux-media/[email protected]/
However, I noticed yesterday that the status of the re-send patch changed to 'accpet':
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
But there was no other feedback.
Regards,
Hyunwoo Kim