Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mailbox: mailbox-test: Prevent memory leak

If we set the Signal twice or more, without using it as part of a message,
memory will be re-allocated and the pointer over-written. Prevent this
potential leak by only allocating memory when there isn't any already.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>

authored by

Lee Jones and committed by
Jassi Brar
d1c2f87c 17f5f28f

+6 -3
+6 -3
drivers/mailbox/mailbox-test.c
··· 59 59 return -EINVAL; 60 60 } 61 61 62 - tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL); 63 - if (!tdev->signal) 64 - return -ENOMEM; 62 + /* Only allocate memory if we need to */ 63 + if (!tdev->signal) { 64 + tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL); 65 + if (!tdev->signal) 66 + return -ENOMEM; 67 + } 65 68 66 69 if (copy_from_user(tdev->signal, userbuf, count)) { 67 70 kfree(tdev->signal);