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.

Split 'flush_old_exec' into two functions

'flush_old_exec()' is the point of no return when doing an execve(), and
it is pretty badly misnamed. It doesn't just flush the old executable
environment, it also starts up the new one.

Which is very inconvenient for things like setting up the new
personality, because we want the new personality to affect the starting
of the new environment, but at the same time we do _not_ want the new
personality to take effect if flushing the old one fails.

As a result, the x86-64 '32-bit' personality is actually done using this
insane "I'm going to change the ABI, but I haven't done it yet" bit
(TIF_ABI_PENDING), with SET_PERSONALITY() not actually setting the
personality, but just the "pending" bit, so that "flush_thread()" can do
the actual personality magic.

This patch in no way changes any of that insanity, but it does split the
'flush_old_exec()' function up into a preparatory part that can fail
(still called flush_old_exec()), and a new part that will actually set
up the new exec environment (setup_new_exec()). All callers are changed
to trivially comply with the new world order.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+33 -41
+1 -1
arch/sh/kernel/process_64.c
··· 368 368 void flush_thread(void) 369 369 { 370 370 371 - /* Called by fs/exec.c (flush_old_exec) to remove traces of a 371 + /* Called by fs/exec.c (setup_new_exec) to remove traces of a 372 372 * previously running executable. */ 373 373 #ifdef CONFIG_SH_FPU 374 374 if (last_task_used_math == current) {
+6 -4
arch/x86/ia32/ia32_aout.c
··· 308 308 if (retval) 309 309 return retval; 310 310 311 - regs->cs = __USER32_CS; 312 - regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 = 313 - regs->r13 = regs->r14 = regs->r15 = 0; 314 - 315 311 /* OK, This is the point of no return */ 316 312 set_personality(PER_LINUX); 317 313 set_thread_flag(TIF_IA32); 318 314 clear_thread_flag(TIF_ABI_PENDING); 315 + 316 + setup_new_exec(bprm); 317 + 318 + regs->cs = __USER32_CS; 319 + regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 = 320 + regs->r13 = regs->r14 = regs->r15 = 0; 319 321 320 322 current->mm->end_code = ex.a_text + 321 323 (current->mm->start_code = N_TXTADDR(ex));
+1
fs/binfmt_aout.c
··· 264 264 #else 265 265 set_personality(PER_LINUX); 266 266 #endif 267 + setup_new_exec(bprm); 267 268 268 269 current->mm->end_code = ex.a_text + 269 270 (current->mm->start_code = N_TXTADDR(ex));
+2 -25
fs/binfmt_elf.c
··· 662 662 if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0') 663 663 goto out_free_interp; 664 664 665 - /* 666 - * The early SET_PERSONALITY here is so that the lookup 667 - * for the interpreter happens in the namespace of the 668 - * to-be-execed image. SET_PERSONALITY can select an 669 - * alternate root. 670 - * 671 - * However, SET_PERSONALITY is NOT allowed to switch 672 - * this task into the new images's memory mapping 673 - * policy - that is, TASK_SIZE must still evaluate to 674 - * that which is appropriate to the execing application. 675 - * This is because exit_mmap() needs to have TASK_SIZE 676 - * evaluate to the size of the old image. 677 - * 678 - * So if (say) a 64-bit application is execing a 32-bit 679 - * application it is the architecture's responsibility 680 - * to defer changing the value of TASK_SIZE until the 681 - * switch really is going to happen - do this in 682 - * flush_thread(). - akpm 683 - */ 684 - SET_PERSONALITY(loc->elf_ex); 685 - 686 665 interpreter = open_exec(elf_interpreter); 687 666 retval = PTR_ERR(interpreter); 688 667 if (IS_ERR(interpreter)) ··· 709 730 /* Verify the interpreter has a valid arch */ 710 731 if (!elf_check_arch(&loc->interp_elf_ex)) 711 732 goto out_free_dentry; 712 - } else { 713 - /* Executables without an interpreter also need a personality */ 714 - SET_PERSONALITY(loc->elf_ex); 715 733 } 716 734 717 735 /* Flush all traces of the currently running executable */ ··· 728 752 729 753 if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) 730 754 current->flags |= PF_RANDOMIZE; 731 - arch_pick_mmap_layout(current->mm); 755 + 756 + setup_new_exec(bprm); 732 757 733 758 /* Do this so that we can load the interpreter, if need be. We will 734 759 change some of these later */
+3
fs/binfmt_elf_fdpic.c
··· 321 321 set_personality(PER_LINUX_FDPIC); 322 322 if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) 323 323 current->personality |= READ_IMPLIES_EXEC; 324 + 325 + setup_new_exec(bprm); 326 + 324 327 set_binfmt(&elf_fdpic_format); 325 328 326 329 current->mm->start_code = 0;
+1
fs/binfmt_flat.c
··· 519 519 520 520 /* OK, This is the point of no return */ 521 521 set_personality(PER_LINUX_32BIT); 522 + setup_new_exec(bprm); 522 523 } 523 524 524 525 /*
+1
fs/binfmt_som.c
··· 227 227 /* OK, This is the point of no return */ 228 228 current->flags &= ~PF_FORKNOEXEC; 229 229 current->personality = PER_HPUX; 230 + setup_new_exec(bprm); 230 231 231 232 /* Set the task size for HP-UX processes such that 232 233 * the gateway page is outside the address space.
+16 -10
fs/exec.c
··· 941 941 942 942 int flush_old_exec(struct linux_binprm * bprm) 943 943 { 944 - char * name; 945 - int i, ch, retval; 946 - char tcomm[sizeof(current->comm)]; 944 + int retval; 947 945 948 946 /* 949 947 * Make sure we have a private signal table and that ··· 961 963 goto out; 962 964 963 965 bprm->mm = NULL; /* We're using it now */ 966 + return 0; 967 + 968 + out: 969 + return retval; 970 + } 971 + EXPORT_SYMBOL(flush_old_exec); 972 + 973 + void setup_new_exec(struct linux_binprm * bprm) 974 + { 975 + int i, ch; 976 + char * name; 977 + char tcomm[sizeof(current->comm)]; 978 + 979 + arch_pick_mmap_layout(current->mm); 964 980 965 981 /* This is the point of no return */ 966 982 current->sas_ss_sp = current->sas_ss_size = 0; ··· 1031 1019 1032 1020 flush_signal_handlers(current, 0); 1033 1021 flush_old_files(current->files); 1034 - 1035 - return 0; 1036 - 1037 - out: 1038 - return retval; 1039 1022 } 1040 - 1041 - EXPORT_SYMBOL(flush_old_exec); 1023 + EXPORT_SYMBOL(setup_new_exec); 1042 1024 1043 1025 /* 1044 1026 * Prepare credentials and lock ->cred_guard_mutex.
+1
include/linux/binfmts.h
··· 109 109 extern int __must_check remove_arg_zero(struct linux_binprm *); 110 110 extern int search_binary_handler(struct linux_binprm *,struct pt_regs *); 111 111 extern int flush_old_exec(struct linux_binprm * bprm); 112 + extern void setup_new_exec(struct linux_binprm * bprm); 112 113 113 114 extern int suid_dumpable; 114 115 #define SUID_DUMP_DISABLE 0 /* No setuid dumping */
+1 -1
include/linux/sched.h
··· 1369 1369 char comm[TASK_COMM_LEN]; /* executable name excluding path 1370 1370 - access with [gs]et_task_comm (which lock 1371 1371 it with task_lock()) 1372 - - initialized normally by flush_old_exec */ 1372 + - initialized normally by setup_new_exec */ 1373 1373 /* file system info */ 1374 1374 int link_count, total_link_count; 1375 1375 #ifdef CONFIG_SYSVIPC