Lines Matching +full:px +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-only
37 #include <linux/elf-randomize.h>
77 * If we don't support core dumping, then supply a NULL so we
96 #define ELF_PAGESTART(_v) ((_v) & ~(int)(ELF_MIN_ALIGN-1))
97 #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
98 #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
122 int error = vm_brk_flags(start, end - start, in set_brk()
127 current->mm->start_brk = current->mm->brk = end; in set_brk()
142 nbyte = ELF_MIN_ALIGN - nbyte; in padzero()
144 return -EFAULT; in padzero()
158 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) - (items))
160 (((unsigned long) (sp - items)) &~ 15UL)
161 #define STACK_ALLOC(sp, len) (sp -= len)
178 struct mm_struct *mm = current->mm; in create_elf_tables()
179 unsigned long p = bprm->p; in create_elf_tables()
180 int argc = bprm->argc; in create_elf_tables()
181 int envc = bprm->envc; in create_elf_tables()
197 * In some cases (e.g. Hyper-Threading), we want to avoid L1 in create_elf_tables()
216 return -EFAULT; in create_elf_tables()
229 return -EFAULT; in create_elf_tables()
239 return -EFAULT; in create_elf_tables()
242 elf_info = (elf_addr_t *)mm->saved_auxv; in create_elf_tables()
264 NEW_AUX_ENT(AT_PHNUM, exec->e_phnum); in create_elf_tables()
266 if (bprm->interp_flags & BINPRM_FLAGS_PRESERVE_ARGV0) in create_elf_tables()
270 NEW_AUX_ENT(AT_UID, from_kuid_munged(cred->user_ns, cred->uid)); in create_elf_tables()
271 NEW_AUX_ENT(AT_EUID, from_kuid_munged(cred->user_ns, cred->euid)); in create_elf_tables()
272 NEW_AUX_ENT(AT_GID, from_kgid_munged(cred->user_ns, cred->gid)); in create_elf_tables()
273 NEW_AUX_ENT(AT_EGID, from_kgid_munged(cred->user_ns, cred->egid)); in create_elf_tables()
274 NEW_AUX_ENT(AT_SECURE, bprm->secureexec); in create_elf_tables()
279 NEW_AUX_ENT(AT_EXECFN, bprm->exec); in create_elf_tables()
288 if (bprm->have_execfd) { in create_elf_tables()
289 NEW_AUX_ENT(AT_EXECFD, bprm->execfd); in create_elf_tables()
293 memset(elf_info, 0, (char *)mm->saved_auxv + in create_elf_tables()
294 sizeof(mm->saved_auxv) - (char *)elf_info); in create_elf_tables()
299 ei_index = elf_info - (elf_addr_t *)mm->saved_auxv; in create_elf_tables()
303 bprm->p = STACK_ROUND(sp, items); in create_elf_tables()
307 sp = (elf_addr_t __user *)bprm->p - items - ei_index; in create_elf_tables()
308 bprm->exec = (unsigned long)sp; /* XXX: PARISC HACK */ in create_elf_tables()
310 sp = (elf_addr_t __user *)bprm->p; in create_elf_tables()
316 * far ahead a user-space access may be in order to grow the stack. in create_elf_tables()
319 return -EINTR; in create_elf_tables()
320 vma = find_extend_vma(mm, bprm->p); in create_elf_tables()
323 return -EFAULT; in create_elf_tables()
327 return -EFAULT; in create_elf_tables()
330 p = mm->arg_end = mm->arg_start; in create_elf_tables()
331 while (argc-- > 0) { in create_elf_tables()
334 return -EFAULT; in create_elf_tables()
337 return -EINVAL; in create_elf_tables()
341 return -EFAULT; in create_elf_tables()
342 mm->arg_end = p; in create_elf_tables()
345 mm->env_end = mm->env_start = p; in create_elf_tables()
346 while (envc-- > 0) { in create_elf_tables()
349 return -EFAULT; in create_elf_tables()
352 return -EINVAL; in create_elf_tables()
356 return -EFAULT; in create_elf_tables()
357 mm->env_end = p; in create_elf_tables()
360 if (copy_to_user(sp, mm->saved_auxv, ei_index * sizeof(elf_addr_t))) in create_elf_tables()
361 return -EFAULT; in create_elf_tables()
370 unsigned long size = eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr); in elf_map()
371 unsigned long off = eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr); in elf_map()
375 /* mmap() will return -EINVAL if given a zero size, but a in elf_map()
385 * So we first map the 'big' image - and unmap the remainder at in elf_map()
392 vm_munmap(map_addr+size, total_size-size); in elf_map()
397 PTR_ERR((void *)map_addr) == -EEXIST) in elf_map()
398 pr_info("%d (%s): Uhuuh, elf segment at %px requested but the memory is mapped already\n", in elf_map()
399 task_pid_nr(current), current->comm, (void *)addr); in elf_map()
406 elf_addr_t min_addr = -1; in total_mapping_size()
418 return pt_load ? (max_addr - min_addr) : 0; in total_mapping_size()
427 return (rv < 0) ? rv : -EIO; in elf_read()
441 /* skip non-power of two alignments as invalid */ in maximum_alignment()
453 * load_elf_phdrs() - load ELF program headers
465 int retval, err = -1; in load_elf_phdrs()
472 if (elf_ex->e_phentsize != sizeof(struct elf_phdr)) in load_elf_phdrs()
477 size = sizeof(struct elf_phdr) * elf_ex->e_phnum; in load_elf_phdrs()
486 retval = elf_read(elf_file, elf_phdata, size, elf_ex->e_phoff); in load_elf_phdrs()
505 * struct arch_elf_state - arch-specific ELF loading state
521 * arch_elf_pt_proc() - check a PT_LOPROC..PT_HIPROC ELF program header
527 * @state: Architecture-specific state preserved throughout the process
535 * Return: Zero to proceed with the ELF load, non-zero to fail the ELF load
548 * arch_check_elf() - check an ELF executable
552 * @state: Architecture-specific state preserved throughout the process
559 * Return: Zero to proceed with the ELF load, non-zero to fail the ELF load
607 if (interp_elf_ex->e_type != ET_EXEC && in load_elf_interp()
608 interp_elf_ex->e_type != ET_DYN) in load_elf_interp()
613 if (!interpreter->f_op->mmap) in load_elf_interp()
617 interp_elf_ex->e_phnum); in load_elf_interp()
619 error = -EINVAL; in load_elf_interp()
624 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) { in load_elf_interp()
625 if (eppnt->p_type == PT_LOAD) { in load_elf_interp()
627 int elf_prot = make_prot(eppnt->p_flags, arch_state, in load_elf_interp()
632 vaddr = eppnt->p_vaddr; in load_elf_interp()
633 if (interp_elf_ex->e_type == ET_EXEC || load_addr_set) in load_elf_interp()
635 else if (no_base && interp_elf_ex->e_type == ET_DYN) in load_elf_interp()
636 load_addr = -vaddr; in load_elf_interp()
646 interp_elf_ex->e_type == ET_DYN) { in load_elf_interp()
647 load_addr = map_addr - ELF_PAGESTART(vaddr); in load_elf_interp()
656 k = load_addr + eppnt->p_vaddr; in load_elf_interp()
658 eppnt->p_filesz > eppnt->p_memsz || in load_elf_interp()
659 eppnt->p_memsz > TASK_SIZE || in load_elf_interp()
660 TASK_SIZE - eppnt->p_memsz < k) { in load_elf_interp()
661 error = -ENOMEM; in load_elf_interp()
669 k = load_addr + eppnt->p_vaddr + eppnt->p_filesz; in load_elf_interp()
674 * Do the same thing for the memory mapping - between in load_elf_interp()
677 k = load_addr + eppnt->p_vaddr + eppnt->p_memsz; in load_elf_interp()
691 error = -EFAULT; in load_elf_interp()
703 error = vm_brk_flags(elf_bss, last_bss - elf_bss, in load_elf_interp()
728 return -ENOENT; in parse_elf_property()
731 return -EIO; in parse_elf_property()
733 datasz -= *off; in parse_elf_property()
736 return -ENOEXEC; in parse_elf_property()
739 datasz -= sizeof(*pr); in parse_elf_property()
741 if (pr->pr_datasz > datasz) in parse_elf_property()
742 return -ENOEXEC; in parse_elf_property()
745 step = round_up(pr->pr_datasz, ELF_GNU_PROPERTY_ALIGN); in parse_elf_property()
747 return -ENOEXEC; in parse_elf_property()
750 if (have_prev_type && pr->pr_type <= *prev_type) in parse_elf_property()
751 return -ENOEXEC; in parse_elf_property()
752 *prev_type = pr->pr_type; in parse_elf_property()
754 ret = arch_parse_elf_property(pr->pr_type, data + o, in parse_elf_property()
755 pr->pr_datasz, ELF_COMPAT, arch); in parse_elf_property()
785 if (WARN_ON_ONCE(phdr->p_type != PT_GNU_PROPERTY)) in parse_elf_properties()
786 return -ENOEXEC; in parse_elf_properties()
789 if (phdr->p_filesz > sizeof(note)) in parse_elf_properties()
790 return -ENOEXEC; in parse_elf_properties()
792 pos = phdr->p_offset; in parse_elf_properties()
793 n = kernel_read(f, &note, phdr->p_filesz, &pos); in parse_elf_properties()
797 return -EIO; in parse_elf_properties()
802 GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr))) in parse_elf_properties()
803 return -ENOEXEC; in parse_elf_properties()
808 return -ENOEXEC; in parse_elf_properties()
810 if (note.nhdr.n_descsz > n - off) in parse_elf_properties()
811 return -ENOEXEC; in parse_elf_properties()
821 return ret == -ENOENT ? 0 : ret; in parse_elf_properties()
841 struct elfhdr *elf_ex = (struct elfhdr *)bprm->buf; in load_elf_binary()
847 retval = -ENOEXEC; in load_elf_binary()
849 if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0) in load_elf_binary()
852 if (elf_ex->e_type != ET_EXEC && elf_ex->e_type != ET_DYN) in load_elf_binary()
858 if (!bprm->file->f_op->mmap) in load_elf_binary()
861 elf_phdata = load_elf_phdrs(elf_ex, bprm->file); in load_elf_binary()
866 for (i = 0; i < elf_ex->e_phnum; i++, elf_ppnt++) { in load_elf_binary()
869 if (elf_ppnt->p_type == PT_GNU_PROPERTY) { in load_elf_binary()
874 if (elf_ppnt->p_type != PT_INTERP) in load_elf_binary()
878 * This is the program interpreter used for shared libraries - in load_elf_binary()
881 retval = -ENOEXEC; in load_elf_binary()
882 if (elf_ppnt->p_filesz > PATH_MAX || elf_ppnt->p_filesz < 2) in load_elf_binary()
885 retval = -ENOMEM; in load_elf_binary()
886 elf_interpreter = kmalloc(elf_ppnt->p_filesz, GFP_KERNEL); in load_elf_binary()
890 retval = elf_read(bprm->file, elf_interpreter, elf_ppnt->p_filesz, in load_elf_binary()
891 elf_ppnt->p_offset); in load_elf_binary()
895 retval = -ENOEXEC; in load_elf_binary()
896 if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0') in load_elf_binary()
906 * If the binary is not readable then enforce mm->dumpable = 0 in load_elf_binary()
913 retval = -ENOMEM; in load_elf_binary()
931 for (i = 0; i < elf_ex->e_phnum; i++, elf_ppnt++) in load_elf_binary()
932 switch (elf_ppnt->p_type) { in load_elf_binary()
934 if (elf_ppnt->p_flags & PF_X) in load_elf_binary()
942 bprm->file, false, in load_elf_binary()
951 retval = -ELIBBAD; in load_elf_binary()
953 if (memcmp(interp_elf_ex->e_ident, ELFMAG, SELFMAG) != 0) in load_elf_binary()
969 for (i = 0; i < interp_elf_ex->e_phnum; i++, elf_ppnt++) in load_elf_binary()
970 switch (elf_ppnt->p_type) { in load_elf_binary()
985 retval = parse_elf_properties(interpreter ?: bprm->file, in load_elf_binary()
1010 current->personality |= READ_IMPLIES_EXEC; in load_elf_binary()
1012 if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) in load_elf_binary()
1013 current->flags |= PF_RANDOMIZE; in load_elf_binary()
1035 i < elf_ex->e_phnum; i++, elf_ppnt++) { in load_elf_binary()
1041 if (elf_ppnt->p_type != PT_LOAD) in load_elf_binary()
1057 nbyte = ELF_MIN_ALIGN - nbyte; in load_elf_binary()
1058 if (nbyte > elf_brk - elf_bss) in load_elf_binary()
1059 nbyte = elf_brk - elf_bss; in load_elf_binary()
1063 * This bss-zeroing can fail if the ELF in load_elf_binary()
1071 elf_prot = make_prot(elf_ppnt->p_flags, &arch_state, in load_elf_binary()
1076 vaddr = elf_ppnt->p_vaddr; in load_elf_binary()
1081 * MAP_FIXED_NOREPLACE in the once-per-binary logic following. in load_elf_binary()
1085 } else if (elf_ex->e_type == ET_EXEC) { in load_elf_binary()
1092 } else if (elf_ex->e_type == ET_DYN) { in load_elf_binary()
1122 if (current->flags & PF_RANDOMIZE) in load_elf_binary()
1124 alignment = maximum_alignment(elf_phdata, elf_ex->e_phnum); in load_elf_binary()
1126 load_bias &= ~(alignment - 1); in load_elf_binary()
1138 load_bias = ELF_PAGESTART(load_bias - vaddr); in load_elf_binary()
1159 elf_ex->e_phnum); in load_elf_binary()
1161 retval = -EINVAL; in load_elf_binary()
1166 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, in load_elf_binary()
1170 PTR_ERR((void*)error) : -EINVAL; in load_elf_binary()
1176 if (elf_ex->e_type == ET_DYN) { in load_elf_binary()
1177 load_bias += error - in load_elf_binary()
1187 if (elf_ppnt->p_offset <= elf_ex->e_phoff && in load_elf_binary()
1188 elf_ex->e_phoff < elf_ppnt->p_offset + elf_ppnt->p_filesz) { in load_elf_binary()
1189 phdr_addr = elf_ex->e_phoff - elf_ppnt->p_offset + in load_elf_binary()
1190 elf_ppnt->p_vaddr; in load_elf_binary()
1193 k = elf_ppnt->p_vaddr; in load_elf_binary()
1194 if ((elf_ppnt->p_flags & PF_X) && k < start_code) in load_elf_binary()
1204 if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz || in load_elf_binary()
1205 elf_ppnt->p_memsz > TASK_SIZE || in load_elf_binary()
1206 TASK_SIZE - elf_ppnt->p_memsz < k) { in load_elf_binary()
1208 retval = -EINVAL; in load_elf_binary()
1212 k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; in load_elf_binary()
1216 if ((elf_ppnt->p_flags & PF_X) && end_code < k) in load_elf_binary()
1220 k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; in load_elf_binary()
1227 e_entry = elf_ex->e_entry + load_bias; in load_elf_binary()
1245 retval = -EFAULT; /* Nobody gets to see this, but.. */ in load_elf_binary()
1260 elf_entry += interp_elf_ex->e_entry; in load_elf_binary()
1264 (int)elf_entry : -EINVAL; in load_elf_binary()
1277 retval = -EINVAL; in load_elf_binary()
1297 mm = current->mm; in load_elf_binary()
1298 mm->end_code = end_code; in load_elf_binary()
1299 mm->start_code = start_code; in load_elf_binary()
1300 mm->start_data = start_data; in load_elf_binary()
1301 mm->end_data = end_data; in load_elf_binary()
1302 mm->start_stack = bprm->p; in load_elf_binary()
1304 if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) { in load_elf_binary()
1313 elf_ex->e_type == ET_DYN && !interpreter) { in load_elf_binary()
1314 mm->brk = mm->start_brk = ELF_ET_DYN_BASE; in load_elf_binary()
1317 mm->brk = mm->start_brk = arch_randomize_brk(mm); in load_elf_binary()
1319 current->brk_randomized = 1; in load_elf_binary()
1323 if (current->personality & MMAP_PAGE_ZERO) { in load_elf_binary()
1324 /* Why this, you ask??? Well SVr4 maps page 0 as read-only, in load_elf_binary()
1348 START_THREAD(elf_ex, regs, elf_entry, bprm->p); in load_elf_binary()
1367 /* This is really simpleminded and specialized - we are loading an
1377 error = -ENOEXEC; in load_elf_library()
1387 !elf_check_arch(&elf_ex) || !file->f_op->mmap) in load_elf_library()
1397 error = -ENOMEM; in load_elf_library()
1403 error = -ENOEXEC; in load_elf_library()
1409 if ((eppnt + i)->p_type == PT_LOAD) in load_elf_library()
1414 while (eppnt->p_type != PT_LOAD) in load_elf_library()
1419 ELF_PAGESTART(eppnt->p_vaddr), in load_elf_library()
1420 (eppnt->p_filesz + in load_elf_library()
1421 ELF_PAGEOFFSET(eppnt->p_vaddr)), in load_elf_library()
1424 (eppnt->p_offset - in load_elf_library()
1425 ELF_PAGEOFFSET(eppnt->p_vaddr))); in load_elf_library()
1426 if (error != ELF_PAGESTART(eppnt->p_vaddr)) in load_elf_library()
1429 elf_bss = eppnt->p_vaddr + eppnt->p_filesz; in load_elf_library()
1431 error = -EFAULT; in load_elf_library()
1435 len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr); in load_elf_library()
1436 bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr); in load_elf_library()
1438 error = vm_brk(len, bss - len); in load_elf_library()
1473 sz += roundup(strlen(en->name) + 1, 4); in notesize()
1474 sz += roundup(en->datasz, 4); in notesize()
1482 en.n_namesz = strlen(men->name) + 1; in writenote()
1483 en.n_descsz = men->datasz; in writenote()
1484 en.n_type = men->type; in writenote()
1487 dump_emit(cprm, men->name, en.n_namesz) && dump_align(cprm, 4) && in writenote()
1488 dump_emit(cprm, men->data, men->datasz) && dump_align(cprm, 4); in writenote()
1496 memcpy(elf->e_ident, ELFMAG, SELFMAG); in fill_elf_header()
1497 elf->e_ident[EI_CLASS] = ELF_CLASS; in fill_elf_header()
1498 elf->e_ident[EI_DATA] = ELF_DATA; in fill_elf_header()
1499 elf->e_ident[EI_VERSION] = EV_CURRENT; in fill_elf_header()
1500 elf->e_ident[EI_OSABI] = ELF_OSABI; in fill_elf_header()
1502 elf->e_type = ET_CORE; in fill_elf_header()
1503 elf->e_machine = machine; in fill_elf_header()
1504 elf->e_version = EV_CURRENT; in fill_elf_header()
1505 elf->e_phoff = sizeof(struct elfhdr); in fill_elf_header()
1506 elf->e_flags = flags; in fill_elf_header()
1507 elf->e_ehsize = sizeof(struct elfhdr); in fill_elf_header()
1508 elf->e_phentsize = sizeof(struct elf_phdr); in fill_elf_header()
1509 elf->e_phnum = segs; in fill_elf_header()
1514 phdr->p_type = PT_NOTE; in fill_elf_note_phdr()
1515 phdr->p_offset = offset; in fill_elf_note_phdr()
1516 phdr->p_vaddr = 0; in fill_elf_note_phdr()
1517 phdr->p_paddr = 0; in fill_elf_note_phdr()
1518 phdr->p_filesz = sz; in fill_elf_note_phdr()
1519 phdr->p_memsz = 0; in fill_elf_note_phdr()
1520 phdr->p_flags = 0; in fill_elf_note_phdr()
1521 phdr->p_align = 0; in fill_elf_note_phdr()
1527 note->name = name; in fill_note()
1528 note->type = type; in fill_note()
1529 note->datasz = sz; in fill_note()
1530 note->data = data; in fill_note()
1540 prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; in fill_prstatus()
1541 prstatus->pr_sigpend = p->pending.signal.sig[0]; in fill_prstatus()
1542 prstatus->pr_sighold = p->blocked.sig[0]; in fill_prstatus()
1544 prstatus->pr_ppid = task_pid_vnr(rcu_dereference(p->real_parent)); in fill_prstatus()
1546 prstatus->pr_pid = task_pid_vnr(p); in fill_prstatus()
1547 prstatus->pr_pgrp = task_pgrp_vnr(p); in fill_prstatus()
1548 prstatus->pr_sid = task_session_vnr(p); in fill_prstatus()
1554 * group-wide total, not its individual thread total. in fill_prstatus()
1557 prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime); in fill_prstatus()
1558 prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime); in fill_prstatus()
1563 prstatus->pr_utime = ns_to_kernel_old_timeval(utime); in fill_prstatus()
1564 prstatus->pr_stime = ns_to_kernel_old_timeval(stime); in fill_prstatus()
1567 prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime); in fill_prstatus()
1568 prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime); in fill_prstatus()
1581 len = mm->arg_end - mm->arg_start; in fill_psinfo()
1583 len = ELF_PRARGSZ-1; in fill_psinfo()
1584 if (copy_from_user(&psinfo->pr_psargs, in fill_psinfo()
1585 (const char __user *)mm->arg_start, len)) in fill_psinfo()
1586 return -EFAULT; in fill_psinfo()
1588 if (psinfo->pr_psargs[i] == 0) in fill_psinfo()
1589 psinfo->pr_psargs[i] = ' '; in fill_psinfo()
1590 psinfo->pr_psargs[len] = 0; in fill_psinfo()
1593 psinfo->pr_ppid = task_pid_vnr(rcu_dereference(p->real_parent)); in fill_psinfo()
1595 psinfo->pr_pid = task_pid_vnr(p); in fill_psinfo()
1596 psinfo->pr_pgrp = task_pgrp_vnr(p); in fill_psinfo()
1597 psinfo->pr_sid = task_session_vnr(p); in fill_psinfo()
1599 state = READ_ONCE(p->__state); in fill_psinfo()
1601 psinfo->pr_state = i; in fill_psinfo()
1602 psinfo->pr_sname = (i > 5) ? '.' : "RSDTZW"[i]; in fill_psinfo()
1603 psinfo->pr_zomb = psinfo->pr_sname == 'Z'; in fill_psinfo()
1604 psinfo->pr_nice = task_nice(p); in fill_psinfo()
1605 psinfo->pr_flag = p->flags; in fill_psinfo()
1608 SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); in fill_psinfo()
1609 SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); in fill_psinfo()
1611 get_task_comm(psinfo->pr_fname, p); in fill_psinfo()
1618 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv; in fill_auxv_note()
1622 while (auxv[i - 2] != AT_NULL); in fill_auxv_note()
1637 * long count -- how many files are mapped
1638 * long page_size -- units for file_ofs
1654 count = cprm->vma_count; in fill_files_note()
1656 return -EINVAL; in fill_files_note()
1662 return -EINVAL; in fill_files_note()
1670 return -ENOMEM; in fill_files_note()
1674 remaining = size - names_ofs; in fill_files_note()
1676 for (i = 0; i < cprm->vma_count; i++) { in fill_files_note()
1677 struct core_vma_metadata *m = &cprm->vma_meta[i]; in fill_files_note()
1681 file = m->file; in fill_files_note()
1686 if (PTR_ERR(filename) == -ENAMETOOLONG) { in fill_files_note()
1696 n = (name_curpos + remaining) - filename; in fill_files_note()
1697 remaining = filename - name_curpos; in fill_files_note()
1701 *start_end_ofs++ = m->start; in fill_files_note()
1702 *start_end_ofs++ = m->end; in fill_files_note()
1703 *start_end_ofs++ = m->pgoff; in fill_files_note()
1711 * Count usually is less than mm->map_count, in fill_files_note()
1714 n = cprm->vma_count - count; in fill_files_note()
1717 memmove(name_base - shift_bytes, name_base, in fill_files_note()
1718 name_curpos - name_base); in fill_files_note()
1719 name_curpos -= shift_bytes; in fill_files_note()
1722 size = name_curpos - (char *)data; in fill_files_note()
1756 if (regset->writeback) in do_thread_regset_writeback()
1757 regset->writeback(task, regset, 1); in do_thread_regset_writeback()
1765 #define SET_PR_FPVALID(S) ((S)->pr_fpvalid = 1)
1780 fill_prstatus(&t->prstatus.common, t->task, signr); in fill_thread_core_info()
1781 regset_get(t->task, &view->regsets[0], in fill_thread_core_info()
1782 sizeof(t->prstatus.pr_reg), &t->prstatus.pr_reg); in fill_thread_core_info()
1784 fill_note(&t->notes[0], "CORE", NT_PRSTATUS, in fill_thread_core_info()
1785 PRSTATUS_SIZE, &t->prstatus); in fill_thread_core_info()
1786 info->size += notesize(&t->notes[0]); in fill_thread_core_info()
1788 do_thread_regset_writeback(t->task, &view->regsets[0]); in fill_thread_core_info()
1795 for (view_iter = 1; view_iter < view->n; ++view_iter) { in fill_thread_core_info()
1796 const struct user_regset *regset = &view->regsets[view_iter]; in fill_thread_core_info()
1797 int note_type = regset->core_note_type; in fill_thread_core_info()
1802 do_thread_regset_writeback(t->task, regset); in fill_thread_core_info()
1805 if (regset->active && regset->active(t->task, regset) <= 0) in fill_thread_core_info()
1808 ret = regset_get_alloc(t->task, regset, ~0U, &data); in fill_thread_core_info()
1812 if (WARN_ON_ONCE(note_iter >= info->thread_notes)) in fill_thread_core_info()
1816 SET_PR_FPVALID(&t->prstatus); in fill_thread_core_info()
1818 fill_note(&t->notes[note_iter], is_fpreg ? "CORE" : "LINUX", in fill_thread_core_info()
1821 info->size += notesize(&t->notes[note_iter]); in fill_thread_core_info()
1839 info->size = 0; in fill_note_info()
1840 info->thread = NULL; in fill_note_info()
1844 info->psinfo.data = NULL; /* So we don't free this wrongly */ in fill_note_info()
1848 fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo); in fill_note_info()
1853 info->thread_notes = 0; in fill_note_info()
1854 for (i = 0; i < view->n; ++i) in fill_note_info()
1855 if (view->regsets[i].core_note_type != 0) in fill_note_info()
1856 ++info->thread_notes; in fill_note_info()
1862 if (unlikely(info->thread_notes == 0) || in fill_note_info()
1863 unlikely(view->regsets[0].core_note_type != NT_PRSTATUS)) { in fill_note_info()
1872 view->e_machine, view->e_flags); in fill_note_info()
1877 for (ct = &dump_task->signal->core_state->dumper; ct; ct = ct->next) { in fill_note_info()
1879 notes[info->thread_notes]), in fill_note_info()
1884 t->task = ct->task; in fill_note_info()
1885 if (ct->task == dump_task || !info->thread) { in fill_note_info()
1886 t->next = info->thread; in fill_note_info()
1887 info->thread = t; in fill_note_info()
1893 t->next = info->thread->next; in fill_note_info()
1894 info->thread->next = t; in fill_note_info()
1901 for (t = info->thread; t != NULL; t = t->next) in fill_note_info()
1902 if (!fill_thread_core_info(t, view, cprm->siginfo->si_signo, info)) in fill_note_info()
1906 * Fill in the two process-wide notes. in fill_note_info()
1908 fill_psinfo(psinfo, dump_task->group_leader, dump_task->mm); in fill_note_info()
1909 info->size += notesize(&info->psinfo); in fill_note_info()
1911 fill_siginfo_note(&info->signote, &info->csigdata, cprm->siginfo); in fill_note_info()
1912 info->size += notesize(&info->signote); in fill_note_info()
1914 fill_auxv_note(&info->auxv, current->mm); in fill_note_info()
1915 info->size += notesize(&info->auxv); in fill_note_info()
1917 if (fill_files_note(&info->files, cprm) == 0) in fill_note_info()
1918 info->size += notesize(&info->files); in fill_note_info()
1925 return info->size; in get_note_info_size()
1930 * process-wide notes are interleaved after the first thread-specific note.
1936 struct elf_thread_core_info *t = info->thread; in write_note_info()
1941 if (!writenote(&t->notes[0], cprm)) in write_note_info()
1944 if (first && !writenote(&info->psinfo, cprm)) in write_note_info()
1946 if (first && !writenote(&info->signote, cprm)) in write_note_info()
1948 if (first && !writenote(&info->auxv, cprm)) in write_note_info()
1950 if (first && info->files.data && in write_note_info()
1951 !writenote(&info->files, cprm)) in write_note_info()
1954 for (i = 1; i < info->thread_notes; ++i) in write_note_info()
1955 if (t->notes[i].data && in write_note_info()
1956 !writenote(&t->notes[i], cprm)) in write_note_info()
1960 t = t->next; in write_note_info()
1968 struct elf_thread_core_info *threads = info->thread; in free_note_info()
1972 threads = t->next; in free_note_info()
1973 WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus); in free_note_info()
1974 for (i = 1; i < info->thread_notes; ++i) in free_note_info()
1975 kfree(t->notes[i].data); in free_note_info()
1978 kfree(info->psinfo.data); in free_note_info()
1979 kvfree(info->files.data); in free_note_info()
2003 struct task_struct *p = t->thread; in elf_dump_thread_status()
2004 t->num_notes = 0; in elf_dump_thread_status()
2006 fill_prstatus(&t->prstatus.common, p, signr); in elf_dump_thread_status()
2007 elf_core_copy_task_regs(p, &t->prstatus.pr_reg); in elf_dump_thread_status()
2009 fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus), in elf_dump_thread_status()
2010 &(t->prstatus)); in elf_dump_thread_status()
2011 t->num_notes++; in elf_dump_thread_status()
2012 sz += notesize(&t->notes[0]); in elf_dump_thread_status()
2014 if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, in elf_dump_thread_status()
2015 &t->fpu))) { in elf_dump_thread_status()
2016 fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu), in elf_dump_thread_status()
2017 &(t->fpu)); in elf_dump_thread_status()
2018 t->num_notes++; in elf_dump_thread_status()
2019 sz += notesize(&t->notes[1]); in elf_dump_thread_status()
2039 INIT_LIST_HEAD(&info->thread_list); in elf_note_info_init()
2042 info->notes = kmalloc_array(8, sizeof(struct memelfnote), GFP_KERNEL); in elf_note_info_init()
2043 if (!info->notes) in elf_note_info_init()
2045 info->psinfo = kmalloc(sizeof(*info->psinfo), GFP_KERNEL); in elf_note_info_init()
2046 if (!info->psinfo) in elf_note_info_init()
2048 info->prstatus = kmalloc(sizeof(*info->prstatus), GFP_KERNEL); in elf_note_info_init()
2049 if (!info->prstatus) in elf_note_info_init()
2051 info->fpu = kmalloc(sizeof(*info->fpu), GFP_KERNEL); in elf_note_info_init()
2052 if (!info->fpu) in elf_note_info_init()
2067 for (ct = current->signal->core_state->dumper.next; in fill_note_info()
2068 ct; ct = ct->next) { in fill_note_info()
2073 ets->thread = ct->task; in fill_note_info()
2074 list_add(&ets->list, &info->thread_list); in fill_note_info()
2077 list_for_each_entry(ets, &info->thread_list, list) { in fill_note_info()
2080 sz = elf_dump_thread_status(cprm->siginfo->si_signo, ets); in fill_note_info()
2081 info->thread_status_size += sz; in fill_note_info()
2084 memset(info->prstatus, 0, sizeof(*info->prstatus)); in fill_note_info()
2085 fill_prstatus(&info->prstatus->common, current, cprm->siginfo->si_signo); in fill_note_info()
2086 elf_core_copy_regs(&info->prstatus->pr_reg, cprm->regs); in fill_note_info()
2096 fill_note(info->notes + 0, "CORE", NT_PRSTATUS, in fill_note_info()
2097 sizeof(*info->prstatus), info->prstatus); in fill_note_info()
2098 fill_psinfo(info->psinfo, current->group_leader, current->mm); in fill_note_info()
2099 fill_note(info->notes + 1, "CORE", NT_PRPSINFO, in fill_note_info()
2100 sizeof(*info->psinfo), info->psinfo); in fill_note_info()
2102 fill_siginfo_note(info->notes + 2, &info->csigdata, cprm->siginfo); in fill_note_info()
2103 fill_auxv_note(info->notes + 3, current->mm); in fill_note_info()
2104 info->numnote = 4; in fill_note_info()
2106 if (fill_files_note(info->notes + info->numnote, cprm) == 0) { in fill_note_info()
2107 info->notes_files = info->notes + info->numnote; in fill_note_info()
2108 info->numnote++; in fill_note_info()
2112 info->prstatus->pr_fpvalid = in fill_note_info()
2113 elf_core_copy_task_fpregs(current, cprm->regs, info->fpu); in fill_note_info()
2114 if (info->prstatus->pr_fpvalid) in fill_note_info()
2115 fill_note(info->notes + info->numnote++, in fill_note_info()
2116 "CORE", NT_PRFPREG, sizeof(*info->fpu), info->fpu); in fill_note_info()
2125 for (i = 0; i < info->numnote; i++) in get_note_info_size()
2126 sz += notesize(info->notes + i); in get_note_info_size()
2128 sz += info->thread_status_size; in get_note_info_size()
2139 for (i = 0; i < info->numnote; i++) in write_note_info()
2140 if (!writenote(info->notes + i, cprm)) in write_note_info()
2144 list_for_each_entry(ets, &info->thread_list, list) { in write_note_info()
2145 for (i = 0; i < ets->num_notes; i++) in write_note_info()
2146 if (!writenote(&ets->notes[i], cprm)) in write_note_info()
2155 while (!list_empty(&info->thread_list)) { in free_note_info()
2156 struct list_head *tmp = info->thread_list.next; in free_note_info()
2162 if (info->notes_files) in free_note_info()
2163 kvfree(info->notes_files->data); in free_note_info()
2165 kfree(info->prstatus); in free_note_info()
2166 kfree(info->psinfo); in free_note_info()
2167 kfree(info->notes); in free_note_info()
2168 kfree(info->fpu); in free_note_info()
2176 elf->e_shoff = e_shoff; in fill_extnum_info()
2177 elf->e_shentsize = sizeof(*shdr4extnum); in fill_extnum_info()
2178 elf->e_shnum = 1; in fill_extnum_info()
2179 elf->e_shstrndx = SHN_UNDEF; in fill_extnum_info()
2183 shdr4extnum->sh_type = SHT_NULL; in fill_extnum_info()
2184 shdr4extnum->sh_size = elf->e_shnum; in fill_extnum_info()
2185 shdr4extnum->sh_link = elf->e_shstrndx; in fill_extnum_info()
2186 shdr4extnum->sh_info = segs; in fill_extnum_info()
2192 * This is a two-pass process; first we find the offsets of the bits,
2212 segs = cprm->vma_count + elf_core_extra_phdrs(); in elf_core_dump()
2223 * Collect all the non-memory information about the process for the in elf_core_dump()
2251 offset += cprm->vma_data_size; in elf_core_dump()
2271 for (i = 0; i < cprm->vma_count; i++) { in elf_core_dump()
2272 struct core_vma_metadata *meta = cprm->vma_meta + i; in elf_core_dump()
2277 phdr.p_vaddr = meta->start; in elf_core_dump()
2279 phdr.p_filesz = meta->dump_size; in elf_core_dump()
2280 phdr.p_memsz = meta->end - meta->start; in elf_core_dump()
2283 if (meta->flags & VM_READ) in elf_core_dump()
2285 if (meta->flags & VM_WRITE) in elf_core_dump()
2287 if (meta->flags & VM_EXEC) in elf_core_dump()
2309 for (i = 0; i < cprm->vma_count; i++) { in elf_core_dump()
2310 struct core_vma_metadata *meta = cprm->vma_meta + i; in elf_core_dump()
2312 if (!dump_user_range(cprm, meta->start, meta->dump_size)) in elf_core_dump()