From ca20dbf407cb51f472c7a96b5953ca2febe40627 Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Wed, 16 Jan 2019 11:28:49 -0800 Subject: [PATCH] ANDROID: cfi: fix shadow rebasing If the module area base address changes when loading a new module, the new CFI shadow will only cover the first allocated page for each existing module. This will cause cross-DSO look-ups to functions elsewhere in the module to fall back to a red-black tree, which may be slower. Bug: 122963951 Change-Id: I9262034d39351afcd42590ead8d6384fc30a8ce8 Reported-by: Wu,Le Signed-off-by: Sami Tolvanen --- kernel/cfi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/cfi.c b/kernel/cfi.c index c32e6b358797..3265b55efc22 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -88,6 +88,14 @@ static inline unsigned long shadow_to_ptr(const struct cfi_shadow *s, return (s->r.min_page + s->shadow[index]) << PAGE_SHIFT; } +static inline unsigned long shadow_to_page(const struct cfi_shadow *s, + int index) +{ + BUG_ON(index < 0 || index >= SHADOW_SIZE); + + return (s->r.min_page + index) << PAGE_SHIFT; +} + static void prepare_next_shadow(const struct cfi_shadow __rcu *prev, struct cfi_shadow *next) { @@ -110,7 +118,7 @@ static void prepare_next_shadow(const struct cfi_shadow __rcu *prev, if (prev->shadow[i] == SHADOW_INVALID) continue; - index = ptr_to_shadow(next, shadow_to_ptr(prev, i)); + index = ptr_to_shadow(next, shadow_to_page(prev, i)); if (index < 0) continue;