Module Name: src Committed By: maxv Date: Tue Jul 8 17:16:25 UTC 2014
Modified Files: src/sys/kern: exec_elf.c src/sys/sys: exec_elf.h Log Message: Define ELF_MAXNOTESIZE, ELF_MAXSHNUM and ELF_MAXPHNUM in <sys/exec_elf.h>, so that it can be used externally. To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sys/kern/exec_elf.c cvs rdiff -u -r1.140 -r1.141 src/sys/sys/exec_elf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/exec_elf.c diff -u src/sys/kern/exec_elf.c:1.68 src/sys/kern/exec_elf.c:1.69 --- src/sys/kern/exec_elf.c:1.68 Sun Jul 6 07:41:41 2014 +++ src/sys/kern/exec_elf.c Tue Jul 8 17:16:25 2014 @@ -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, stru #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, stru 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: Index: src/sys/sys/exec_elf.h diff -u src/sys/sys/exec_elf.h:1.140 src/sys/sys/exec_elf.h:1.141 --- src/sys/sys/exec_elf.h:1.140 Sun Mar 9 17:59:19 2014 +++ src/sys/sys/exec_elf.h Tue Jul 8 17:16:25 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.h,v 1.140 2014/03/09 17:59:19 christos Exp $ */ +/* $NetBSD: exec_elf.h,v 1.141 2014/07/08 17:16:25 maxv Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -1225,6 +1225,13 @@ typedef Elf32_Versym Elf64_Versym; #ifdef _KERNEL +/* + * Arbitrary limits to avoid DoS for excessive memory allocation. + */ +#define ELF_MAXPHNUM 128 +#define ELF_MAXSHNUM 32768 +#define ELF_MAXNOTESIZE 1024 + #define ELF_AUX_ENTRIES 15 /* Max size of aux array passed to loader */ #define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */ #define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */