Fri Aug 21 18:00:36 2009 UTC ()
Add support for ELF_MD_PROBE_FUNC and ELF_COREDUMP_SETUP so that more
exact checks can be made before committing to execute or better info
about what's being dumped.


(matt)
diff -r1.32 -r1.32.16.1 src/sys/kern/core_elf32.c
diff -r1.136 -r1.136.8.1 src/sys/kern/exec_elf32.c

cvs diff -r1.32 -r1.32.16.1 src/sys/kern/core_elf32.c (expand / switch to unified diff)

--- src/sys/kern/core_elf32.c 2008/04/24 15:35:28 1.32
+++ src/sys/kern/core_elf32.c 2009/08/21 18:00:36 1.32.16.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: core_elf32.c,v 1.32 2008/04/24 15:35:28 ad Exp $ */ 1/* $NetBSD: core_elf32.c,v 1.32.16.1 2009/08/21 18:00:36 matt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38/* 38/*
39 * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format. 39 * core_elf32.c/core_elf64.c: Support for the Elf32/Elf64 core file format.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.32 2008/04/24 15:35:28 ad Exp $"); 43__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.32.16.1 2009/08/21 18:00:36 matt Exp $");
44 44
45/* If not included by core_elf64.c, ELFSIZE won't be defined. */ 45/* If not included by core_elf64.c, ELFSIZE won't be defined. */
46#ifndef ELFSIZE 46#ifndef ELFSIZE
47#define ELFSIZE 32 47#define ELFSIZE 32
48#endif 48#endif
49 49
50#include <sys/param.h> 50#include <sys/param.h>
51#include <sys/systm.h> 51#include <sys/systm.h>
52#include <sys/proc.h> 52#include <sys/proc.h>
53#include <sys/vnode.h> 53#include <sys/vnode.h>
54#include <sys/exec.h> 54#include <sys/exec.h>
55#include <sys/exec_elf.h> 55#include <sys/exec_elf.h>
56#include <sys/ptrace.h> 56#include <sys/ptrace.h>
@@ -147,26 +147,30 @@ ELFNAMEEND(coredump)(struct lwp *l, void @@ -147,26 +147,30 @@ ELFNAMEEND(coredump)(struct lwp *l, void
147 ehdr.e_machine = ELFDEFNNAME(MACHDEP_ID); 147 ehdr.e_machine = ELFDEFNNAME(MACHDEP_ID);
148 ehdr.e_version = EV_CURRENT; 148 ehdr.e_version = EV_CURRENT;
149 ehdr.e_entry = 0; 149 ehdr.e_entry = 0;
150 ehdr.e_phoff = sizeof(ehdr); 150 ehdr.e_phoff = sizeof(ehdr);
151 ehdr.e_shoff = 0; 151 ehdr.e_shoff = 0;
152 ehdr.e_flags = 0; 152 ehdr.e_flags = 0;
153 ehdr.e_ehsize = sizeof(ehdr); 153 ehdr.e_ehsize = sizeof(ehdr);
154 ehdr.e_phentsize = sizeof(Elf_Phdr); 154 ehdr.e_phentsize = sizeof(Elf_Phdr);
155 ehdr.e_phnum = cs.npsections; 155 ehdr.e_phnum = cs.npsections;
156 ehdr.e_shentsize = 0; 156 ehdr.e_shentsize = 0;
157 ehdr.e_shnum = 0; 157 ehdr.e_shnum = 0;
158 ehdr.e_shstrndx = 0; 158 ehdr.e_shstrndx = 0;
159 159
 160#ifdef ELF_MD_COREDUMP_SETUP
 161 ELF_MD_COREDUMP_SETUP(l, &ehdr);
 162#endif
 163
160 /* Write out the ELF header. */ 164 /* Write out the ELF header. */
161 error = coredump_write(cookie, UIO_SYSSPACE, &ehdr, sizeof(ehdr)); 165 error = coredump_write(cookie, UIO_SYSSPACE, &ehdr, sizeof(ehdr));
162 if (error) 166 if (error)
163 goto out; 167 goto out;
164 168
165 offset = sizeof(ehdr); 169 offset = sizeof(ehdr);
166 170
167 notestart = offset + sizeof(phdr) * cs.npsections; 171 notestart = offset + sizeof(phdr) * cs.npsections;
168 secstart = notestart + notesize; 172 secstart = notestart + notesize;
169 173
170 psections = malloc(cs.npsections * sizeof(Elf_Phdr), 174 psections = malloc(cs.npsections * sizeof(Elf_Phdr),
171 M_TEMP, M_WAITOK|M_ZERO); 175 M_TEMP, M_WAITOK|M_ZERO);
172 176

cvs diff -r1.136 -r1.136.8.1 src/sys/kern/exec_elf32.c (expand / switch to unified diff)

--- src/sys/kern/exec_elf32.c 2008/09/15 18:12:56 1.136
+++ src/sys/kern/exec_elf32.c 2009/08/21 18:00:36 1.136.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: exec_elf32.c,v 1.136 2008/09/15 18:12:56 rmind Exp $ */ 1/* $NetBSD: exec_elf32.c,v 1.136.8.1 2009/08/21 18:00:36 matt Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -47,27 +47,27 @@ @@ -47,27 +47,27 @@
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */ 57 */
58 58
59#include <sys/cdefs.h> 59#include <sys/cdefs.h>
60__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.136 2008/09/15 18:12:56 rmind Exp $"); 60__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.136.8.1 2009/08/21 18:00:36 matt Exp $");
61 61
62/* If not included by exec_elf64.c, ELFSIZE won't be defined. */ 62/* If not included by exec_elf64.c, ELFSIZE won't be defined. */
63#ifndef ELFSIZE 63#ifndef ELFSIZE
64#define ELFSIZE 32 64#define ELFSIZE 32
65#endif 65#endif
66 66
67#ifdef _KERNEL_OPT 67#ifdef _KERNEL_OPT
68#include "opt_pax.h" 68#include "opt_pax.h"
69#endif /* _KERNEL_OPT */ 69#endif /* _KERNEL_OPT */
70 70
71#include <sys/param.h> 71#include <sys/param.h>
72#include <sys/proc.h> 72#include <sys/proc.h>
73#include <sys/malloc.h> 73#include <sys/malloc.h>
@@ -903,18 +903,22 @@ next: @@ -903,18 +903,22 @@ next:
903out: 903out:
904 kmem_free(ph, phsize); 904 kmem_free(ph, phsize);
905 return error; 905 return error;
906} 906}
907 907
908int 908int
909netbsd_elf_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp, 909netbsd_elf_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp,
910 vaddr_t *pos) 910 vaddr_t *pos)
911{ 911{
912 int error; 912 int error;
913 913
914 if ((error = netbsd_elf_signature(l, epp, eh)) != 0) 914 if ((error = netbsd_elf_signature(l, epp, eh)) != 0)
915 return error; 915 return error;
 916#ifdef ELF_MD_PROBE_FUNC
 917 if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0)
 918 return error;
 919#endif
916#ifdef ELF_INTERP_NON_RELOCATABLE 920#ifdef ELF_INTERP_NON_RELOCATABLE
917 *pos = ELF_LINK_ADDR; 921 *pos = ELF_LINK_ADDR;
918#endif 922#endif
919 return 0; 923 return 0;
920} 924}