Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fe72b7

Browse files
Dan CarpenterJassiBrar
authored andcommitted
mailbox: mailbox-test: fix a locking issue in mbox_test_message_write()
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: 2d1e952 ("mailbox: mailbox-test: Fix potential double-free in mbox_test_message_write()") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Lee Jones <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent 884fe9d commit 8fe72b7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/mailbox/mailbox-test.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static ssize_t mbox_test_message_write(struct file *filp,
9898
size_t count, loff_t *ppos)
9999
{
100100
struct mbox_test_device *tdev = filp->private_data;
101+
char *message;
101102
void *data;
102103
int ret;
103104

@@ -113,12 +114,13 @@ static ssize_t mbox_test_message_write(struct file *filp,
113114
return -EINVAL;
114115
}
115116

116-
mutex_lock(&tdev->mutex);
117-
118-
tdev->message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
119-
if (!tdev->message)
117+
message = kzalloc(MBOX_MAX_MSG_LEN, GFP_KERNEL);
118+
if (!message)
120119
return -ENOMEM;
121120

121+
mutex_lock(&tdev->mutex);
122+
123+
tdev->message = message;
122124
ret = copy_from_user(tdev->message, userbuf, count);
123125
if (ret) {
124126
ret = -EFAULT;

0 commit comments

Comments
 (0)