[PATCH 4/8] of/irq: Fix using uninitialized variable @addr_len in API of_irq_parse_one()

Zijun Hu posted 8 patches 1 year ago
[PATCH 4/8] of/irq: Fix using uninitialized variable @addr_len in API of_irq_parse_one()
Posted by Zijun Hu 1 year ago
From: Zijun Hu <quic_zijuhu@quicinc.com>

of_irq_parse_one() may use uninitialized variable @addr_len as shown below:

// @addr_len is uninitialized
int addr_len;

// This operation does not touch @addr_len if it fails.
addr = of_get_property(device, "reg", &addr_len);

// Use uninitialized @addr_len if the operation fails.
if (addr_len > sizeof(addr_buf))
	addr_len = sizeof(addr_buf);

// Check the operation result here.
if (addr)
	memcpy(addr_buf, addr, addr_len);

Fix by initializing @addr_len before the operation.

Fixes: b739dffa5d57 ("of/irq: Prevent device address out-of-bounds read in interrupt map walk")
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/of/irq.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index cb39624a5e7799b9d2f4525f42dac4cd921ab403..64c005dfa23bd157d891f3f10526327deb5e2cfa 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -361,6 +361,7 @@ int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_ar
 		return of_irq_parse_oldworld(device, index, out_irq);
 
 	/* Get the reg property (if any) */
+	addr_len = 0;
 	addr = of_get_property(device, "reg", &addr_len);
 
 	/* Prevent out-of-bounds read in case of longer interrupt parent address size */

-- 
2.34.1
Re: [PATCH 4/8] of/irq: Fix using uninitialized variable @addr_len in API of_irq_parse_one()
Posted by Rob Herring 1 year ago
On Mon, Dec 09, 2024 at 09:25:02PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> of_irq_parse_one() may use uninitialized variable @addr_len as shown below:
> 
> // @addr_len is uninitialized
> int addr_len;
> 
> // This operation does not touch @addr_len if it fails.
> addr = of_get_property(device, "reg", &addr_len);
> 
> // Use uninitialized @addr_len if the operation fails.
> if (addr_len > sizeof(addr_buf))
> 	addr_len = sizeof(addr_buf);
> 
> // Check the operation result here.
> if (addr)
> 	memcpy(addr_buf, addr, addr_len);
> 
> Fix by initializing @addr_len before the operation.
> 
> Fixes: b739dffa5d57 ("of/irq: Prevent device address out-of-bounds read in interrupt map walk")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/of/irq.c | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks.

Rob