ANDROID: modpost: add symbol import protection flag to kflagstab

When the unused exports whitelist is provided, the symbol protection bit
is set for symbols not present in the unused exports whitelist.

The flag will be used in the following commit to prevent unsigned
modules from the using symbols other than those explicitly declared by
the such modules ahead of time.

Bug: 519119852
Change-Id: Ibddd628a8b1463397cc95d3d8f556b9bc82bf623
Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
This commit is contained in:
Siddharth Nayyar authored and Sid Nayyar committed 2026-06-04 01:46:10 -07:00
1 parent 8a1ef95dff
commit e0ea42b26f
2 files changed
+12 -2

No files matched your search

+11 -2
View File
@@ -63,6 +63,9 @@ static bool extra_warn __attribute__((unused));
bool target_is_big_endian;
bool host_is_big_endian;
/* Are symbols protected against being used by unsigned modules? */
static bool default_symbol_protected_status;
/*
* Cut off the warnings when there are too many. This typically occurs when
* vmlinux is missing. ('make modules' without building vmlinux.)
@@ -227,6 +230,7 @@ struct symbol {
bool is_func;
bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */
bool used; /* there exists a user of this symbol */
bool protected; /* this symbol cannot be used by unsigned modules */
char name[];
};
@@ -248,7 +252,8 @@ static struct symbol *alloc_symbol(const char *name)
static uint8_t get_symbol_flags(const struct symbol *sym)
{
return sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0;
return (sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0) |
(sym->protected ? KSYM_FLAG_PROTECTED : 0);
}
/* For the hash of exported symbols */
@@ -372,6 +377,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
s->namespace = xstrdup(namespace);
list_add_tail(&s->list, &mod->exported_symbols);
hash_add_symbol(s);
s->protected = default_symbol_protected_status;
return s;
}
@@ -1796,8 +1802,10 @@ static void handle_white_list_exports(const char *white_list)
while ((name = strsep(&p, "\n"))) {
struct symbol *sym = find_symbol(name);
if (sym)
if (sym) {
sym->used = true;
sym->protected = false;
}
}
free(buf);
@@ -2323,6 +2331,7 @@ int main(int argc, char **argv)
break;
case 'u':
unused_exports_white_list = optarg;
default_symbol_protected_status = true;
break;
case 'W':
extra_warn = true;