The patch titled Subject: kernel/kexec_file.c: search symbols in read-only kexec_purgatory has been added to the -mm tree. Its filename is kexec_file-search-symbols-in-read-only-kexec_purgatory.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kexec_file-search-symbols-in-read-only-kexec_purgatory.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kexec_file-search-symbols-in-read-only-kexec_purgatory.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Philipp Rudo <prudo@xxxxxxxxxxxxxxxxxx> Subject: 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@xxxxxxxxxxxxxxxxxx Signed-off-by: Philipp Rudo <prudo@xxxxxxxxxxxxxxxxxx> Cc: AKASHI Takahiro <takahiro.akashi@xxxxxxxxxx> Cc: Dave Young <dyoung@xxxxxxxxxx> Cc: Eric Biederman <ebiederm@xxxxxxxxxxxx> Cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Martin Schwidefsky <schwidefsky@xxxxxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Thiago Jung Bauermann <bauerman@xxxxxxxxxxxxxxxxxx> Cc: Vivek Goyal <vgoyal@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/kexec_file.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff -puN kernel/kexec_file.c~kexec_file-search-symbols-in-read-only-kexec_purgatory kernel/kexec_file.c --- a/kernel/kexec_file.c~kexec_file-search-symbols-in-read-only-kexec_purgatory +++ a/kernel/kexec_file.c @@ -1004,20 +1004,27 @@ out: return ret; } -static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi, - const char *name) +/* + * 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 Elf_Shdr *sechdrs; const Elf_Ehdr *ehdr; - Elf_Sym *syms; - Elf_Shdr *sechdrs; - int i, k; + const Elf_Sym *syms; const char *strtab; + int i, k; - if (!pi->sechdrs || !pi->ehdr) + if (!pi->ehdr) return NULL; - sechdrs = pi->sechdrs; ehdr = pi->ehdr; + sechdrs = (void *)ehdr + ehdr->e_shoff; for (i = 0; i < ehdr->e_shnum; i++) { if (sechdrs[i].sh_type != SHT_SYMTAB) @@ -1026,8 +1033,8 @@ static Elf_Sym *kexec_purgatory_find_sym if (sechdrs[i].sh_link >= ehdr->e_shnum) /* Invalid strtab section number */ continue; - strtab = (char *)sechdrs[sechdrs[i].sh_link].sh_offset; - syms = (Elf_Sym *)sechdrs[i].sh_offset; + strtab = (void *)ehdr + sechdrs[sechdrs[i].sh_link].sh_offset; + syms = (void *)ehdr + sechdrs[i].sh_offset; /* Go through symbols for a match */ for (k = 0; k < sechdrs[i].sh_size/sizeof(Elf_Sym); k++) { @@ -1055,7 +1062,7 @@ static Elf_Sym *kexec_purgatory_find_sym void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name) { struct purgatory_info *pi = &image->purgatory_info; - Elf_Sym *sym; + const Elf_Sym *sym; Elf_Shdr *sechdr; sym = kexec_purgatory_find_symbol(pi, name); @@ -1078,9 +1085,9 @@ void *kexec_purgatory_get_symbol_addr(st int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, void *buf, unsigned int size, bool get_value) { - Elf_Sym *sym; - Elf_Shdr *sechdrs; struct purgatory_info *pi = &image->purgatory_info; + const Elf_Sym *sym; + Elf_Shdr *sec; char *sym_buf; sym = kexec_purgatory_find_symbol(pi, name); @@ -1093,16 +1100,15 @@ int kexec_purgatory_get_set_symbol(struc 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, get_value ? "get" : "set"); return -EINVAL; } - sym_buf = (unsigned char *)sechdrs[sym->st_shndx].sh_offset + - sym->st_value; + sym_buf = (char *)sec->sh_offset + sym->st_value; if (get_value) memcpy((void *)buf, sym_buf, size); _ Patches currently in -mm which might be from prudo@xxxxxxxxxxxxxxxxxx are kexec_file-silence-compile-warnings.patch kexec_file-remove-checks-in-kexec_purgatory_load.patch kexec_file-make-purgatory_info-ehdr-const.patch kexec_file-search-symbols-in-read-only-kexec_purgatory.patch kexec_file-use-read-only-sections-in-arch_kexec_apply_relocations.patch kexec_file-split-up-__kexec_load_puragory.patch kexec_file-remove-unneeded-for-loop-in-kexec_purgatory_setup_sechdrs.patch kexec_file-remove-unneeded-variables-in-kexec_purgatory_setup_sechdrs.patch kexec_file-remove-mis-use-of-sh_offset-field-during-purgatory-load.patch kexec_file-allow-archs-to-set-purgatory-load-address.patch kexec_file-move-purgatories-sha256-to-common-code.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html