FROMGIT: module: Factor out elf_validity_cache_index_str
Pull out index validation for the symbol string section. Note that this does not validate the *contents* of the string table, only shape and presence of the section. Change-Id: Idcfa9fff876e2071d1ffbd4bac8c5410adcf0234 Signed-off-by: Matthew Maurer <mmaurer@google.com> Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> (cherry picked from commit 0a9395334496d3be8bde491e46087540cb8f141d kernel/git/modules/linux.git modules-next) Bug: 347787665
This commit is contained in:
committed by
Matthias Männich
parent
d487c4ca16
commit
a12cb510f1
+28
-9
@@ -2050,6 +2050,31 @@ static int elf_validity_cache_index_sym(struct load_info *info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* elf_validity_cache_index_str() - Validate and cache strtab index
|
||||
* @info: Load info to cache strtab index in.
|
||||
* Must have &load_info->sechdrs and &load_info->secstrings populated.
|
||||
* Must have &load_info->index.sym populated.
|
||||
*
|
||||
* Looks at the symbol table's associated string table, makes sure it is
|
||||
* in-bounds, and caches it.
|
||||
*
|
||||
* Return: %0 if valid, %-ENOEXEC on failure.
|
||||
*/
|
||||
static int elf_validity_cache_index_str(struct load_info *info)
|
||||
{
|
||||
unsigned int str_idx = info->sechdrs[info->index.sym].sh_link;
|
||||
|
||||
if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) {
|
||||
pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n",
|
||||
str_idx, str_idx, info->hdr->e_shnum);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
info->index.str = str_idx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check userspace passed ELF module against our expectations, and cache
|
||||
* useful variables for further processing as we go.
|
||||
@@ -2073,7 +2098,6 @@ static int elf_validity_cache_index_sym(struct load_info *info)
|
||||
static int elf_validity_cache_copy(struct load_info *info, int flags)
|
||||
{
|
||||
int err;
|
||||
int str_idx;
|
||||
|
||||
err = elf_validity_cache_sechdrs(info);
|
||||
if (err < 0)
|
||||
@@ -2090,16 +2114,11 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
|
||||
err = elf_validity_cache_index_sym(info);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
str_idx = info->sechdrs[info->index.sym].sh_link;
|
||||
if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) {
|
||||
pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n",
|
||||
str_idx, str_idx, info->hdr->e_shnum);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
err = elf_validity_cache_index_str(info);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
/* Sets internal strings. */
|
||||
info->index.str = str_idx;
|
||||
info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;
|
||||
|
||||
/* This is temporary: point mod into copy of data. */
|
||||
|
||||
Reference in New Issue
Block a user