Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

elfcore: Add a cprm parameter to elf_core_extra_{phdrs,data_size}

A subsequent fix for arm64 will use this parameter to parse the vma
information from the snapshot created by dump_vma_snapshot() rather than
traversing the vma list without the mmap_lock.

Fixes: 6dd8b1a0b6cb ("arm64: mte: Dump the MTE tags in the core file")
Cc: <stable@vger.kernel.org> # 5.18.x
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reported-by: Seth Jenkins <sethjenkins@google.com>
Suggested-by: Seth Jenkins <sethjenkins@google.com>
Cc: Will Deacon <will@kernel.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221222181251.1345752-3-catalin.marinas@arm.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Catalin Marinas and committed by
Will Deacon
19e183b5 736eedc9

+14 -14
+2 -2
arch/arm64/kernel/elfcore.c
··· 76 76 return ret; 77 77 } 78 78 79 - Elf_Half elf_core_extra_phdrs(void) 79 + Elf_Half elf_core_extra_phdrs(struct coredump_params *cprm) 80 80 { 81 81 struct vm_area_struct *vma; 82 82 int vma_count = 0; ··· 113 113 return 1; 114 114 } 115 115 116 - size_t elf_core_extra_data_size(void) 116 + size_t elf_core_extra_data_size(struct coredump_params *cprm) 117 117 { 118 118 struct vm_area_struct *vma; 119 119 size_t data_size = 0;
+2 -2
arch/ia64/kernel/elfcore.c
··· 7 7 #include <asm/elf.h> 8 8 9 9 10 - Elf64_Half elf_core_extra_phdrs(void) 10 + Elf64_Half elf_core_extra_phdrs(struct coredump_params *cprm) 11 11 { 12 12 return GATE_EHDR->e_phnum; 13 13 } ··· 60 60 return 1; 61 61 } 62 62 63 - size_t elf_core_extra_data_size(void) 63 + size_t elf_core_extra_data_size(struct coredump_params *cprm) 64 64 { 65 65 const struct elf_phdr *const gate_phdrs = 66 66 (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
+2 -2
arch/x86/um/elfcore.c
··· 7 7 #include <asm/elf.h> 8 8 9 9 10 - Elf32_Half elf_core_extra_phdrs(void) 10 + Elf32_Half elf_core_extra_phdrs(struct coredump_params *cprm) 11 11 { 12 12 return vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0; 13 13 } ··· 60 60 return 1; 61 61 } 62 62 63 - size_t elf_core_extra_data_size(void) 63 + size_t elf_core_extra_data_size(struct coredump_params *cprm) 64 64 { 65 65 if ( vsyscall_ehdr ) { 66 66 const struct elfhdr *const ehdrp =
+2 -2
fs/binfmt_elf.c
··· 2034 2034 * The number of segs are recored into ELF header as 16bit value. 2035 2035 * Please check DEFAULT_MAX_MAP_COUNT definition when you modify here. 2036 2036 */ 2037 - segs = cprm->vma_count + elf_core_extra_phdrs(); 2037 + segs = cprm->vma_count + elf_core_extra_phdrs(cprm); 2038 2038 2039 2039 /* for notes section */ 2040 2040 segs++; ··· 2074 2074 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); 2075 2075 2076 2076 offset += cprm->vma_data_size; 2077 - offset += elf_core_extra_data_size(); 2077 + offset += elf_core_extra_data_size(cprm); 2078 2078 e_shoff = offset; 2079 2079 2080 2080 if (e_phnum == PN_XNUM) {
+2 -2
fs/binfmt_elf_fdpic.c
··· 1509 1509 tmp->next = thread_list; 1510 1510 thread_list = tmp; 1511 1511 1512 - segs = cprm->vma_count + elf_core_extra_phdrs(); 1512 + segs = cprm->vma_count + elf_core_extra_phdrs(cprm); 1513 1513 1514 1514 /* for notes section */ 1515 1515 segs++; ··· 1555 1555 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); 1556 1556 1557 1557 offset += cprm->vma_data_size; 1558 - offset += elf_core_extra_data_size(); 1558 + offset += elf_core_extra_data_size(cprm); 1559 1559 e_shoff = offset; 1560 1560 1561 1561 if (e_phnum == PN_XNUM) {
+4 -4
include/linux/elfcore.h
··· 105 105 * Dumping its extra ELF program headers includes all the other information 106 106 * a debugger needs to easily find how the gate DSO was being used. 107 107 */ 108 - extern Elf_Half elf_core_extra_phdrs(void); 108 + extern Elf_Half elf_core_extra_phdrs(struct coredump_params *cprm); 109 109 extern int 110 110 elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset); 111 111 extern int 112 112 elf_core_write_extra_data(struct coredump_params *cprm); 113 - extern size_t elf_core_extra_data_size(void); 113 + extern size_t elf_core_extra_data_size(struct coredump_params *cprm); 114 114 #else 115 - static inline Elf_Half elf_core_extra_phdrs(void) 115 + static inline Elf_Half elf_core_extra_phdrs(struct coredump_params *cprm) 116 116 { 117 117 return 0; 118 118 } ··· 127 127 return 1; 128 128 } 129 129 130 - static inline size_t elf_core_extra_data_size(void) 130 + static inline size_t elf_core_extra_data_size(struct coredump_params *cprm) 131 131 { 132 132 return 0; 133 133 }