From b891b375910c2f4bc13820fc526589c10125f5f6 Mon Sep 17 00:00:00 2001 From: "rogercl.yang" Date: Wed, 23 Sep 2020 11:32:32 +0800 Subject: [PATCH] ANDROID: adding __nocfi to cpuidle_enter_state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Background: When CPU is going to idle state, it would inform RCU that current CPU is entering idle through rcu_idle_enter(), and RCU will ignore read-side critical sections of this CPU. However, there is CFI check mechanism inside idle flow and calls rcu_read_lock(), so "rcu_read_lock() used illegally while idle" in rcu_read_lock() will be triggered because rcu_idle_enter() was already called before. Beside, the pointer of rcu_dereference() might be invalid due to the RCU read-side critical sections will be ignoring in this going idle CPU, it might cause problems like: access the wrong data/address, kernel exception... Based on above description: We will add __nocfi to cpuidle_enter_state to avoid “rcu_read_lock() used illegally while idle!” and avoid the usage of invalid pointer of rcu_dereference() in this situation. Bug: 169017431 Change-Id: I8bbe25704e18cfde351a8f4277dd4b44b07421f5 Signed-off-by: rogercl.yang Signed-off-by: Chun-Hung Wu --- drivers/cpuidle/cpuidle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 3b71fe130337..573605ead9f9 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -199,7 +199,7 @@ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device *dev) * @drv: cpuidle driver for this cpu * @index: index into the states table in @drv of the state to enter */ -int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, +int __nocfi cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { int entered_state;