limit malloc so that corrupted executables don't allocate a lot of memory.

This commit is contained in:
christos 2003-11-05 04:03:21 +00:00
parent 81468ece49
commit 293ab5b508
3 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_exec_coff.c,v 1.8 2003/08/08 18:57:03 christos Exp $ */
/* $NetBSD: ibcs2_exec_coff.c,v 1.9 2003/11/05 04:03:21 christos Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.8 2003/08/08 18:57:03 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.9 2003/11/05 04:03:21 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -448,11 +448,9 @@ exec_ibcs2_coff_prep_zmagic(p, epp, fp, ap)
char *buf, *bufp;
int len = sh.s_size, path_index, entry_len;
#if 0
if (len > COFF_SHLIBSEC_MAXSIZE) {
if (len > 64 * 1024)
return ENOEXEC;
}
#endif
buf = (char *) malloc(len, M_TEMP, M_WAITOK);
if (buf == NULL)
return ENOEXEC;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_exec_elf32.c,v 1.7 2003/10/31 14:04:35 drochner Exp $ */
/* $NetBSD: ibcs2_exec_elf32.c,v 1.8 2003/11/05 04:03:21 christos Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_elf32.c,v 1.7 2003/10/31 14:04:35 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_elf32.c,v 1.8 2003/11/05 04:03:21 christos Exp $");
#define ELFSIZE 32
@ -86,6 +86,9 @@ ibcs2_elf32_signature(p, epp, eh)
Elf32_Shdr *sh;
int error;
if (shsize > 64 * 1024)
return ENOEXEC;
sh = (Elf32_Shdr *)malloc(shsize, M_TEMP, M_WAITOK);
if ((error = exec_read_from(p, epp->ep_vp, eh->e_shoff, sh,

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_exec_xout.c,v 1.6 2003/08/08 18:57:03 christos Exp $ */
/* $NetBSD: ibcs2_exec_xout.c,v 1.7 2003/11/05 04:03:21 christos Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_xout.c,v 1.6 2003/08/08 18:57:03 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_xout.c,v 1.7 2003/11/05 04:03:21 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -115,6 +115,9 @@ exec_ibcs2_xout_prep_nmagic(p, epp, xp, xep)
struct xseg *xs;
size_t resid;
if (xep->xe_segsize > 16 * sizeof(*xs))
return ENOEXEC;
/* read in segment table */
xs = (struct xseg *)malloc(xep->xe_segsize, M_TEMP, M_WAITOK);
error = vn_rdwr(UIO_READ, epp->ep_vp, (caddr_t)xs,