summaryrefslogtreecommitdiff
path: root/sys/kern/exec_elf.c
diff options
context:
space:
mode:
authormaxv <maxv@NetBSD.org>2014-07-08 17:16:25 +0000
committermaxv <maxv@NetBSD.org>2014-07-08 17:16:25 +0000
commite8c7d251a2a90fa8dafa452f4a9fa0ffbfb69c48 (patch)
treee06c506cf5c0e98577555197e6a17eb2ce42e9a4 /sys/kern/exec_elf.c
parent12b3bda1fb194e3b92a4923232e3922c022025ef (diff)
Define ELF_MAXNOTESIZE, ELF_MAXSHNUM and ELF_MAXPHNUM in <sys/exec_elf.h>, so
that it can be used externally.
Diffstat (limited to 'sys/kern/exec_elf.c')
-rw-r--r--sys/kern/exec_elf.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index dbdb3724657..78e9b53a53c 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.68 2014/07/06 07:41:41 maxv Exp $ */
+/* $NetBSD: exec_elf.c,v 1.69 2014/07/08 17:16:25 maxv Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.68 2014/07/06 07:41:41 maxv Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69 2014/07/08 17:16:25 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -115,13 +115,6 @@ static void elf_free_emul_arg(void *);
#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
#define ELF_TRUNC(a, b) ((a) & ~((b) - 1))
-/*
- * Arbitrary limits to avoid DoS for excessive memory allocation.
- */
-#define MAXPHNUM 128
-#define MAXSHNUM 32768
-#define MAXNOTESIZE 1024
-
static void
elf_placedynexec(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh,
Elf_Phdr *ph)
@@ -304,7 +297,7 @@ elf_check_header(Elf_Ehdr *eh)
if (ELF_EHDR_FLAGS_OK(eh) == 0)
return ENOEXEC;
- if (eh->e_shnum > MAXSHNUM || eh->e_phnum > MAXPHNUM)
+ if (eh->e_shnum > ELF_MAXSHNUM || eh->e_phnum > ELF_MAXPHNUM)
return ENOEXEC;
return 0;
@@ -882,7 +875,7 @@ netbsd_elf_signature(struct lwp *l, struct exec_package *epp,
#endif
epp->ep_pax_flags = 0;
- if (eh->e_shnum > MAXSHNUM || eh->e_shnum == 0)
+ if (eh->e_shnum > ELF_MAXSHNUM || eh->e_shnum == 0)
return ENOEXEC;
shsize = eh->e_shnum * sizeof(Elf_Shdr);
@@ -891,12 +884,12 @@ netbsd_elf_signature(struct lwp *l, struct exec_package *epp,
if (error)
goto out;
- np = kmem_alloc(MAXNOTESIZE, KM_SLEEP);
+ np = kmem_alloc(ELF_MAXNOTESIZE, KM_SLEEP);
for (i = 0; i < eh->e_shnum; i++) {
Elf_Shdr *shp = &sh[i];
if (shp->sh_type != SHT_NOTE ||
- shp->sh_size > MAXNOTESIZE ||
+ shp->sh_size > ELF_MAXNOTESIZE ||
shp->sh_size < sizeof(Elf_Nhdr) + ELF_NOTE_NETBSD_NAMESZ)
continue;
@@ -1035,7 +1028,7 @@ bad:
break;
}
}
- kmem_free(np, MAXNOTESIZE);
+ kmem_free(np, ELF_MAXNOTESIZE);
error = isnetbsd ? 0 : ENOEXEC;
out: