Skip to contentSkip to conversation

interconnect: qcom: icc-rpm: Set the count member before accessing the flex array

PATCH In review [email protected] 3 participants 3 messages Dec 3, 2024 – Aug 29, 2025

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 interconnect: qcom: icc-rpm: Set the count member before accessing the flex array

From: Georgi Djakov <[email protected]>

The following UBSAN error is reported during boot on the db410c board on a clang-19 build:

Internal error: UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP
...
pc : qnoc_probe+0x5f8/0x5fc

...

The cause of the error is that the counter member was not set before accessing the annotated flexible array member, but after that. Fix this by initializing it earlier.

Fixes dd4904f3b924 ("interconnect: qcom: Annotate struct icc_onecell_data with __counted_by")
---
 drivers/interconnect/qcom/icc-rpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/interconnect/qcom/icc-rpm.c +1 -1
index a8ed435f696c..ea1042d38128 100644
@@ -503,6 +503,7 @@ int qnoc_probe(struct platform_device *pdev)
 			    GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
+	data->num_nodes = num_nodes;
 
 	qp->num_intf_clks = cd_num;
 	for (i = 0; i < cd_num; i++)
@@ -597,7 +598,6 @@ int qnoc_probe(struct platform_device *pdev)
 
 		data->nodes[i] = node;
 	}
-	data->num_nodes = num_nodes;
 
 	clk_bulk_disable_unprepare(qp->num_intf_clks, qp->intf_clks);
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Wed, Dec 04, 2024 at 12:33:34AM +0200, [email protected] wrote:

From: Georgi Djakov <[email protected]>

The following UBSAN error is reported during boot on the db410c board on a clang-19 build:

Internal error: UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP
...
pc : qnoc_probe+0x5f8/0x5fc

...

Really happy to see more coverage of real hardware with compilers that support __counted_by() so that we can start getting these addressed, thanks for this!

Quoted 7 lines

The cause of the error is that the counter member was not set before accessing the annotated flexible array member, but after that. Fix this by initializing it earlier.

Fixes dd4904f3b924 ("interconnect: qcom: Annotate struct icc_onecell_data with __counted_by")

Guess Kees missed one :)

Quoted 1 line

This is exactly the thing that __builtin_counted_by_ref() is trying to address, as these assignments happen right after the allocation:

https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fcounted_005fby_005fref

Quoted 24 lines
---
 drivers/interconnect/qcom/icc-rpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/interconnect/qcom/icc-rpm.c +1 -1
index a8ed435f696c..ea1042d38128 100644
@@ -503,6 +503,7 @@ int qnoc_probe(struct platform_device *pdev)
 			    GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
+	data->num_nodes = num_nodes;
 
 	qp->num_intf_clks = cd_num;
 	for (i = 0; i < cd_num; i++)
@@ -597,7 +598,6 @@ int qnoc_probe(struct platform_device *pdev)
 
 		data->nodes[i] = node;
 	}
-	data->num_nodes = num_nodes;
 
 	clk_bulk_disable_unprepare(qp->num_intf_clks, qp->intf_clks);
 
#2 lore raw
In reply to [email protected]

Hi Greg,

Could you pick up this commit for 6.12 and 6.6:

00a973e093e9 ("interconnect: qcom: icc-rpm: Set the count member before accessing the flex array")

It just silences a UBSan warning so it doesn't affect regular users, but it helps in testing to silence those warnings. It is a clean cherry-pick.

regards,
dan carpenter

Quoted 42 lines · On Wed, Dec 04, 2024 at 12:33:34AM +0200, [email protected] wrote:

From: Georgi Djakov <[email protected]>

The following UBSAN error is reported during boot on the db410c board on a clang-19 build:

Internal error: UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP
...
pc : qnoc_probe+0x5f8/0x5fc

...

The cause of the error is that the counter member was not set before accessing the annotated flexible array member, but after that. Fix this by initializing it earlier.

Fixes dd4904f3b924 ("interconnect: qcom: Annotate struct icc_onecell_data with __counted_by")
---
 drivers/interconnect/qcom/icc-rpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/interconnect/qcom/icc-rpm.c +1 -1
index a8ed435f696c..ea1042d38128 100644
@@ -503,6 +503,7 @@ int qnoc_probe(struct platform_device *pdev)
 			    GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
+	data->num_nodes = num_nodes;
 
 	qp->num_intf_clks = cd_num;
 	for (i = 0; i < cd_num; i++)
@@ -597,7 +598,6 @@ int qnoc_probe(struct platform_device *pdev)
 
 		data->nodes[i] = node;
 	}
-	data->num_nodes = num_nodes;
 
 	clk_bulk_disable_unprepare(qp->num_intf_clks, qp->intf_clks);