diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-09-28 20:33:00 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-09-28 20:33:00 +0000 |
commit | 00f6f0acf40e4249ba69705f6e2692fa920d3430 (patch) | |
tree | f6821acdb21209e176a85c618f341cad38b1a3f9 /sys/kern | |
parent | e46bfca6710ab4a9d3a0804a563e9edf01f4b965 (diff) |
Track size of an opaque allocation to pass to free() later
ok guenther tedu
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/exec_elf.c | 7 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 12 |
2 files changed, 10 insertions, 9 deletions
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index bc827f45011..4c0c5ee2079 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.116 2015/04/30 11:15:28 jsg Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.117 2015/09/28 20:32:59 deraadt Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -759,6 +759,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) ap->arg_interp = exe_base; epp->ep_emul_arg = ap; + epp->ep_emul_argsize = sizeof *ap; epp->ep_interp_pos = pos; } @@ -798,7 +799,7 @@ ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp) if (interp && (error = ELFNAME(load_file)(p, interp, epp, ap, &pos)) != 0) { - free(ap, M_TEMP, 0); + free(ap, M_TEMP, epp->ep_emul_argsize); pool_put(&namei_pool, interp); kill_vmcmds(&epp->ep_vmcmds); return (error); @@ -849,7 +850,7 @@ ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp) error = copyout(ai, epp->ep_emul_argp, sizeof ai); } - free(ap, M_TEMP, 0); + free(ap, M_TEMP, epp->ep_emul_argsize); if (interp) pool_put(&namei_pool, interp); return (error); diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 76cf228f33e..ee5bb5dafdc 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.163 2015/07/22 05:31:33 deraadt Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.164 2015/09/28 20:32:59 deraadt Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -686,7 +686,7 @@ sys_execve(struct proc *p, void *v, register_t *retval) if (pr->ps_flags & PS_TRACED) psignal(p, SIGTRAP); - free(pack.ep_hdr, M_EXEC, 0); + free(pack.ep_hdr, M_EXEC, pack.ep_hdrlen); /* * Call emulation specific exec hook. This can setup per-process @@ -748,14 +748,14 @@ bad: if (pack.ep_interp != NULL) pool_put(&namei_pool, pack.ep_interp); if (pack.ep_emul_arg != NULL) - free(pack.ep_emul_arg, M_TEMP, 0); + free(pack.ep_emul_arg, M_TEMP, pack.ep_emul_argsize); /* close and put the exec'd file */ vn_close(pack.ep_vp, FREAD, cred, p); pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf); km_free(argp, NCARGS, &kv_exec, &kp_pageable); freehdr: - free(pack.ep_hdr, M_EXEC, 0); + free(pack.ep_hdr, M_EXEC, pack.ep_hdrlen); #if NSYSTRACE > 0 clrflag: #endif @@ -778,13 +778,13 @@ exec_abort: if (pack.ep_interp != NULL) pool_put(&namei_pool, pack.ep_interp); if (pack.ep_emul_arg != NULL) - free(pack.ep_emul_arg, M_TEMP, 0); + free(pack.ep_emul_arg, M_TEMP, pack.ep_emul_argsize); pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf); vn_close(pack.ep_vp, FREAD, cred, p); km_free(argp, NCARGS, &kv_exec, &kp_pageable); free_pack_abort: - free(pack.ep_hdr, M_EXEC, 0); + free(pack.ep_hdr, M_EXEC, pack.ep_hdrlen); if (pathbuf != NULL) pool_put(&namei_pool, pathbuf); exit1(p, W_EXITCODE(0, SIGABRT), EXIT_NORMAL); |