Skip to content

Commit 837031e

Browse files
maurermcgrof
authored andcommitted
module: Factor out elf_validity_cache_strtab
This patch only moves the existing strtab population to a function. Validation comes in a following patch, this is split out to make the new validation checks more clearly separated. Signed-off-by: Matthew Maurer <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent f3f5612 commit 837031e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

kernel/module/main.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,23 @@ static int elf_validity_cache_index(struct load_info *info, int flags)
20892089
return 0;
20902090
}
20912091

2092+
/**
2093+
* elf_validity_cache_strtab() - Cache symbol string table
2094+
* @info: Load info to read from and update.
2095+
* Must have &load_info->sechdrs and &load_info->secstrings populated.
2096+
* Must have &load_info->index populated.
2097+
*
2098+
* Return: 0 on success, negative error code if a check failed.
2099+
*/
2100+
static int elf_validity_cache_strtab(struct load_info *info)
2101+
{
2102+
Elf_Shdr *str_shdr = &info->sechdrs[info->index.str];
2103+
char *strtab = (char *)info->hdr + str_shdr->sh_offset;
2104+
2105+
info->strtab = strtab;
2106+
return 0;
2107+
}
2108+
20922109
/*
20932110
* Check userspace passed ELF module against our expectations, and cache
20942111
* useful variables for further processing as we go.
@@ -2122,9 +2139,9 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
21222139
err = elf_validity_cache_index(info, flags);
21232140
if (err < 0)
21242141
return err;
2125-
2126-
/* Sets internal strings. */
2127-
info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;
2142+
err = elf_validity_cache_strtab(info);
2143+
if (err < 0)
2144+
return err;
21282145

21292146
/* This is temporary: point mod into copy of data. */
21302147
info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset;

0 commit comments

Comments
 (0)