Skip to contentSkip to conversation

irqchip/irq-crossbar: not allocating enough memory

PATCH In review Dan Carpenter 3 participants 3 messages Apr 3, 2014 – Apr 28, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/irq-crossbar: not allocating enough memory

We are allocating the size of a pointer and not the size of the data. This will lead to memory corruption.

There isn't actually a "cb_device" struct, btw. The code is only able to compile because GCC knows that all pointers are the same size.

Fixes 96ca848ef7ea ('DRIVERS: IRQCHIP: CROSSBAR: Add support for Crossbar IP')
drivers/irqchip/irq-crossbar.c +1 -1
index fc817d2..3d15d16 100644
@@ -107,7 +107,7 @@ static int __init crossbar_of_init(struct device_node *node)
 	int i, size, max, reserved = 0, entry;
 	const __be32 *irqsr;
 
-	cb = kzalloc(sizeof(struct cb_device *), GFP_KERNEL);
+	cb = kzalloc(sizeof(*cb), GFP_KERNEL);
 
 	if (!cb)
 		return -ENOMEM;
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Dan Carpenter

We are allocating the size of a pointer and not the size of the data. This will lead to memory corruption.

There isn't actually a "cb_device" struct, btw. The code is only able to compile because GCC knows that all pointers are the same size.

Fixes 96ca848ef7ea ('DRIVERS: IRQCHIP: CROSSBAR: Add support for Crossbar IP')
drivers/irqchip/irq-crossbar.c +0 -0
index fc817d2..3d15d16 100644

drivers/irqchip/irq-crossbar.c static int __init crossbar_of_init(struct device_node *node) · line 113

Quoted 8 lines
drivers/irqchip/irq-crossbar.c +1 -1
@@ -107,7 +107,7 @@ static int __init crossbar_of_init(struct device_node *node)
 	int i, size, max, reserved = 0, entry;
 	const __be32 *irqsr;
 
-	cb = kzalloc(sizeof(struct cb_device *), GFP_KERNEL);
+	cb = kzalloc(sizeof(*cb), GFP_KERNEL);
 
 	if (!cb)
 		return -ENOMEM;

Yes. correct. Thanks for the catch.

Regards,
Sricharan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

[tip:irq/urgent] irqchip: irq-crossbar: Not allocating enough memory

In reply to Dan Carpenter
irqchip: irq-crossbar: Not allocating enough memory
Commit-ID:  3894e9e82dfdc87fa35dc7976e0472d220228826
Gitweb:     http://git.kernel.org/tip/3894e9e82dfdc87fa35dc7976e0472d220228826
Author:     Dan Carpenter <[email protected]>
AuthorDate: Thu, 3 Apr 2014 10:21:34 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Mon, 28 Apr 2014 21:43:24 +0200

irqchip: irq-crossbar: Not allocating enough memory

We are allocating the size of a pointer and not the size of the data. This will lead to memory corruption.

There isn't actually a "cb_device" struct, btw. The code is only able to compile because GCC knows that all pointers are the same size.

Fixes 96ca848ef7ea ('DRIVERS: IRQCHIP: CROSSBAR: Add support for Crossbar IP')
---
 drivers/irqchip/irq-crossbar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +1 -1
index fc817d2..3d15d16 100644
@@ -107,7 +107,7 @@ static int __init crossbar_of_init(struct device_node *node)
 	int i, size, max, reserved = 0, entry;
 	const __be32 *irqsr;
 
-	cb = kzalloc(sizeof(struct cb_device *), GFP_KERNEL);
+	cb = kzalloc(sizeof(*cb), GFP_KERNEL);
 
 	if (!cb)
 		return -ENOMEM;