linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/prom: Avoid reference to potentially freed memory
@ 2015-10-16  6:14 Christophe JAILLET
  2015-10-16  7:50 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Christophe JAILLET @ 2015-10-16  6:14 UTC (permalink / raw)
  To: benh, paulus, mpe
  Cc: linuxppc-dev, linux-kernel, kernel-janitors, Christophe JAILLET

of_get_property() is used inside the loop, but then the reference to the
node is dropped before dereferencing the prop pointer, which could by then
point to junk if the node has been freed.

Instead use of_property_read_u32() to actually read the property
value before dropping the reference.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
*** UNTESTED ***
---
 arch/powerpc/kernel/prom.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index bef76c5..dc4f6a4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -783,14 +783,13 @@ void __init early_get_first_memblock_info(void *params, phys_addr_t *size)
 int of_get_ibm_chip_id(struct device_node *np)
 {
 	of_node_get(np);
-	while(np) {
+	while (np) {
 		struct device_node *old = np;
-		const __be32 *prop;
+		u32 chip_id;
 
-		prop = of_get_property(np, "ibm,chip-id", NULL);
-		if (prop) {
+		if (!of_property_read_u32(np, "ibm,chip-id", &chip_id))
 			of_node_put(np);
-			return be32_to_cpup(prop);
+			return chip_id;
 		}
 		np = of_get_parent(np);
 		of_node_put(old);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-21 11:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-16  6:14 [PATCH] powerpc/prom: Avoid reference to potentially freed memory Christophe JAILLET
2015-10-16  7:50 ` kbuild test robot
2015-10-16 10:02 ` Michael Ellerman
2015-10-16 20:09   ` Christophe JAILLET
2015-10-19  9:32     ` Michael Ellerman
2015-10-16 21:38 ` [PATCH v2] " Christophe JAILLET
2015-10-19  9:27   ` Michael Ellerman
2015-10-21  4:36     ` [PATCH v3] " Christophe JAILLET
2015-10-21 11:41   ` [v2] " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).