* [PATCH 0/2] of/irq: Bugfixes for linux-next branch
@ 2013-11-02 8:24 Grant Likely
2013-11-02 8:24 ` [PATCH 1/2] of/irq: Fix bug in interrupt parsing refactor Grant Likely
2013-11-02 8:24 ` [PATCH 2/2] of/irq: Fix potential buffer overflow Grant Likely
0 siblings, 2 replies; 3+ messages in thread
From: Grant Likely @ 2013-11-02 8:24 UTC (permalink / raw)
To: devicetree-discuss, linux-kernel
A couple of patches I'm about to push onto my linux-next branch. They
are bug fixes to patches I've already applied instead of rebasing the
branch.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] of/irq: Fix bug in interrupt parsing refactor.
2013-11-02 8:24 [PATCH 0/2] of/irq: Bugfixes for linux-next branch Grant Likely
@ 2013-11-02 8:24 ` Grant Likely
2013-11-02 8:24 ` [PATCH 2/2] of/irq: Fix potential buffer overflow Grant Likely
1 sibling, 0 replies; 3+ messages in thread
From: Grant Likely @ 2013-11-02 8:24 UTC (permalink / raw)
To: devicetree-discuss, linux-kernel; +Cc: Grant Likely, Rob Herring
Commit 2361613206e6, "of/irq: Refactor interrupt-map parsing" introduced
a bug. The irq parsing will fail for some nodes that don't have a reg
property. It is fixed by deferring the check for reg until it is
actually needed. Also adjust the testcase data to catch the bug.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Tested-by: Stephen Warren <swarren@nvidia.com>
Cc: Rob Herring <rob.herring@calxeda.com>
---
arch/arm/boot/dts/testcases/tests-interrupts.dtsi | 6 +++---
drivers/of/irq.c | 20 ++++++++++----------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/arch/arm/boot/dts/testcases/tests-interrupts.dtsi b/arch/arm/boot/dts/testcases/tests-interrupts.dtsi
index 560d6bf680b6..94cd511a1f64 100644
--- a/arch/arm/boot/dts/testcases/tests-interrupts.dtsi
+++ b/arch/arm/boot/dts/testcases/tests-interrupts.dtsi
@@ -2,7 +2,7 @@
/ {
testcase-data {
interrupts {
- #address-cells = <0>;
+ #address-cells = <1>;
test_intc0: intc0 {
interrupt-controller;
#interrupt-cells = <1>;
@@ -29,8 +29,7 @@
test_intmap1: intmap1 {
#interrupt-cells = <2>;
- #address-cells = <0>;
- interrupt-map = <1 2 &test_intc0 15>;
+ interrupt-map = <0x5000 1 2 &test_intc0 15>;
};
interrupts0 {
@@ -44,6 +43,7 @@
};
interrupts-extended0 {
+ reg = <0x5000>;
interrupts-extended = <&test_intc0 1>,
<&test_intc1 2 3 4>,
<&test_intc2 5 6>,
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 8cc62b4a7988..52dba6a01423 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -147,18 +147,9 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
pr_debug(" -> addrsize=%d\n", addrsize);
- /* If we were passed no "reg" property and we attempt to parse
- * an interrupt-map, then #address-cells must be 0.
- * Fail if it's not.
- */
- if (addr == NULL && addrsize != 0) {
- pr_debug(" -> no reg passed in when needed !\n");
- return -EINVAL;
- }
-
/* Precalculate the match array - this simplifies match loop */
for (i = 0; i < addrsize; i++)
- initial_match_array[i] = addr[i];
+ initial_match_array[i] = addr ? addr[i] : 0;
for (i = 0; i < intsize; i++)
initial_match_array[addrsize + i] = cpu_to_be32(out_irq->args[i]);
@@ -174,6 +165,15 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
return 0;
}
+ /*
+ * interrupt-map parsing does not work without a reg
+ * property when #address-cells != 0
+ */
+ if (addrsize && !addr) {
+ pr_debug(" -> no reg passed in when needed !\n");
+ goto fail;
+ }
+
/* Now look for an interrupt-map */
imap = of_get_property(ipar, "interrupt-map", &imaplen);
/* No interrupt map, check for an interrupt parent */
--
1.8.1.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] of/irq: Fix potential buffer overflow
2013-11-02 8:24 [PATCH 0/2] of/irq: Bugfixes for linux-next branch Grant Likely
2013-11-02 8:24 ` [PATCH 1/2] of/irq: Fix bug in interrupt parsing refactor Grant Likely
@ 2013-11-02 8:24 ` Grant Likely
1 sibling, 0 replies; 3+ messages in thread
From: Grant Likely @ 2013-11-02 8:24 UTC (permalink / raw)
To: devicetree-discuss, linux-kernel; +Cc: Grant Likely, Rob Herring
Commit 2361613206e6, "of/irq: Refactor interrupt-map parsing" introduced
a potential buffer overflow bug because it doesn't do sufficient range
checking on the input data. This patch adds the appropriate checking and
buffer size adjustments. If the bounds are out of range then warn
loudly. MAX_PHANDLE_ARGS should be sufficient. If it is not then the
value can be increased.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
---
drivers/of/irq.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 52dba6a01423..d385bb824772 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -95,9 +95,9 @@ struct device_node *of_irq_find_parent(struct device_node *child)
int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
{
struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL;
- __be32 initial_match_array[8];
+ __be32 initial_match_array[MAX_PHANDLE_ARGS];
const __be32 *match_array = initial_match_array;
- const __be32 *tmp, *imap, *imask, dummy_imask[] = { ~0, ~0, ~0, ~0, ~0 };
+ const __be32 *tmp, *imap, *imask, dummy_imask[] = { [0 ... MAX_PHANDLE_ARGS] = ~0 };
u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0;
int imaplen, match, i;
@@ -147,6 +147,10 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
pr_debug(" -> addrsize=%d\n", addrsize);
+ /* Range check so that the temporary buffer doesn't overflow */
+ if (WARN_ON(addrsize + intsize > MAX_PHANDLE_ARGS))
+ goto fail;
+
/* Precalculate the match array - this simplifies match loop */
for (i = 0; i < addrsize; i++)
initial_match_array[i] = addr ? addr[i] : 0;
@@ -229,6 +233,8 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
newintsize, newaddrsize);
/* Check for malformed properties */
+ if (WARN_ON(newaddrsize + newintsize > MAX_PHANDLE_ARGS))
+ goto fail;
if (imaplen < (newaddrsize + newintsize))
goto fail;
--
1.8.1.2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-02 22:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-02 8:24 [PATCH 0/2] of/irq: Bugfixes for linux-next branch Grant Likely
2013-11-02 8:24 ` [PATCH 1/2] of/irq: Fix bug in interrupt parsing refactor Grant Likely
2013-11-02 8:24 ` [PATCH 2/2] of/irq: Fix potential buffer overflow Grant Likely
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®