Index: kern/imgact_elf.c =================================================================== RCS file: /home/cvsroot/jsn/sys/kern/imgact_elf.c,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- kern/imgact_elf.c 2000/04/17 10:30:39 1.1.1.1 +++ kern/imgact_elf.c 2000/04/25 16:52:11 1.4 @@ -451,7 +451,38 @@ return ENOEXEC; } phdr = (const Elf_Phdr*)(imgp->image_header + hdr->e_phoff); + + /* we better check rlimits *before* new vmspace is exec()-ed */ + for (i = 0; i < hdr->e_phnum; i++) { + if (phdr[i].p_type == PT_LOAD) { /* Loadable segment */ + /* + * Is this .text or .data ?? + * + * We only handle one each of those yet XXX + */ + if (hdr->e_entry >= phdr[i].p_vaddr && + hdr->e_entry <(phdr[i].p_vaddr+phdr[i].p_memsz)) { + text_addr = trunc_page(phdr[i].p_vaddr); + text_size = round_page(phdr[i].p_memsz + + phdr[i].p_vaddr - + text_addr); + entry = (u_long)hdr->e_entry; + } else { + data_addr = trunc_page(phdr[i].p_vaddr); + data_size = round_page(phdr[i].p_memsz + + phdr[i].p_vaddr - + data_addr); + } + } + } + + if (text_size > MAXTSIZ || + data_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur) { + error = ENOMEM ; + goto fail ; + } + /* * From this point on, we may have resources that need to be freed. */ @@ -481,25 +513,6 @@ phdr[i].p_memsz, phdr[i].p_filesz, prot)) != 0) goto fail; - - /* - * Is this .text or .data ?? - * - * We only handle one each of those yet XXX - */ - if (hdr->e_entry >= phdr[i].p_vaddr && - hdr->e_entry <(phdr[i].p_vaddr+phdr[i].p_memsz)) { - text_addr = trunc_page(phdr[i].p_vaddr); - text_size = round_page(phdr[i].p_memsz + - phdr[i].p_vaddr - - text_addr); - entry = (u_long)hdr->e_entry; - } else { - data_addr = trunc_page(phdr[i].p_vaddr); - data_size = round_page(phdr[i].p_memsz + - phdr[i].p_vaddr - - data_addr); - } break; case PT_INTERP: /* Path to interpreter */ if (phdr[i].p_filesz > MAXPATHLEN ||