Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Signed-off-by: Matthew Maurer <mmaurer@google.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Matthew Maurer and committed by
Luis Chamberlain
0a939533 9bd4982c

+28 -9
+28 -9
kernel/module/main.c
··· 2014 2014 return 0; 2015 2015 } 2016 2016 2017 + /** 2018 + * elf_validity_cache_index_str() - Validate and cache strtab index 2019 + * @info: Load info to cache strtab index in. 2020 + * Must have &load_info->sechdrs and &load_info->secstrings populated. 2021 + * Must have &load_info->index.sym populated. 2022 + * 2023 + * Looks at the symbol table's associated string table, makes sure it is 2024 + * in-bounds, and caches it. 2025 + * 2026 + * Return: %0 if valid, %-ENOEXEC on failure. 2027 + */ 2028 + static int elf_validity_cache_index_str(struct load_info *info) 2029 + { 2030 + unsigned int str_idx = info->sechdrs[info->index.sym].sh_link; 2031 + 2032 + if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) { 2033 + pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n", 2034 + str_idx, str_idx, info->hdr->e_shnum); 2035 + return -ENOEXEC; 2036 + } 2037 + 2038 + info->index.str = str_idx; 2039 + return 0; 2040 + } 2041 + 2017 2042 /* 2018 2043 * Check userspace passed ELF module against our expectations, and cache 2019 2044 * useful variables for further processing as we go. ··· 2062 2037 static int elf_validity_cache_copy(struct load_info *info, int flags) 2063 2038 { 2064 2039 int err; 2065 - int str_idx; 2066 2040 2067 2041 err = elf_validity_cache_sechdrs(info); 2068 2042 if (err < 0) ··· 2078 2054 err = elf_validity_cache_index_sym(info); 2079 2055 if (err < 0) 2080 2056 return err; 2081 - 2082 - str_idx = info->sechdrs[info->index.sym].sh_link; 2083 - if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) { 2084 - pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n", 2085 - str_idx, str_idx, info->hdr->e_shnum); 2086 - return -ENOEXEC; 2087 - } 2057 + err = elf_validity_cache_index_str(info); 2058 + if (err < 0) 2059 + return err; 2088 2060 2089 2061 /* Sets internal strings. */ 2090 - info->index.str = str_idx; 2091 2062 info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset; 2092 2063 2093 2064 /* This is temporary: point mod into copy of data. */