Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1fc302c authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman
Browse files

mailbox: mailbox-test: fix a locking issue in mbox_test_message_write()



[ Upstream commit 8fe72b76db79d694858e872370df49676bc3be8c ]

There was a bug where this code forgot to unlock the tdev->mutex if the
kzalloc() failed.  Fix this issue, by moving the allocation outside the
lock.

Fixes: 2d1e952a2b8e ("mailbox: mailbox-test: Fix potential double-free in mbox_test_message_write()")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarLee Jones <lee@kernel.org>
Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 35027a6a
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ static ssize_t mbox_test_message_write(struct file *filp,
				       size_t count, loff_t *ppos)
{
	struct mbox_test_device *tdev = filp->private_data;
	char *message;
	void *data;
	int ret;

@@ -116,12 +117,13 @@ static ssize_t mbox_test_message_write(struct file *filp,
		return -EINVAL;
	}

	mutex_lock(&tdev->mutex);

	tdev->message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
	if (!tdev->message)
	message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
	if (!message)
		return -ENOMEM;

	mutex_lock(&tdev->mutex);

	tdev->message = message;
	ret = copy_from_user(tdev->message, userbuf, count);
	if (ret) {
		ret = -EFAULT;