Skip to content

Commit f3f5612

Browse files
maurermcgrof
authored andcommitted
module: Group section index calculations together
Group all the index detection together to make the parent function easier to read. Signed-off-by: Matthew Maurer <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 0a93953 commit f3f5612

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

kernel/module/main.c

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,56 @@ static int elf_validity_cache_index_str(struct load_info *info)
20392039
return 0;
20402040
}
20412041

2042+
/**
2043+
* elf_validity_cache_index() - Resolve, validate, cache section indices
2044+
* @info: Load info to read from and update.
2045+
* &load_info->sechdrs and &load_info->secstrings must be populated.
2046+
* @flags: Load flags, relevant to suppress version loading, see
2047+
* uapi/linux/module.h
2048+
*
2049+
* Populates &load_info->index, validating as it goes.
2050+
* See child functions for per-field validation:
2051+
*
2052+
* * elf_validity_cache_index_info()
2053+
* * elf_validity_cache_index_mod()
2054+
* * elf_validity_cache_index_sym()
2055+
* * elf_validity_cache_index_str()
2056+
*
2057+
* If versioning is not suppressed via flags, load the version index from
2058+
* a section called "__versions" with no validation.
2059+
*
2060+
* If CONFIG_SMP is enabled, load the percpu section by name with no
2061+
* validation.
2062+
*
2063+
* Return: 0 on success, negative error code if an index failed validation.
2064+
*/
2065+
static int elf_validity_cache_index(struct load_info *info, int flags)
2066+
{
2067+
int err;
2068+
2069+
err = elf_validity_cache_index_info(info);
2070+
if (err < 0)
2071+
return err;
2072+
err = elf_validity_cache_index_mod(info);
2073+
if (err < 0)
2074+
return err;
2075+
err = elf_validity_cache_index_sym(info);
2076+
if (err < 0)
2077+
return err;
2078+
err = elf_validity_cache_index_str(info);
2079+
if (err < 0)
2080+
return err;
2081+
2082+
if (flags & MODULE_INIT_IGNORE_MODVERSIONS)
2083+
info->index.vers = 0; /* Pretend no __versions section! */
2084+
else
2085+
info->index.vers = find_sec(info, "__versions");
2086+
2087+
info->index.pcpu = find_pcpusec(info);
2088+
2089+
return 0;
2090+
}
2091+
20422092
/*
20432093
* Check userspace passed ELF module against our expectations, and cache
20442094
* useful variables for further processing as we go.
@@ -2069,16 +2119,7 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
20692119
err = elf_validity_cache_secstrings(info);
20702120
if (err < 0)
20712121
return err;
2072-
err = elf_validity_cache_index_info(info);
2073-
if (err < 0)
2074-
return err;
2075-
err = elf_validity_cache_index_mod(info);
2076-
if (err < 0)
2077-
return err;
2078-
err = elf_validity_cache_index_sym(info);
2079-
if (err < 0)
2080-
return err;
2081-
err = elf_validity_cache_index_str(info);
2122+
err = elf_validity_cache_index(info, flags);
20822123
if (err < 0)
20832124
return err;
20842125

@@ -2095,13 +2136,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
20952136
if (!info->name)
20962137
info->name = info->mod->name;
20972138

2098-
if (flags & MODULE_INIT_IGNORE_MODVERSIONS)
2099-
info->index.vers = 0; /* Pretend no __versions section! */
2100-
else
2101-
info->index.vers = find_sec(info, "__versions");
2102-
2103-
info->index.pcpu = find_pcpusec(info);
2104-
21052139
return 0;
21062140
}
21072141

0 commit comments

Comments
 (0)