public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Charles Manning <cdhmanning@gmail.com>
To: linux-kernel@vger.kernel.org, s.trumtrar@pengutronix.de,
	dinguyen@altera.com, cslee@altera.com
Cc: Charles Manning <cdhmanning@gmail.com>
Subject: [PATCH 2/3] clk: Prevent a hanging pointer being abused
Date: Tue, 22 Jul 2014 14:20:33 +1200	[thread overview]
Message-ID: <1405995634-3297-3-git-send-email-cdhmanning@gmail.com> (raw)
In-Reply-To: <1405995634-3297-1-git-send-email-cdhmanning@gmail.com>

Clock init structs are normally created on the stack.

If the pointer is left intact after clk_register then there is
opportunity for clk drivers to dereference the pointer.

This was causing a problem in socfpga/clk.c for instance.

Better to NULL out the pointer so it can't be abused.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
---
 drivers/clk/clk.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index ec41922..9e92170 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1973,6 +1973,10 @@ struct clk *__clk_register(struct device *dev, struct clk_hw *hw)
 		clk->owner = NULL;
 
 	ret = __clk_init(dev, clk);
+
+	/* Prevent a hanging pointer being left around. */
+	hw->init = NULL;
+
 	if (ret)
 		return ERR_PTR(ret);
 
-- 
1.9.1


  parent reply	other threads:[~2014-07-22  2:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-22  2:20 [PATCH 0/3] clk : Fix SOCFPGA clk crash and some clean up Charles Manning
2014-07-22  2:20 ` [PATCH 1/3] clk : Clean up checkpatch warnings Charles Manning
2014-07-30 12:19   ` Pavel Machek
2014-07-22  2:20 ` Charles Manning [this message]
2014-07-30 12:20   ` [PATCH 2/3] clk: Prevent a hanging pointer being abused Pavel Machek
2014-07-22  2:20 ` [PATCH 3/3] clk: socfpga Change name look-up to not use the init pointer Charles Manning
2014-07-22  6:00 ` [PATCH 0/3] clk : Fix SOCFPGA clk crash and some clean up Steffen Trumtrar
2014-07-22 15:34   ` Dinh Nguyen

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=1405995634-3297-3-git-send-email-cdhmanning@gmail.com \
    --to=cdhmanning@gmail.com \
    --cc=cslee@altera.com \
    --cc=dinguyen@altera.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.trumtrar@pengutronix.de \
    /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