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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'execve-v6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull execve updates from Kees Cook:

- binfmt_elf: preserve original ELF e_flags for core dumps (Svetlana
Parfenova)

- exec: Fix incorrect type for ret (Xichao Zhao)

- binfmt_elf: Replace offsetof() with struct_size() in fill_note_info()
(Xichao Zhao)

* tag 'execve-v6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
binfmt_elf: preserve original ELF e_flags for core dumps
binfmt_elf: Replace offsetof() with struct_size() in fill_note_info()
exec: Fix incorrect type for ret

+53 -12
+1
arch/riscv/Kconfig
··· 28 28 select ARCH_HAS_DEBUG_VIRTUAL if MMU 29 29 select ARCH_HAS_DEBUG_VM_PGTABLE 30 30 select ARCH_HAS_DEBUG_WX 31 + select ARCH_HAS_ELF_CORE_EFLAGS 31 32 select ARCH_HAS_FAST_MULTIPLIER 32 33 select ARCH_HAS_FORTIFY_SOURCE 33 34 select ARCH_HAS_GCOV_PROFILE_ALL
+9
fs/Kconfig.binfmt
··· 184 184 This builds the exec KUnit tests, which tests boundary conditions 185 185 of various aspects of the exec internals. 186 186 187 + config ARCH_HAS_ELF_CORE_EFLAGS 188 + bool 189 + depends on BINFMT_ELF && ELF_CORE 190 + default n 191 + help 192 + Select this option if the architecture makes use of the e_flags 193 + field in the ELF header to store ABI or other architecture-specific 194 + information that should be preserved in core dumps. 195 + 187 196 endmenu
+37 -11
fs/binfmt_elf.c
··· 103 103 104 104 #define BAD_ADDR(x) (unlikely((unsigned long)(x) >= TASK_SIZE)) 105 105 106 + static inline void elf_coredump_set_mm_eflags(struct mm_struct *mm, u32 flags) 107 + { 108 + #ifdef CONFIG_ARCH_HAS_ELF_CORE_EFLAGS 109 + mm->saved_e_flags = flags; 110 + #endif 111 + } 112 + 113 + static inline u32 elf_coredump_get_mm_eflags(struct mm_struct *mm, u32 flags) 114 + { 115 + #ifdef CONFIG_ARCH_HAS_ELF_CORE_EFLAGS 116 + flags = mm->saved_e_flags; 117 + #endif 118 + return flags; 119 + } 120 + 106 121 /* 107 122 * We need to explicitly zero any trailing portion of the page that follows 108 123 * p_filesz when it ends before the page ends (e.g. bss), otherwise this ··· 1305 1290 mm->end_data = end_data; 1306 1291 mm->start_stack = bprm->p; 1307 1292 1293 + elf_coredump_set_mm_eflags(mm, elf_ex->e_flags); 1294 + 1308 1295 /** 1309 1296 * DOC: "brk" handling 1310 1297 * ··· 1821 1804 struct elf_thread_core_info *t; 1822 1805 struct elf_prpsinfo *psinfo; 1823 1806 struct core_thread *ct; 1807 + u16 machine; 1808 + u32 flags; 1824 1809 1825 1810 psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL); 1826 1811 if (!psinfo) ··· 1850 1831 return 0; 1851 1832 } 1852 1833 1853 - /* 1854 - * Initialize the ELF file header. 1855 - */ 1856 - fill_elf_header(elf, phdrs, 1857 - view->e_machine, view->e_flags); 1834 + machine = view->e_machine; 1835 + flags = view->e_flags; 1858 1836 #else 1859 1837 view = NULL; 1860 1838 info->thread_notes = 2; 1861 - fill_elf_header(elf, phdrs, ELF_ARCH, ELF_CORE_EFLAGS); 1839 + machine = ELF_ARCH; 1840 + flags = ELF_CORE_EFLAGS; 1862 1841 #endif 1842 + 1843 + /* 1844 + * Override ELF e_flags with value taken from process, 1845 + * if arch needs that. 1846 + */ 1847 + flags = elf_coredump_get_mm_eflags(dump_task->mm, flags); 1848 + 1849 + /* 1850 + * Initialize the ELF file header. 1851 + */ 1852 + fill_elf_header(elf, phdrs, machine, flags); 1863 1853 1864 1854 /* 1865 1855 * Allocate a structure for each thread. 1866 1856 */ 1867 - info->thread = kzalloc(offsetof(struct elf_thread_core_info, 1868 - notes[info->thread_notes]), 1869 - GFP_KERNEL); 1857 + info->thread = kzalloc(struct_size(info->thread, notes, info->thread_notes), 1858 + GFP_KERNEL); 1870 1859 if (unlikely(!info->thread)) 1871 1860 return 0; 1872 1861 1873 1862 info->thread->task = dump_task; 1874 1863 for (ct = dump_task->signal->core_state->dumper.next; ct; ct = ct->next) { 1875 - t = kzalloc(offsetof(struct elf_thread_core_info, 1876 - notes[info->thread_notes]), 1864 + t = kzalloc(struct_size(t, notes, info->thread_notes), 1877 1865 GFP_KERNEL); 1878 1866 if (unlikely(!t)) 1879 1867 return 0;
+1 -1
fs/exec.c
··· 599 599 unsigned long stack_top, 600 600 int executable_stack) 601 601 { 602 - unsigned long ret; 602 + int ret; 603 603 unsigned long stack_shift; 604 604 struct mm_struct *mm = current->mm; 605 605 struct vm_area_struct *vma = bprm->vma;
+5
include/linux/mm_types.h
··· 1107 1107 1108 1108 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */ 1109 1109 1110 + #ifdef CONFIG_ARCH_HAS_ELF_CORE_EFLAGS 1111 + /* the ABI-related flags from the ELF header. Used for core dump */ 1112 + unsigned long saved_e_flags; 1113 + #endif 1114 + 1110 1115 struct percpu_counter rss_stat[NR_MM_COUNTERS]; 1111 1116 1112 1117 struct linux_binfmt *binfmt;