From e4a6cb847fc47fa294a9db9bbd64128976b1bbf4 Mon Sep 17 00:00:00 2001 From: Ramji Jiyani Date: Sun, 18 Dec 2022 23:09:16 -0800 Subject: [PATCH] ANDROID: GKI: Only protect exports if KMI symbols are present Only enforce export protection if there are symbols in the unprotected list for the Kernel Module Interface (KMI). This is only relevant for targets like arm64 that have defined ABI symbol lists. This allows non-GKI targets like arm and x86 to continue using GKI source code without disabling the feature for those targets. Bug: 232430739 Test: TH Fixes: fd1e76886660 ("ANDROID: GKI: Protect exports of protected GKI modules") Change-Id: Ie89e8f63eda99d9b7aacd1bb76d036b3ff4ba37c Signed-off-by: Ramji Jiyani (cherry picked from commit a6eaf3db80788a1445a7a2e05503f32610d79486) --- kernel/module/gki_module.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/module/gki_module.c b/kernel/module/gki_module.c index fc2968c3791e..4f124f9a14ec 100644 --- a/kernel/module/gki_module.c +++ b/kernel/module/gki_module.c @@ -34,8 +34,17 @@ static int cmp_name(const void *sym, const void *protected_sym) */ bool gki_is_module_protected_export(const char *name) { - return bsearch(name, gki_protected_exports_symbols, NR_PROTECTED_EXPORTS_SYMBOLS, + if (NR_UNPROTECTED_SYMBOLS) { + return bsearch(name, gki_protected_exports_symbols, NR_PROTECTED_EXPORTS_SYMBOLS, MAX_PROTECTED_EXPORTS_NAME_LEN, cmp_name) != NULL; + } else { + /* + * If there are no symbols in unprotected list; We don't need to + * protect exports as there is no KMI enforcement. + * Treat everything exportable in this case. + */ + return false; + } } /** @@ -52,7 +61,7 @@ bool gki_is_module_unprotected_symbol(const char *name) /* * If there are no symbols in unprotected list; * there isn't a KMI enforcement for the kernel. - * Treat evertything accessible in this case. + * Treat everything accessible in this case. */ return true; }