Tue Oct 13 00:24:35 2015 UTC ()
In execve_runproc(), update the p_waited entry for the process being
moved to SSTOP state, not for its parent.  (It is correct to update
the parent's p_nstopchild count.)  If the value is not already zero,
it could prevent its parent from waiting for the process.

Fixes PR kern/50298

Pullups will be requested for:

       NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2


(pgoyette)
diff -r1.418 -r1.419 src/sys/kern/kern_exec.c

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

--- src/sys/kern/kern_exec.c 2015/10/02 16:54:15 1.418
+++ src/sys/kern/kern_exec.c 2015/10/13 00:24:35 1.419
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_exec.c,v 1.418 2015/10/02 16:54:15 christos Exp $ */ 1/* $NetBSD: kern_exec.c,v 1.419 2015/10/13 00:24:35 pgoyette 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.418 2015/10/02 16:54:15 christos Exp $"); 62__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.419 2015/10/13 00:24:35 pgoyette 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>
@@ -1272,27 +1272,27 @@ execve_runproc(struct lwp *l, struct exe @@ -1272,27 +1272,27 @@ execve_runproc(struct lwp *l, struct exe
1272 ksiginfo_t ksi; 1272 ksiginfo_t ksi;
1273 1273
1274 KSI_INIT_EMPTY(&ksi); 1274 KSI_INIT_EMPTY(&ksi);
1275 ksi.ksi_signo = SIGTRAP; 1275 ksi.ksi_signo = SIGTRAP;
1276 ksi.ksi_lid = l->l_lid; 1276 ksi.ksi_lid = l->l_lid;
1277 kpsignal(p, &ksi, NULL); 1277 kpsignal(p, &ksi, NULL);
1278 } 1278 }
1279 1279
1280 if (p->p_sflag & PS_STOPEXEC) { 1280 if (p->p_sflag & PS_STOPEXEC) {
1281 ksiginfoq_t kq; 1281 ksiginfoq_t kq;
1282 1282
1283 KERNEL_UNLOCK_ALL(l, &l->l_biglocks); 1283 KERNEL_UNLOCK_ALL(l, &l->l_biglocks);
1284 p->p_pptr->p_nstopchild++; 1284 p->p_pptr->p_nstopchild++;
1285 p->p_pptr->p_waited = 0; 1285 p->p_waited = 0;
1286 mutex_enter(p->p_lock); 1286 mutex_enter(p->p_lock);
1287 ksiginfo_queue_init(&kq); 1287 ksiginfo_queue_init(&kq);
1288 sigclearall(p, &contsigmask, &kq); 1288 sigclearall(p, &contsigmask, &kq);
1289 lwp_lock(l); 1289 lwp_lock(l);
1290 l->l_stat = LSSTOP; 1290 l->l_stat = LSSTOP;
1291 p->p_stat = SSTOP; 1291 p->p_stat = SSTOP;
1292 p->p_nrlwps--; 1292 p->p_nrlwps--;
1293 lwp_unlock(l); 1293 lwp_unlock(l);
1294 mutex_exit(p->p_lock); 1294 mutex_exit(p->p_lock);
1295 mutex_exit(proc_lock); 1295 mutex_exit(proc_lock);
1296 lwp_lock(l); 1296 lwp_lock(l);
1297 mi_switch(l); 1297 mi_switch(l);
1298 ksiginfo_queue_drain(&kq); 1298 ksiginfo_queue_drain(&kq);