From d5ee67c8efc01e3ba4716c001a1db11220dbf9cc Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 16 Mar 2021 16:32:22 +0000 Subject: [PATCH] handle theoretical case of sigfillsz not being pow2-sized on some architecture. from miod --- sys/kern/kern_exec.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 1a693806777..674c62a53ed 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.222 2021/03/12 10:13:28 mpi Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.223 2021/03/16 16:32:22 deraadt Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -834,7 +834,7 @@ exec_sigcode_map(struct process *pr, struct emul *e) if (e->e_sigobject == NULL) { extern int sigfillsiz; extern u_char sigfill[]; - size_t off; + size_t off, left; vaddr_t va; int r; @@ -848,8 +848,12 @@ exec_sigcode_map(struct process *pr, struct emul *e) return (ENOMEM); } - for (off = 0; off < round_page(sz); off += sigfillsiz) - memcpy((caddr_t)va + off, sigfill, sigfillsiz); + for (off = 0, left = round_page(sz); left != 0; + off += sigfillsiz) { + size_t chunk = ulmin(left, sigfillsiz); + memcpy((caddr_t)va + off, sigfill, chunk); + left -= chunk; + } memcpy((caddr_t)va, e->e_sigcode, sz); uvm_unmap(kernel_map, va, va + round_page(sz)); } -- 2.20.1