Skip to content

Commit c23965b

Browse files
quic-deesinandersson
authored andcommitted
rpmsg: ctrl: Add lock to rpmsg_ctrldev_remove
Call to rpmsg_ctrldev_ioctl() and rpmsg_ctrldev_remove() must be synchronized. In present code rpmsg_ctrldev_remove() is not protected with lock, therefore new char device creation can succeed through rpmsg_ctrldev_ioctl() call. At the same time call to rpmsg_ctrldev_remove() function for ctrl device removal will free associated rpdev device. As char device creation already succeeded, user space is free to issue open() call which maps to rpmsg_create_ept() in kernel. rpmsg_create_ept() function tries to reference rpdev which has already been freed through rpmsg_ctrldev_remove(). Issue is predominantly seen in aggressive reboot tests where rpmsg_ctrldev_ioctl() and rpmsg_ctrldev_remove() can race with each other. Adding lock in rpmsg_ctrldev_remove() avoids any new char device creation through rpmsg_ctrldev_ioctl() while remove call is already in progress. Signed-off-by: Deepak Kumar Singh <quic_deesin@quicinc.com> Signed-off-by: Bjorn Andersson <andersson@kernel.org> Link: https://lore.kernel.org/r/1663584840-15762-3-git-send-email-quic_deesin@quicinc.com
1 parent 17b88a2 commit c23965b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/rpmsg/rpmsg_ctrl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ static void rpmsg_ctrldev_remove(struct rpmsg_device *rpdev)
194194
struct rpmsg_ctrldev *ctrldev = dev_get_drvdata(&rpdev->dev);
195195
int ret;
196196

197+
mutex_lock(&ctrldev->ctrl_lock);
197198
/* Destroy all endpoints */
198199
ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_chrdev_eptdev_destroy);
199200
if (ret)
200201
dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret);
202+
mutex_unlock(&ctrldev->ctrl_lock);
201203

202204
cdev_device_del(&ctrldev->cdev, &ctrldev->dev);
203205
put_device(&ctrldev->dev);

0 commit comments

Comments
 (0)