Skip to content

Commit efccd54

Browse files
bluesheep1337gregkh
authored andcommitted
media: saa7134: fix use after free bug in saa7134_finidev due to race condition
[ Upstream commit 30cf57d ] In saa7134_initdev, it will call saa7134_hwinit1. There are three function invoking here: saa7134_video_init1, saa7134_ts_init1 and saa7134_vbi_init1. All of them will init a timer with same function. Take saa7134_video_init1 as an example. It'll bound &dev->video_q.timeout with saa7134_buffer_timeout. In buffer_activate, the timer funtcion is started. If we remove the module or device which will call saa7134_finidev to make cleanup, there may be a unfinished work. The possible sequence is as follows, which will cause a typical UAF bug. Fix it by canceling the timer works accordingly before cleanup in saa7134_finidev. CPU0 CPU1 |saa7134_buffer_timeout saa7134_finidev | kfree(dev); | | | saa7134_buffer_next | //use dev Fixes: 1e7126b ("media: saa7134: Convert timers to use timer_setup()") Signed-off-by: Zheng Wang <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ad99807 commit efccd54

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

drivers/media/pci/saa7134/saa7134-ts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ int saa7134_ts_start(struct saa7134_dev *dev)
300300

301301
int saa7134_ts_fini(struct saa7134_dev *dev)
302302
{
303+
del_timer_sync(&dev->ts_q.timeout);
303304
saa7134_pgtable_free(dev->pci, &dev->ts_q.pt);
304305
return 0;
305306
}

drivers/media/pci/saa7134/saa7134-vbi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int saa7134_vbi_init1(struct saa7134_dev *dev)
185185
int saa7134_vbi_fini(struct saa7134_dev *dev)
186186
{
187187
/* nothing */
188+
del_timer_sync(&dev->vbi_q.timeout);
188189
return 0;
189190
}
190191

drivers/media/pci/saa7134/saa7134-video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,7 @@ int saa7134_video_init1(struct saa7134_dev *dev)
21462146

21472147
void saa7134_video_fini(struct saa7134_dev *dev)
21482148
{
2149+
del_timer_sync(&dev->video_q.timeout);
21492150
/* free stuff */
21502151
saa7134_pgtable_free(dev->pci, &dev->video_q.pt);
21512152
saa7134_pgtable_free(dev->pci, &dev->vbi_q.pt);

0 commit comments

Comments
 (0)