@@ -2014,6 +2014,31 @@ static int elf_validity_cache_index_sym(struct load_info *info)
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.
@@ -2037,7 +2062,6 @@ static int elf_validity_cache_index_sym(struct load_info *info)
2037
2062
static int elf_validity_cache_copy (struct load_info * info , int flags )
2038
2063
{
2039
2064
int err ;
2040
- int str_idx ;
2041
2065
2042
2066
err = elf_validity_cache_sechdrs (info );
2043
2067
if (err < 0 )
@@ -2054,16 +2078,11 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
2054
2078
err = elf_validity_cache_index_sym (info );
2055
2079
if (err < 0 )
2056
2080
return err ;
2057
-
2058
- str_idx = info -> sechdrs [info -> index .sym ].sh_link ;
2059
- if (str_idx == SHN_UNDEF || str_idx >= info -> hdr -> e_shnum ) {
2060
- pr_err ("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n" ,
2061
- str_idx , str_idx , info -> hdr -> e_shnum );
2062
- return - ENOEXEC ;
2063
- }
2081
+ err = elf_validity_cache_index_str (info );
2082
+ if (err < 0 )
2083
+ return err ;
2064
2084
2065
2085
/* Sets internal strings. */
2066
- info -> index .str = str_idx ;
2067
2086
info -> strtab = (char * )info -> hdr + info -> sechdrs [info -> index .str ].sh_offset ;
2068
2087
2069
2088
/* This is temporary: point mod into copy of data. */
0 commit comments