Sun Nov 11 10:55:58 2018 UTC ()
Fix stack info leak. There are 2x4 bytes of padding in struct ps_strings.

[  223.896199] kleak: Possible leak in copyout: [len=32, leaked=8]
[  223.906430] #0 0xffffffff80224d0a in kleak_note <netbsd>
[  223.906430] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[  223.918363] #2 0xffffffff80b1e26c in copyoutpsstrs <netbsd>
[  223.926560] #3 0xffffffff80b1e331 in copyoutargs <netbsd>
[  223.936216] #4 0xffffffff80b21768 in execve_runproc <netbsd>
[  223.946225] #5 0xffffffff80b21cc9 in execve1 <netbsd>
[  223.946225] #6 0xffffffff8025a89c in sy_call <netbsd>
[  223.956225] #7 0xffffffff8025aace in sy_invoke <netbsd>
[  223.966232] #8 0xffffffff8025ab54 in syscall <netbsd>


(maxv)
diff -r1.461 -r1.462 src/sys/kern/kern_exec.c

cvs diff -r1.461 -r1.462 src/sys/kern/kern_exec.c (expand / switch to unified diff)

--- src/sys/kern/kern_exec.c 2018/09/03 16:29:35 1.461
+++ src/sys/kern/kern_exec.c 2018/11/11 10:55:58 1.462
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_exec.c,v 1.461 2018/09/03 16:29:35 riastradh Exp $ */ 1/* $NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -49,27 +49,27 @@ @@ -49,27 +49,27 @@
49 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 49 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
58 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.461 2018/09/03 16:29:35 riastradh Exp $"); 62__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $");
63 63
64#include "opt_exec.h" 64#include "opt_exec.h"
65#include "opt_execfmt.h" 65#include "opt_execfmt.h"
66#include "opt_ktrace.h" 66#include "opt_ktrace.h"
67#include "opt_modular.h" 67#include "opt_modular.h"
68#include "opt_syscall_debug.h" 68#include "opt_syscall_debug.h"
69#include "veriexec.h" 69#include "veriexec.h"
70#include "opt_pax.h" 70#include "opt_pax.h"
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/systm.h> 73#include <sys/systm.h>
74#include <sys/filedesc.h> 74#include <sys/filedesc.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
@@ -1414,26 +1414,28 @@ calcstack(struct execve_data * restrict  @@ -1414,26 +1414,28 @@ calcstack(struct execve_data * restrict
1414 1414
1415 /* make the stack "safely" aligned */ 1415 /* make the stack "safely" aligned */
1416 return STACK_LEN_ALIGN(stacklen, STACK_ALIGNBYTES); 1416 return STACK_LEN_ALIGN(stacklen, STACK_ALIGNBYTES);
1417} 1417}
1418 1418
1419static int 1419static int
1420copyoutargs(struct execve_data * restrict data, struct lwp *l, 1420copyoutargs(struct execve_data * restrict data, struct lwp *l,
1421 char * const newstack) 1421 char * const newstack)
1422{ 1422{
1423 struct exec_package * const epp = &data->ed_pack; 1423 struct exec_package * const epp = &data->ed_pack;
1424 struct proc *p = l->l_proc; 1424 struct proc *p = l->l_proc;
1425 int error; 1425 int error;
1426 1426
 1427 memset(&data->ed_arginfo, 0, sizeof(data->ed_arginfo));
 1428
1427 /* remember information about the process */ 1429 /* remember information about the process */
1428 data->ed_arginfo.ps_nargvstr = data->ed_argc; 1430 data->ed_arginfo.ps_nargvstr = data->ed_argc;
1429 data->ed_arginfo.ps_nenvstr = data->ed_envc; 1431 data->ed_arginfo.ps_nenvstr = data->ed_envc;
1430 1432
1431 /* 1433 /*
1432 * Allocate the stack address passed to the newly execve()'ed process. 1434 * Allocate the stack address passed to the newly execve()'ed process.
1433 * 1435 *
1434 * The new stack address will be set to the SP (stack pointer) register 1436 * The new stack address will be set to the SP (stack pointer) register
1435 * in setregs(). 1437 * in setregs().
1436 */ 1438 */
1437 1439
1438 char *newargs = STACK_ALLOC( 1440 char *newargs = STACK_ALLOC(
1439 STACK_SHRINK(newstack, data->ed_argslen), data->ed_argslen); 1441 STACK_SHRINK(newstack, data->ed_argslen), data->ed_argslen);