Commit 961d921a authored by Philipp Rudo's avatar Philipp Rudo Committed by Linus Torvalds

kernel/kexec_file.c: search symbols in read-only kexec_purgatory

The stripped purgatory does not contain a symtab.  So when looking for
symbols this is done in read-only kexec_purgatory.  Highlight this by
marking the corresponding variables as 'const'.

Link: http://lkml.kernel.org/r/20180321112751.22196-5-prudo@linux.vnet.ibm.comSigned-off-by: default avatarPhilipp Rudo <prudo@linux.vnet.ibm.com>
Acked-by: default avatarDave Young <dyoung@redhat.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 65c225d3
...@@ -962,20 +962,27 @@ int kexec_load_purgatory(struct kimage *image, unsigned long min, ...@@ -962,20 +962,27 @@ int kexec_load_purgatory(struct kimage *image, unsigned long min,
return ret; return ret;
} }
static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi, /*
* kexec_purgatory_find_symbol - find a symbol in the purgatory
* @pi: Purgatory to search in.
* @name: Name of the symbol.
*
* Return: pointer to symbol in read-only symtab on success, NULL on error.
*/
static const Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi,
const char *name) const char *name)
{ {
const Elf_Shdr *sechdrs;
const Elf_Ehdr *ehdr; const Elf_Ehdr *ehdr;
Elf_Sym *syms; const Elf_Sym *syms;
Elf_Shdr *sechdrs;
int i, k;
const char *strtab; const char *strtab;
int i, k;
if (!pi->sechdrs || !pi->ehdr) if (!pi->ehdr)
return NULL; return NULL;
sechdrs = pi->sechdrs;
ehdr = pi->ehdr; ehdr = pi->ehdr;
sechdrs = (void *)ehdr + ehdr->e_shoff;
for (i = 0; i < ehdr->e_shnum; i++) { for (i = 0; i < ehdr->e_shnum; i++) {
if (sechdrs[i].sh_type != SHT_SYMTAB) if (sechdrs[i].sh_type != SHT_SYMTAB)
...@@ -984,8 +991,8 @@ static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi, ...@@ -984,8 +991,8 @@ static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi,
if (sechdrs[i].sh_link >= ehdr->e_shnum) if (sechdrs[i].sh_link >= ehdr->e_shnum)
/* Invalid strtab section number */ /* Invalid strtab section number */
continue; continue;
strtab = (char *)sechdrs[sechdrs[i].sh_link].sh_offset; strtab = (void *)ehdr + sechdrs[sechdrs[i].sh_link].sh_offset;
syms = (Elf_Sym *)sechdrs[i].sh_offset; syms = (void *)ehdr + sechdrs[i].sh_offset;
/* Go through symbols for a match */ /* Go through symbols for a match */
for (k = 0; k < sechdrs[i].sh_size/sizeof(Elf_Sym); k++) { for (k = 0; k < sechdrs[i].sh_size/sizeof(Elf_Sym); k++) {
...@@ -1013,7 +1020,7 @@ static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi, ...@@ -1013,7 +1020,7 @@ static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi,
void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name) void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name)
{ {
struct purgatory_info *pi = &image->purgatory_info; struct purgatory_info *pi = &image->purgatory_info;
Elf_Sym *sym; const Elf_Sym *sym;
Elf_Shdr *sechdr; Elf_Shdr *sechdr;
sym = kexec_purgatory_find_symbol(pi, name); sym = kexec_purgatory_find_symbol(pi, name);
...@@ -1036,9 +1043,9 @@ void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name) ...@@ -1036,9 +1043,9 @@ void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name)
int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
void *buf, unsigned int size, bool get_value) void *buf, unsigned int size, bool get_value)
{ {
Elf_Sym *sym;
Elf_Shdr *sechdrs;
struct purgatory_info *pi = &image->purgatory_info; struct purgatory_info *pi = &image->purgatory_info;
const Elf_Sym *sym;
Elf_Shdr *sec;
char *sym_buf; char *sym_buf;
sym = kexec_purgatory_find_symbol(pi, name); sym = kexec_purgatory_find_symbol(pi, name);
...@@ -1051,16 +1058,15 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, ...@@ -1051,16 +1058,15 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
return -EINVAL; return -EINVAL;
} }
sechdrs = pi->sechdrs; sec = pi->sechdrs + sym->st_shndx;
if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) { if (sec->sh_type == SHT_NOBITS) {
pr_err("symbol %s is in a bss section. Cannot %s\n", name, pr_err("symbol %s is in a bss section. Cannot %s\n", name,
get_value ? "get" : "set"); get_value ? "get" : "set");
return -EINVAL; return -EINVAL;
} }
sym_buf = (unsigned char *)sechdrs[sym->st_shndx].sh_offset + sym_buf = (char *)sec->sh_offset + sym->st_value;
sym->st_value;
if (get_value) if (get_value)
memcpy((void *)buf, sym_buf, size); memcpy((void *)buf, sym_buf, size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment