Skip to contentSkip to conversation

cpufreq: dt: fix oops on armada37xx

PATCH Applied Ivan Kokshaysky 3 participants 4 messages Jun 20, 2020 – Jun 22, 2020

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

PATCH 1/1 cpufreq: dt: fix oops on armada37xx

Commit 0c868627e617e43a295d8 (cpufreq: dt: Allow platform specific intermediate callbacks) added two function pointers to the struct cpufreq_dt_platform_data. However, armada37xx_cpufreq_driver_init() has this struct (pdata) located on the stack and uses only "suspend" and "resume" fields. So these newly added "get_intermediate" and "target_intermediate" pointers are uninitialized and contain arbitrary non-null values, causing all kinds of trouble.

For instance, here is an oops on espressobin after an attempt to change the cpefreq governor:

[   29.174554] Unable to handle kernel execute from non-executable memory at virtual address ffff00003f87bdc0
...
[   29.269373] pc : 0xffff00003f87bdc0
[   29.272957] lr : __cpufreq_driver_target+0x138/0x580

...

Fixed by zeroing out pdata before use.

---
 drivers/cpufreq/armada-37xx-cpufreq.c | 1 +
 1 file changed, 1 insertion(+)
drivers/cpufreq/armada-37xx-cpufreq.c +1 -0
index aa0f06dec959..df1c941260d1 100644
@@ -456,6 +456,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
 	/* Now that everything is setup, enable the DVFS at hardware level */
 	armada37xx_cpufreq_enable_dvfs(nb_pm_base);
 
+	memset(&pdata, 0, sizeof(pdata));
 	pdata.suspend = armada37xx_cpufreq_suspend;
 	pdata.resume = armada37xx_cpufreq_resume;
 
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Ivan Kokshaysky

Commit 0c868627e617e43a295d8 (cpufreq: dt: Allow platform specific intermediate callbacks) added two function pointers to the struct cpufreq_dt_platform_data. However, armada37xx_cpufreq_driver_init() has this struct (pdata) located on the stack and uses only "suspend" and "resume" fields. So these newly added "get_intermediate" and "target_intermediate" pointers are uninitialized and contain arbitrary non-null values, causing all kinds of trouble.

For instance, here is an oops on espressobin after an attempt to change the cpefreq governor:

[   29.174554] Unable to handle kernel execute from non-executable memory at virtual address ffff00003f87bdc0
...
[   29.269373] pc : 0xffff00003f87bdc0
[   29.272957] lr : __cpufreq_driver_target+0x138/0x580
Quoted 5 lines

...

Fixed by zeroing out pdata before use.

Hi Ivan

A Fixes: tag would be good.

Andrew

#2 lore raw
Quoted 18 lines · Andrew Lunn
Quoted 17 lines · Ivan Kokshaysky

Commit 0c868627e617e43a295d8 (cpufreq: dt: Allow platform specific intermediate callbacks) added two function pointers to the struct cpufreq_dt_platform_data. However, armada37xx_cpufreq_driver_init() has this struct (pdata) located on the stack and uses only "suspend" and "resume" fields. So these newly added "get_intermediate" and "target_intermediate" pointers are uninitialized and contain arbitrary non-null values, causing all kinds of trouble.

For instance, here is an oops on espressobin after an attempt to change the cpefreq governor:

[   29.174554] Unable to handle kernel execute from non-executable memory at virtual address ffff00003f87bdc0
...
[   29.269373] pc : 0xffff00003f87bdc0
[   29.272957] lr : __cpufreq_driver_target+0x138/0x580

...

Quoted 7 lines
Quoted 3 lines

Fixed by zeroing out pdata before use.

Hi Ivan

A Fixes: tag would be good.

Hi Andrew,

I'm not sure that "Fixes:" would be appropriate here - commit 0c868627e617 is fine by itself, it just revealed a bug in older code.

Thanks for reviewing,
Ivan.

Quoted 3 lines

Andrew

maintainer Applied
#3 lore raw
In reply to Ivan Kokshaysky
Quoted 29 lines · Ivan Kokshaysky

Commit 0c868627e617e43a295d8 (cpufreq: dt: Allow platform specific intermediate callbacks) added two function pointers to the struct cpufreq_dt_platform_data. However, armada37xx_cpufreq_driver_init() has this struct (pdata) located on the stack and uses only "suspend" and "resume" fields. So these newly added "get_intermediate" and "target_intermediate" pointers are uninitialized and contain arbitrary non-null values, causing all kinds of trouble.

For instance, here is an oops on espressobin after an attempt to change the cpefreq governor:

[   29.174554] Unable to handle kernel execute from non-executable memory at virtual address ffff00003f87bdc0
...
[   29.269373] pc : 0xffff00003f87bdc0
[   29.272957] lr : __cpufreq_driver_target+0x138/0x580

...

Fixed by zeroing out pdata before use.

---
 drivers/cpufreq/armada-37xx-cpufreq.c | 1 +
 1 file changed, 1 insertion(+)
drivers/cpufreq/armada-37xx-cpufreq.c +0 -0
index aa0f06dec959..df1c941260d1 100644

drivers/cpufreq/armada-37xx-cpufreq.c static int __init armada37xx_cpufreq_driver_init(void) · line 461

Quoted 6 lines
drivers/cpufreq/armada-37xx-cpufreq.c +1 -0
@@ -456,6 +456,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
 	/* Now that everything is setup, enable the DVFS at hardware level */
 	armada37xx_cpufreq_enable_dvfs(nb_pm_base);
 
+	memset(&pdata, 0, sizeof(pdata));
 	pdata.suspend = armada37xx_cpufreq_suspend;
 	pdata.resume = armada37xx_cpufreq_resume;

Applied. Thanks.

Signature · 1 line
viresh