Skip to contentSkip to conversation

ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

PATCH New Lukasz Majewski 3 participants 7 messages Mar 23, 2017 – Apr 10, 2017

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

PATCH 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

and then the previously described exception would be caught.

---
 arch/arm/cpu/armv7/omap-common/clocks-common.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm/cpu/armv7/omap-common/clocks-common.c +6 -4
index 097b8e3..157155a 100644
@@ -822,27 +822,29 @@ void do_enable_clocks(u32 const *clk_domains,
 	u32 i, max = 100;
 
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
 	}
 
 	/* Clock modules that need to be put in HW_AUTO */
-	for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_hw_auto &&
+		     clk_modules_hw_auto[i]; i++) {
 		enable_clock_module(clk_modules_hw_auto[i],
 				    MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
 				    wait_for_enable);
 	};
 
 	/* Clock modules that need to be put in SW_EXPLICIT_EN mode */
-	for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_explicit_en &&
+		     clk_modules_explicit_en[i]; i++) {
 		enable_clock_module(clk_modules_explicit_en[i],
 				    MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
 				    wait_for_enable);
 	};
 
 	/* Put the clock domains in HW_AUTO mode now */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
 	}
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

Quoted 15 lines · Lukasz Majewski

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

Quoted 5 lines

and then the previously described exception would be caught.

---
 arch/arm/cpu/armv7/omap-common/clocks-common.c | 10 ++++++----

This has been moved to arch/arm/mach-omap2/clocks-common.c Please use the latest U-Boot.

arch/arm/cpu/armv7/omap-common/clocks-common.c void do_enable_clocks(u32 const *clk_domains, · line 825

Quoted 12 lines
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm/cpu/armv7/omap-common/clocks-common.c +1 -1
index 097b8e3..157155a 100644
@@ -822,27 +822,29 @@ void do_enable_clocks(u32 const *clk_domains,
 	u32 i, max = 100;
 
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {

Instead of checking for clk_domains every time, can we use max as ARRAY_SIZE(clk_domains)? Similarly other places.

Thanks and regards,
Lokesh

Quoted 29 lines
arch/arm/cpu/armv7/omap-common/clocks-common.c +5 -3
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
 	}
 
 	/* Clock modules that need to be put in HW_AUTO */
-	for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_hw_auto &&
+		     clk_modules_hw_auto[i]; i++) {
 		enable_clock_module(clk_modules_hw_auto[i],
 				    MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
 				    wait_for_enable);
 	};
 
 	/* Clock modules that need to be put in SW_EXPLICIT_EN mode */
-	for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_explicit_en &&
+		     clk_modules_explicit_en[i]; i++) {
 		enable_clock_module(clk_modules_explicit_en[i],
 				    MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
 				    wait_for_enable);
 	};
 
 	/* Put the clock domains in HW_AUTO mode now */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
 	}
#2 lore raw

PATCH 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

Hi Lokesh,

Quoted 19 lines · Lukasz Majewski
Quoted 16 lines

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

Quoted 8 lines
Quoted 5 lines

and then the previously described exception would be caught.

---
 arch/arm/cpu/armv7/omap-common/clocks-common.c | 10 ++++++----

This has been moved to arch/arm/mach-omap2/clocks-common.c Please use the latest U-Boot.

Ok. I'm not working on a cutting-edge u-boot.

Quoted 10 lines
Quoted 10 lines
 1 file changed, 6 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/arch/arm/cpu/armv7/omap-common/clocks-common.c index 097b8e3..157155a 100644 --- a/arch/arm/cpu/armv7/omap-common/clocks-common.c +++ b/arch/arm/cpu/armv7/omap-common/clocks-common.c @@ -822,27 +822,29 @@ void do_enable_clocks(u32 const *clk_domains, u32 i, max = 100;

Quoted 7 lines
Quoted 4 lines
arch/arm/cpu/armv7/omap-common/clocks-common.c +1 -1
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i];

i++) {

Instead of checking for clk_domains every time, can we use max as ARRAY_SIZE(clk_domains)?

do_enable_clocks() accepts pointer to u32 as an argument (clk_domains). IMHO the ARRAY_SIZE(clk_domains) would be 1 - always.

Quoted 28 lines

Similarly other places.

Thanks and regards,
Lokesh

Quoted 23 lines
arch/arm/cpu/armv7/omap-common/clocks-common.c +2 -1
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
 	}
 
 	/* Clock modules that need to be put in HW_AUTO */
-	for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_hw_auto &&
+		     clk_modules_hw_auto[i]; i++) {
 		enable_clock_module(clk_modules_hw_auto[i],
 				    MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
 				    wait_for_enable);
 	};
 
 	/* Clock modules that need to be put in SW_EXPLICIT_EN

mode */

arch/arm/cpu/armv7/omap-common/clocks-common.c +2 -1
-	for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_explicit_en &&
+		     clk_modules_explicit_en[i]; i++) {
 		enable_clock_module(clk_modules_explicit_en[i],
 				    MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
 				    wait_for_enable);
 	};
Quoted 7 lines

arch/arm/cpu/armv7/omap-common/clocks-common.c void do_enable_clocks(u32 const *clk_domains, · line 850

Quoted 7 lines
arch/arm/cpu/armv7/omap-common/clocks-common.c +1 -1
 	/* Put the clock domains in HW_AUTO mode now */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i];

i++) { enable_clock_domain(clk_domains[i],

arch/arm/cpu/armv7/omap-common/clocks-common.c +0 -0
 				    CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
 	}

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de

#3 lore raw

PATCH 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

Quoted 50 lines · Lukasz Majewski

Hi Lokesh,

Quoted 19 lines · Lukasz Majewski
Quoted 16 lines

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

Quoted 8 lines
Quoted 5 lines

and then the previously described exception would be caught.

---
 arch/arm/cpu/armv7/omap-common/clocks-common.c | 10 ++++++----

This has been moved to arch/arm/mach-omap2/clocks-common.c Please use the latest U-Boot.

Ok. I'm not working on a cutting-edge u-boot.

Quoted 10 lines
Quoted 10 lines
 1 file changed, 6 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/arch/arm/cpu/armv7/omap-common/clocks-common.c index 097b8e3..157155a 100644 --- a/arch/arm/cpu/armv7/omap-common/clocks-common.c +++ b/arch/arm/cpu/armv7/omap-common/clocks-common.c @@ -822,27 +822,29 @@ void do_enable_clocks(u32 const *clk_domains, u32 i, max = 100;

Quoted 7 lines
Quoted 4 lines
arch/arm/cpu/armv7/omap-common/clocks-common.c +1 -1
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i];

i++) {

Instead of checking for clk_domains every time, can we use max as ARRAY_SIZE(clk_domains)?

Quoted 3 lines

do_enable_clocks() accepts pointer to u32 as an argument (clk_domains). IMHO the ARRAY_SIZE(clk_domains) would be 1 - always.

you are right. Discard my comment.

Thanks and regards,
Lokesh

#4 lore raw

PATCH v2 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

In reply to Lukasz Majewski

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

and then the previously described exception would be caught.

---
Changes for v2:
- Rebase to the newest "master" branch

---
 arch/arm/mach-omap2/clocks-common.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm/mach-omap2/clocks-common.c +6 -4
index 84f93e7..93c4c6f 100644
@@ -828,27 +828,29 @@ void do_enable_clocks(u32 const *clk_domains,
 	u32 i, max = 100;
 
 	/* Put the clock domains in SW_WKUP mode */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
 	}
 
 	/* Clock modules that need to be put in HW_AUTO */
-	for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_hw_auto &&
+		     clk_modules_hw_auto[i]; i++) {
 		enable_clock_module(clk_modules_hw_auto[i],
 				    MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
 				    wait_for_enable);
 	};
 
 	/* Clock modules that need to be put in SW_EXPLICIT_EN mode */
-	for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+	for (i = 0; (i < max) && clk_modules_explicit_en &&
+		     clk_modules_explicit_en[i]; i++) {
 		enable_clock_module(clk_modules_explicit_en[i],
 				    MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
 				    wait_for_enable);
 	};
 
 	/* Put the clock domains in HW_AUTO mode now */
-	for (i = 0; (i < max) && clk_domains[i]; i++) {
+	for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
 		enable_clock_domain(clk_domains[i],
 				    CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
 	}
Signature · 1 line
2.1.4
#5 lore raw

PATCH v2 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

Quoted 11 lines · Lukasz Majewski

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

Quoted 7 lines

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

and then the previously described exception would be caught.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170404/4c75993a/attachment.sig>
#6 lore raw

PATCH v2 1/1 ti: clocks: Fix do_enable_clocks() to accept NULL pointers as input parameters

In reply to Lukasz Majewski
Quoted 11 lines · Lukasz Majewski

Up till this commit passing NULL as input parameter was allowed, but not handled properly.

When one passed NULL to one of this function parameters, the code was executed causing data abort.

However, what is more interesting, the abort was not caught because of code execution in HYP mode with masked CPSR A bit ("Imprecise Data Abort mask bit). The TI's AM57xx SoC switch to HYP mode with A bit masked in lowlevel_init.S due to SMC call. Such operation (by default) is performed in SoC ROM code.

Quoted 8 lines

The problem would pop up when one:
- Switch back to SVC mode after disabling LPAE support
- Somebody enables A bit (by executing cpsie a asm instruction)

and then the previously described exception would be caught.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170410/a1c6b171/attachment.sig>