Files
kernel_arpi/kernel/gki_module.c
Ramji Jiyani 706d642b1d ANDROID: GKI: Handle no ABI symbol list for modules
ACKs with no ABI symbol lists like mainline,
don't let any unsigned modules load as every
access is being treated as violation as
NO_OF_UNPROTECTED_SYMBOLS will be 0 in this case.

Check NO_OF_UNPROTECTED_SYMBOLS and if it's 0,
allow every symbol access by unsigned modules;
so we can keep the feature enable and also not
break any devices. It should never be 0 with
kernel branches where KMI_SYMBOL_LISTS  have been
enabled.

Bug: 257458145
Bug: 232430739
Test: TH
Fixes: e9669eeb2f45 ("ANDROID: GKI: Add module load time symbol protection")
Change-Id: Iab65e1425473e32baaad0d6c7f0d3eb007ae864f
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
(cherry picked from commit 8e00226a8fffa10b6383e448af785ce44451688e)
2022-12-01 00:22:47 +00:00

45 lines
1.1 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2022 Google LLC
* Author: ramjiyani@google.com (Ramji Jiyani)
*/
#include <linux/bsearch.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/string.h>
/*
* Build time generated header files
*
* gki_module_unprotected.h -- Symbols allowed to _access_ by unsigned modules
*/
#include "gki_module_unprotected.h"
/* bsearch() comparision callback */
static int cmp_name(const void *sym, const void *protected_sym)
{
return strncmp(sym, protected_sym, MAX_UNPROTECTED_NAME_LEN);
}
/**
* gki_is_module_unprotected_symbol - Is a symbol unprotected for unsigned module?
*
* @name: Symbol being checked in list of unprotected symbols
*/
bool gki_is_module_unprotected_symbol(const char *name)
{
if (NO_OF_UNPROTECTED_SYMBOLS) {
return bsearch(name, gki_unprotected_symbols, NO_OF_UNPROTECTED_SYMBOLS,
MAX_UNPROTECTED_NAME_LEN, cmp_name) != NULL;
} else {
/*
* If there are no symbols in unprotected list;
* there isn't a KMI enforcement for the kernel.
* Treat evertything accessible in this case.
*/
return true;
}
}