Files
linux/kernel/gki_module.c
Ramji Jiyani 9ab6a24225 ANDROID: GKI: Add module load time protected symbol lookup
Add CONFIG_MODULE_SIG_PROTECT to enable lookup for the protected
symbols and exports from the build time generated list of symbols
and exports.

Module loading behavior will change as follows:
- Allows Android GKI Modules signed using MODULE_SIG_ALL during build.
- Allows other modules to load if they don't violate the access to
  Android GKI protected symbols and do not export the symbols already
  exported by the Android GKI modules. Loading will fail and return
  -EACCES (Permission denied) if symbol access contidions are not met.

Bug: 200082547
Test: Treehugger
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: Iedb99d8434db82a9c7f18ffd363d84f4b2316c5b
2021-12-22 00:12:12 +00:00

51 lines
1.4 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2021 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_exported.h -- Symbols protected from _export_ by unsigned modules
* gki_module_protected.h -- Symbols protected from _access_ by unsigned modules
*/
#include "gki_module_protected.h"
#include "gki_module_exported.h"
#define MAX_STRCMP_LEN (max(MAX_PROTECTED_NAME_LEN, MAX_EXPORTED_NAME_LEN))
/* bsearch() comparision callback */
static int cmp_name(const void *sym, const void *protected_sym)
{
return strncmp(sym, protected_sym, MAX_STRCMP_LEN);
}
/**
* gki_is_module_protected_symbol - Is a symbol protected from unsigned module?
*
* @name: Symbol being checked against protection from unsigned module
*/
bool gki_is_module_protected_symbol(const char *name)
{
return bsearch(name, gki_protected_symbols, NO_OF_PROTECTED_SYMBOLS,
MAX_PROTECTED_NAME_LEN, cmp_name) != NULL;
}
/**
* gki_is_module_exported_symbol - Is a symbol exported from a GKI module?
*
* @name: Symbol being checked against exported symbols from GKI modules
*/
bool gki_is_module_exported_symbol(const char *name)
{
return bsearch(name, gki_exported_symbols, NO_OF_EXPORTED_SYMBOLS,
MAX_EXPORTED_NAME_LEN, cmp_name) != NULL;
}