Skip to content

Commit c926a55

Browse files
committed
Merge tag 'media/v6.4-6' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: "A fix for dvb-core to avoid a race condition during DVB board registration" * tag 'media/v6.4-6' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: Revert "media: dvb-core: Fix use-after-free on race condition at dvb_frontend"
2 parents 62d8779 + ec21a38 commit c926a55

2 files changed

Lines changed: 10 additions & 49 deletions

File tree

drivers/media/dvb-core/dvb_frontend.c

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -817,26 +817,15 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
817817

818818
dev_dbg(fe->dvb->device, "%s:\n", __func__);
819819

820-
mutex_lock(&fe->remove_mutex);
821-
822820
if (fe->exit != DVB_FE_DEVICE_REMOVED)
823821
fe->exit = DVB_FE_NORMAL_EXIT;
824822
mb();
825823

826-
if (!fepriv->thread) {
827-
mutex_unlock(&fe->remove_mutex);
824+
if (!fepriv->thread)
828825
return;
829-
}
830826

831827
kthread_stop(fepriv->thread);
832828

833-
mutex_unlock(&fe->remove_mutex);
834-
835-
if (fepriv->dvbdev->users < -1) {
836-
wait_event(fepriv->dvbdev->wait_queue,
837-
fepriv->dvbdev->users == -1);
838-
}
839-
840829
sema_init(&fepriv->sem, 1);
841830
fepriv->state = FESTATE_IDLE;
842831

@@ -2780,22 +2769,17 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
27802769
struct dvb_adapter *adapter = fe->dvb;
27812770
int ret;
27822771

2783-
mutex_lock(&fe->remove_mutex);
2784-
27852772
dev_dbg(fe->dvb->device, "%s:\n", __func__);
2786-
if (fe->exit == DVB_FE_DEVICE_REMOVED) {
2787-
ret = -ENODEV;
2788-
goto err_remove_mutex;
2789-
}
2773+
if (fe->exit == DVB_FE_DEVICE_REMOVED)
2774+
return -ENODEV;
27902775

27912776
if (adapter->mfe_shared == 2) {
27922777
mutex_lock(&adapter->mfe_lock);
27932778
if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
27942779
if (adapter->mfe_dvbdev &&
27952780
!adapter->mfe_dvbdev->writers) {
27962781
mutex_unlock(&adapter->mfe_lock);
2797-
ret = -EBUSY;
2798-
goto err_remove_mutex;
2782+
return -EBUSY;
27992783
}
28002784
adapter->mfe_dvbdev = dvbdev;
28012785
}
@@ -2818,10 +2802,8 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
28182802
while (mferetry-- && (mfedev->users != -1 ||
28192803
mfepriv->thread)) {
28202804
if (msleep_interruptible(500)) {
2821-
if (signal_pending(current)) {
2822-
ret = -EINTR;
2823-
goto err_remove_mutex;
2824-
}
2805+
if (signal_pending(current))
2806+
return -EINTR;
28252807
}
28262808
}
28272809

@@ -2833,8 +2815,7 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
28332815
if (mfedev->users != -1 ||
28342816
mfepriv->thread) {
28352817
mutex_unlock(&adapter->mfe_lock);
2836-
ret = -EBUSY;
2837-
goto err_remove_mutex;
2818+
return -EBUSY;
28382819
}
28392820
adapter->mfe_dvbdev = dvbdev;
28402821
}
@@ -2893,8 +2874,6 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
28932874

28942875
if (adapter->mfe_shared)
28952876
mutex_unlock(&adapter->mfe_lock);
2896-
2897-
mutex_unlock(&fe->remove_mutex);
28982877
return ret;
28992878

29002879
err3:
@@ -2916,9 +2895,6 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
29162895
err0:
29172896
if (adapter->mfe_shared)
29182897
mutex_unlock(&adapter->mfe_lock);
2919-
2920-
err_remove_mutex:
2921-
mutex_unlock(&fe->remove_mutex);
29222898
return ret;
29232899
}
29242900

@@ -2929,8 +2905,6 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
29292905
struct dvb_frontend_private *fepriv = fe->frontend_priv;
29302906
int ret;
29312907

2932-
mutex_lock(&fe->remove_mutex);
2933-
29342908
dev_dbg(fe->dvb->device, "%s:\n", __func__);
29352909

29362910
if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
@@ -2952,18 +2926,10 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
29522926
}
29532927
mutex_unlock(&fe->dvb->mdev_lock);
29542928
#endif
2929+
if (fe->exit != DVB_FE_NO_EXIT)
2930+
wake_up(&dvbdev->wait_queue);
29552931
if (fe->ops.ts_bus_ctrl)
29562932
fe->ops.ts_bus_ctrl(fe, 0);
2957-
2958-
if (fe->exit != DVB_FE_NO_EXIT) {
2959-
mutex_unlock(&fe->remove_mutex);
2960-
wake_up(&dvbdev->wait_queue);
2961-
} else {
2962-
mutex_unlock(&fe->remove_mutex);
2963-
}
2964-
2965-
} else {
2966-
mutex_unlock(&fe->remove_mutex);
29672933
}
29682934

29692935
dvb_frontend_put(fe);
@@ -3064,7 +3030,6 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
30643030
fepriv = fe->frontend_priv;
30653031

30663032
kref_init(&fe->refcount);
3067-
mutex_init(&fe->remove_mutex);
30683033

30693034
/*
30703035
* After initialization, there need to be two references: one

include/media/dvb_frontend.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,7 @@ struct dtv_frontend_properties {
686686
* @id: Frontend ID
687687
* @exit: Used to inform the DVB core that the frontend
688688
* thread should exit (usually, means that the hardware
689-
* got disconnected).
690-
* @remove_mutex: mutex that avoids a race condition between a callback
691-
* called when the hardware is disconnected and the
692-
* file_operations of dvb_frontend.
689+
* got disconnected.
693690
*/
694691

695692
struct dvb_frontend {
@@ -707,7 +704,6 @@ struct dvb_frontend {
707704
int (*callback)(void *adapter_priv, int component, int cmd, int arg);
708705
int id;
709706
unsigned int exit;
710-
struct mutex remove_mutex;
711707
};
712708

713709
/**

0 commit comments

Comments
 (0)