OSDN Git Service

media: dvb-core: Fix UAF due to refcount races at releasing
authorTakashi Iwai <tiwai@suse.de>
Mon, 31 Oct 2022 10:02:45 +0000 (11:02 +0100)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 4 Nov 2022 15:56:43 +0000 (16:56 +0100)
commitfd3d91ab1c6ab0628fe642dd570b56302c30a792
tree1537b372fc2ae0a9b4a2fe0634f8017b9cb0295e
parent00c47aa85bb26450edc6059c3d245de062e60b5d
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.

CVE-2022-41218 is assigned to those bugs above.

Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/20220908132754.30532-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/dvb-core/dmxdev.c