-/* $OpenBSD: exec_elf.c,v 1.184 2024/01/16 19:05:01 deraadt Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.185 2024/01/17 22:22:25 kurt Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
goto out;
error = coredump_write(cookie, UIO_SYSSPACE, ws.psections,
- ws.psectionslen);
+ ws.psectionslen, 0);
if (error)
goto out;
if (pent->p_vaddr == p->p_p->ps_sigcode &&
pent->p_filesz == sigcode_sz) {
error = coredump_write(cookie, UIO_SYSSPACE,
- (void *)sigcode_va, sigcode_sz);
+ (void *)sigcode_va, sigcode_sz, 0);
} else {
error = coredump_write(cookie, UIO_USERSPACE,
- (void *)(vaddr_t)pent->p_vaddr, pent->p_filesz);
+ (void *)(vaddr_t)pent->p_vaddr, pent->p_filesz,
+ (pent->p_flags & PF_ISVNODE));
}
if (error)
goto out;
}
/* Write out the ELF header. */
- error = coredump_write(ws->iocookie, UIO_SYSSPACE, &ehdr, sizeof(ehdr));
+ error = coredump_write(ws->iocookie, UIO_SYSSPACE, &ehdr, sizeof(ehdr), 0);
if (error)
return error;
if (ehdr.e_shnum != 0) {
Elf_Shdr shdr = { .sh_info = ws->npsections };
error = coredump_write(ws->iocookie, UIO_SYSSPACE, &shdr,
- sizeof shdr);
+ sizeof shdr, 0);
if (error)
return error;
error = coredump_write(ws->iocookie, UIO_SYSSPACE, &shstrtab,
- sizeof(shstrtab.shdr) + sizeof(shstrtab.shstrtab));
+ sizeof(shstrtab.shdr) + sizeof(shstrtab.shstrtab), 0);
if (error)
return error;
}
int
coredump_walk_elf(vaddr_t start, vaddr_t realend, vaddr_t end, vm_prot_t prot,
- int nsegment, void *cookie)
+ int isvnode, int nsegment, void *cookie)
{
struct writesegs_state *ws = cookie;
Elf_Phdr phdr;
phdr.p_flags |= PF_W;
if (prot & PROT_EXEC)
phdr.p_flags |= PF_X;
+ if (isvnode)
+ phdr.p_flags |= PF_ISVNODE;
phdr.p_align = PAGE_SIZE;
ws->secoff += phdr.p_filesz;
nhdr.type = NT_OPENBSD_AUXV;
error = coredump_write(iocookie, UIO_SYSSPACE,
- &nhdr, sizeof(nhdr));
+ &nhdr, sizeof(nhdr), 0);
if (error)
return (error);
error = coredump_write(iocookie, UIO_SYSSPACE,
- "OpenBSD", elfround(nhdr.namesz));
+ "OpenBSD", elfround(nhdr.namesz), 0);
if (error)
return (error);
error = coredump_write(iocookie, UIO_USERSPACE,
- (caddr_t)pr->ps_auxinfo, nhdr.descsz);
+ (caddr_t)pr->ps_auxinfo, nhdr.descsz, 0);
if (error)
return (error);
}
{
int error;
- error = coredump_write(cookie, UIO_SYSSPACE, nhdr, sizeof(*nhdr));
+ error = coredump_write(cookie, UIO_SYSSPACE, nhdr, sizeof(*nhdr), 0);
if (error)
return error;
error = coredump_write(cookie, UIO_SYSSPACE, name,
- elfround(nhdr->namesz));
+ elfround(nhdr->namesz), 0);
if (error)
return error;
- return coredump_write(cookie, UIO_SYSSPACE, data, nhdr->descsz);
+ return coredump_write(cookie, UIO_SYSSPACE, data, nhdr->descsz, 0);
}
#endif /* !SMALL_KERNEL */
-/* $OpenBSD: kern_sig.c,v 1.320 2023/10/06 08:58:13 claudio Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.321 2024/01/17 22:22:25 kurt Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
#ifndef SMALL_KERNEL
int
-coredump_write(void *cookie, enum uio_seg segflg, const void *data, size_t len)
+coredump_write(void *cookie, enum uio_seg segflg, const void *data, size_t len,
+ int isvnode)
{
struct coredump_iostate *io = cookie;
off_t coffset = 0;
(caddr_t)data + coffset, chunk,
io->io_offset + coffset, segflg,
IO_UNIT, io->io_cred, NULL, io->io_proc);
- if (error) {
+ if (error && (error != EFAULT || !isvnode)) {
struct process *pr = io->io_proc->p_p;
if (error == ENOSPC)
-/* $OpenBSD: core.h,v 1.8 2022/02/22 17:14:13 deraadt Exp $ */
+/* $OpenBSD: core.h,v 1.9 2024/01/17 22:22:25 kurt Exp $ */
/* $NetBSD: core.h,v 1.4 1994/10/29 08:20:14 cgd Exp $ */
/*
};
#else
-int coredump_write(void *, enum uio_seg, const void *, size_t);
+int coredump_write(void *, enum uio_seg, const void *, size_t, int);
void coredump_unmap(void *, vaddr_t, vaddr_t);
#endif
-/* $OpenBSD: exec_elf.h,v 1.102 2023/12/08 13:58:41 deraadt Exp $ */
+/* $OpenBSD: exec_elf.h,v 1.103 2024/01/17 22:22:25 kurt Exp $ */
/*
* Copyright (c) 1995, 1996 Erik Theisen. All rights reserved.
*
#define PF_OPENBSD_MUTABLE 0x08000000 /* Mutable */
+#ifdef _KERNEL
+#define PF_ISVNODE 0x00100000 /* For coredump segments */
+#endif
+
/* Dynamic structure */
typedef struct {
Elf32_Sword d_tag; /* controls meaning of d_val */
-/* $OpenBSD: uvm_extern.h,v 1.171 2023/08/18 09:18:52 claudio Exp $ */
+/* $OpenBSD: uvm_extern.h,v 1.172 2024/01/17 22:22:25 kurt Exp $ */
/* $NetBSD: uvm_extern.h,v 1.57 2001/03/09 01:02:12 chs Exp $ */
/*
void uvm_swap_init(void);
typedef int uvm_coredump_setup_cb(int _nsegment, void *_cookie);
typedef int uvm_coredump_walk_cb(vaddr_t _start, vaddr_t _realend,
- vaddr_t _end, vm_prot_t _prot, int _nsegment,
- void *_cookie);
+ vaddr_t _end, vm_prot_t _prot, int _isvnode,
+ int _nsegment, void *_cookie);
int uvm_coredump_walkmap(struct proc *_p,
uvm_coredump_setup_cb *_setup,
uvm_coredump_walk_cb *_walk, void *_cookie);
-/* $OpenBSD: uvm_unix.c,v 1.72 2023/01/13 23:02:44 kettenis Exp $ */
+/* $OpenBSD: uvm_unix.c,v 1.73 2024/01/17 22:22:25 kurt Exp $ */
/* $NetBSD: uvm_unix.c,v 1.18 2000/09/13 15:00:25 thorpej Exp $ */
/*
end = pos + (i << PAGE_SHIFT);
if (start != end) {
error = (*walk)(start, realend, end, prot,
- nsegment, cookie);
+ 0, nsegment, cookie);
if (error)
return error;
nsegment++;
if (!absent)
realend = entry_end;
- error = (*walk)(start, realend, entry_end, prot, nsegment, cookie);
+ error = (*walk)(start, realend, entry_end, prot, 0, nsegment, cookie);
*nsegmentp = nsegment + 1;
return error;
}
/* do nothing callback for uvm_coredump_walk_amap() */
static int
noop(vaddr_t start, vaddr_t realend, vaddr_t end, vm_prot_t prot,
- int nsegment, void *cookie)
+ int isvnode, int nsegment, void *cookie)
{
return 0;
}
struct vm_map_entry *entry;
vaddr_t end;
int refed_amaps = 0;
- int nsegment, error;
+ int nsegment, error, isvnode;
/*
* Walk the map once to count the segments. If an amap is
if (end > VM_MAXUSER_ADDRESS)
end = VM_MAXUSER_ADDRESS;
+ isvnode = (entry->object.uvm_obj != NULL &&
+ UVM_OBJ_IS_VNODE(entry->object.uvm_obj));
error = (*walk)(entry->start, end, end, entry->protection,
- nsegment, cookie);
+ isvnode, nsegment, cookie);
if (error)
break;
nsegment++;