From 0f186b1e6eeb2d756f9e5f3d2f08c731a2cefb8d Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Fri, 25 Sep 2020 18:31:59 -0700 Subject: [PATCH] ANDROID: kthread: cfi: disable callback pointer check with modules With CFI, a callback function passed to __kthread_queue_delayed_work from a module can point to a jump table entry defined in the module instead of the one used in the core kernel, which breaks this test: WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn); To work around the problem, disable the warning when CFI and modules are both enabled. Bug: 145210207 Change-Id: I5b0a60bb69ce8e2bc0d8e4bf6736457b6425b6cf Signed-off-by: Sami Tolvanen --- kernel/kthread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index ff3477dba5bb..09fc3ba16559 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -912,7 +912,13 @@ static void __kthread_queue_delayed_work(struct kthread_worker *worker, struct timer_list *timer = &dwork->timer; struct kthread_work *work = &dwork->work; - WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn); + /* + * With CFI, timer->function can point to a jump table entry in a module, + * which fails the comparison. Disable the warning if CFI and modules are + * both enabled. + */ + if (!IS_ENABLED(CONFIG_CFI_CLANG) || !IS_ENABLED(CONFIG_MODULES)) + WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn); /* * If @delay is 0, queue @dwork->work immediately. This is for