mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: kernel@stlinux.com, maxime.coquelin@st.com,
	jassisinghbrar@gmail.com, dan.carpenter@oracle.com,
	Lee Jones <lee.jones@linaro.org>
Subject: [PATCH v2 4/5] mailbox: mailbox-test: Prevent memory leak
Date: Wed, 23 Mar 2016 14:43:42 +0000	[thread overview]
Message-ID: <1458744223-12164-5-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1458744223-12164-1-git-send-email-lee.jones@linaro.org>

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>
---
 drivers/mailbox/mailbox-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index 5f4b439..58d0472 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -59,9 +59,12 @@ static ssize_t mbox_test_signal_write(struct file *filp,
 		return -EINVAL;
 	}
 
-	tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
-	if (!tdev->signal)
-		return -ENOMEM;
+	/* Only allocate memory if we need to */
+	if (!tdev->signal) {
+		tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
+		if (!tdev->signal)
+			return -ENOMEM;
+	}
 
 	if (copy_from_user(tdev->signal, userbuf, count)) {
 		kfree(tdev->signal);
-- 
1.9.1

  parent reply	other threads:[~2016-03-23 14:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 14:43 [PATCH v2 0/5] mailbox: A few fixes due for the v4.6 -rcs Lee Jones
2016-03-23 14:43 ` [PATCH v2 1/5] ARM: STi: stih407-family: Add nodes for Mailbox Lee Jones
2016-04-13 21:58   ` Olof Johansson
2016-03-23 14:43 ` [PATCH v2 2/5] ARM: STi: DT: STiH407: Enable Mailbox testing facility Lee Jones
2016-04-12  9:18   ` Sudeep Holla
2016-04-12 14:19     ` Lee Jones
2016-04-13 21:56   ` Olof Johansson
2016-03-23 14:43 ` [PATCH v2 3/5] mailbox: mailbox-test: Use more consistent format for calling copy_from_user() Lee Jones
2016-03-23 14:43 ` Lee Jones [this message]
2016-03-23 14:43 ` [PATCH v2 5/5] mailbox: Stop using ENOSYS for anything other than unimplemented syscalls Lee Jones
2016-04-12  7:27 ` [PATCH v2 0/5] mailbox: A few fixes due for the v4.6 -rcs Lee Jones
2016-04-12  8:06   ` Jassi Brar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458744223-12164-5-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=dan.carpenter@oracle.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=kernel@stlinux.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.coquelin@st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®