Don't release proc_lock until we're done looking at things that are protected by the lock, particularly p_stat and p_waited. Found by Robert Elz. XXX Pullup to NetBSD-7, -6, -6-0, and -6-1diff -r1.18 -r1.19 src/sys/compat/linux/arch/arm/linux_ptrace.c
(pgoyette)
--- src/sys/compat/linux/arch/arm/linux_ptrace.c 2014/11/09 17:48:07 1.18
+++ src/sys/compat/linux/arch/arm/linux_ptrace.c 2015/10/13 08:24:35 1.19
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_ptrace.c,v 1.18 2014/11/09 17:48:07 maxv Exp $ */ | 1 | /* $NetBSD: linux_ptrace.c,v 1.19 2015/10/13 08:24:35 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Matthias Scheler. | 8 | * by Matthias Scheler. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.18 2014/11/09 17:48:07 maxv Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.19 2015/10/13 08:24:35 pgoyette Exp $"); | |
35 | 35 | |||
36 | #include <sys/param.h> | 36 | #include <sys/param.h> | |
37 | #include <sys/mount.h> | 37 | #include <sys/mount.h> | |
38 | #include <sys/proc.h> | 38 | #include <sys/proc.h> | |
39 | #include <sys/ptrace.h> | 39 | #include <sys/ptrace.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/syscallargs.h> | 41 | #include <sys/syscallargs.h> | |
42 | #include <uvm/uvm_extern.h> | 42 | #include <uvm/uvm_extern.h> | |
43 | 43 | |||
44 | #include <machine/reg.h> | 44 | #include <machine/reg.h> | |
45 | #include <machine/pcb.h> | 45 | #include <machine/pcb.h> | |
46 | 46 | |||
47 | #include <compat/linux/common/linux_types.h> | 47 | #include <compat/linux/common/linux_types.h> | |
@@ -130,49 +130,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | @@ -130,49 +130,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | |||
130 | default: | 130 | default: | |
131 | error = EIO; | 131 | error = EIO; | |
132 | goto out; | 132 | goto out; | |
133 | } | 133 | } | |
134 | 134 | |||
135 | /* Find the process we are supposed to be operating on. */ | 135 | /* Find the process we are supposed to be operating on. */ | |
136 | mutex_enter(proc_lock); | 136 | mutex_enter(proc_lock); | |
137 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | 137 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | |
138 | mutex_exit(proc_lock); | 138 | mutex_exit(proc_lock); | |
139 | error = ESRCH; | 139 | error = ESRCH; | |
140 | goto out; | 140 | goto out; | |
141 | } | 141 | } | |
142 | mutex_enter(t->p_lock); | 142 | mutex_enter(t->p_lock); | |
143 | mutex_exit(proc_lock); | |||
144 | 143 | |||
145 | /* | 144 | /* | |
146 | * You cannot do what you want to the process if: | 145 | * You cannot do what you want to the process if: | |
147 | * 1. It is not being traced at all, | 146 | * 1. It is not being traced at all, | |
148 | */ | 147 | */ | |
149 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | 148 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | |
150 | mutex_exit(t->p_lock); | 149 | mutex_exit(t->p_lock); | |
150 | mutex_exit(proc_lock); | |||
151 | error = EPERM; | 151 | error = EPERM; | |
152 | goto out; | 152 | goto out; | |
153 | } | 153 | } | |
154 | /* | 154 | /* | |
155 | * 2. It is being traced by procfs (which has different signal | 155 | * 2. It is being traced by procfs (which has different signal | |
156 | * delivery semantics), | 156 | * delivery semantics), | |
157 | * 3. It is not being traced by _you_, or | 157 | * 3. It is not being traced by _you_, or | |
158 | * 4. It is not currently stopped. | 158 | * 4. It is not currently stopped. | |
159 | */ | 159 | */ | |
160 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | 160 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | |
161 | t->p_stat != SSTOP || !t->p_waited) { | 161 | t->p_stat != SSTOP || !t->p_waited) { | |
162 | mutex_exit(t->p_lock); | 162 | mutex_exit(t->p_lock); | |
163 | mutex_exit(proc_lock); | |||
163 | error = EBUSY; | 164 | error = EBUSY; | |
164 | goto out; | 165 | goto out; | |
165 | } | 166 | } | |
167 | mutex_exit(proc_lock); | |||
166 | /* XXX: ptrace needs revamp for multi-threading support. */ | 168 | /* XXX: ptrace needs revamp for multi-threading support. */ | |
167 | if (t->p_nlwps > 1) { | 169 | if (t->p_nlwps > 1) { | |
168 | mutex_exit(t->p_lock); | 170 | mutex_exit(t->p_lock); | |
169 | error = ENOSYS; | 171 | error = ENOSYS; | |
170 | goto out; | 172 | goto out; | |
171 | } | 173 | } | |
172 | lt = LIST_FIRST(&t->p_lwps); | 174 | lt = LIST_FIRST(&t->p_lwps); | |
173 | *retval = 0; | 175 | *retval = 0; | |
174 | 176 | |||
175 | switch (request) { | 177 | switch (request) { | |
176 | case LINUX_PTRACE_GETREGS: | 178 | case LINUX_PTRACE_GETREGS: | |
177 | error = process_read_regs(lt, regs); | 179 | error = process_read_regs(lt, regs); | |
178 | mutex_exit(t->p_lock); | 180 | mutex_exit(t->p_lock); |
--- src/sys/compat/linux/arch/i386/linux_ptrace.c 2014/11/09 17:48:07 1.30
+++ src/sys/compat/linux/arch/i386/linux_ptrace.c 2015/10/13 08:24:35 1.31
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_ptrace.c,v 1.30 2014/11/09 17:48:07 maxv Exp $ */ | 1 | /* $NetBSD: linux_ptrace.c,v 1.31 2015/10/13 08:24:35 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Matthias Scheler. | 8 | * by Matthias Scheler. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.30 2014/11/09 17:48:07 maxv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.31 2015/10/13 08:24:35 pgoyette Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/mount.h> | 36 | #include <sys/mount.h> | |
37 | #include <sys/proc.h> | 37 | #include <sys/proc.h> | |
38 | #include <sys/ptrace.h> | 38 | #include <sys/ptrace.h> | |
39 | #include <sys/systm.h> | 39 | #include <sys/systm.h> | |
40 | #include <sys/syscall.h> | 40 | #include <sys/syscall.h> | |
41 | #include <sys/syscallargs.h> | 41 | #include <sys/syscallargs.h> | |
42 | #include <uvm/uvm_extern.h> | 42 | #include <uvm/uvm_extern.h> | |
43 | 43 | |||
44 | #include <machine/reg.h> | 44 | #include <machine/reg.h> | |
45 | 45 | |||
46 | #include <compat/linux/common/linux_types.h> | 46 | #include <compat/linux/common/linux_types.h> | |
@@ -175,49 +175,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | @@ -175,49 +175,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | |||
175 | default: | 175 | default: | |
176 | error = EIO; | 176 | error = EIO; | |
177 | goto out; | 177 | goto out; | |
178 | } | 178 | } | |
179 | 179 | |||
180 | /* Find the process we are supposed to be operating on. */ | 180 | /* Find the process we are supposed to be operating on. */ | |
181 | mutex_enter(proc_lock); | 181 | mutex_enter(proc_lock); | |
182 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | 182 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | |
183 | mutex_exit(proc_lock); | 183 | mutex_exit(proc_lock); | |
184 | error = ESRCH; | 184 | error = ESRCH; | |
185 | goto out; | 185 | goto out; | |
186 | } | 186 | } | |
187 | mutex_enter(t->p_lock); | 187 | mutex_enter(t->p_lock); | |
188 | mutex_exit(proc_lock); | |||
189 | 188 | |||
190 | /* | 189 | /* | |
191 | * You cannot do what you want to the process if: | 190 | * You cannot do what you want to the process if: | |
192 | * 1. It is not being traced at all, | 191 | * 1. It is not being traced at all, | |
193 | */ | 192 | */ | |
194 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | 193 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | |
195 | mutex_exit(t->p_lock); | 194 | mutex_exit(t->p_lock); | |
195 | mutex_exit(proc_lock); | |||
196 | error = EPERM; | 196 | error = EPERM; | |
197 | goto out; | 197 | goto out; | |
198 | } | 198 | } | |
199 | /* | 199 | /* | |
200 | * 2. It is being traced by procfs (which has different signal | 200 | * 2. It is being traced by procfs (which has different signal | |
201 | * delivery semantics), | 201 | * delivery semantics), | |
202 | * 3. It is not being traced by _you_, or | 202 | * 3. It is not being traced by _you_, or | |
203 | * 4. It is not currently stopped. | 203 | * 4. It is not currently stopped. | |
204 | */ | 204 | */ | |
205 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | 205 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | |
206 | t->p_stat != SSTOP || !t->p_waited) { | 206 | t->p_stat != SSTOP || !t->p_waited) { | |
207 | mutex_exit(t->p_lock); | 207 | mutex_exit(t->p_lock); | |
208 | mutex_exit(proc_lock); | |||
208 | error = EBUSY; | 209 | error = EBUSY; | |
209 | goto out; | 210 | goto out; | |
210 | } | 211 | } | |
212 | mutex_exit(proc_lock); | |||
211 | /* XXX: ptrace needs revamp for multi-threading support. */ | 213 | /* XXX: ptrace needs revamp for multi-threading support. */ | |
212 | if (t->p_nlwps > 1) { | 214 | if (t->p_nlwps > 1) { | |
213 | mutex_exit(t->p_lock); | 215 | mutex_exit(t->p_lock); | |
214 | error = ENOSYS; | 216 | error = ENOSYS; | |
215 | goto out; | 217 | goto out; | |
216 | } | 218 | } | |
217 | lt = LIST_FIRST(&t->p_lwps); | 219 | lt = LIST_FIRST(&t->p_lwps); | |
218 | *retval = 0; | 220 | *retval = 0; | |
219 | 221 | |||
220 | switch (request) { | 222 | switch (request) { | |
221 | case LINUX_PTRACE_GETREGS: | 223 | case LINUX_PTRACE_GETREGS: | |
222 | error = process_read_regs(lt, regs); | 224 | error = process_read_regs(lt, regs); | |
223 | mutex_exit(t->p_lock); | 225 | mutex_exit(t->p_lock); |
--- src/sys/compat/linux/arch/powerpc/linux_ptrace.c 2014/11/09 17:48:08 1.28
+++ src/sys/compat/linux/arch/powerpc/linux_ptrace.c 2015/10/13 08:24:35 1.29
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_ptrace.c,v 1.28 2014/11/09 17:48:08 maxv Exp $ */ | 1 | /* $NetBSD: linux_ptrace.c,v 1.29 2015/10/13 08:24:35 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Matthias Scheler and Emmanuel Dreyfus. | 8 | * by Matthias Scheler and Emmanuel Dreyfus. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.28 2014/11/09 17:48:08 maxv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.29 2015/10/13 08:24:35 pgoyette Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/mount.h> | 36 | #include <sys/mount.h> | |
37 | #include <sys/proc.h> | 37 | #include <sys/proc.h> | |
38 | #include <sys/ptrace.h> | 38 | #include <sys/ptrace.h> | |
39 | #include <sys/systm.h> | 39 | #include <sys/systm.h> | |
40 | #include <sys/syscallargs.h> | 40 | #include <sys/syscallargs.h> | |
41 | #include <uvm/uvm_extern.h> | 41 | #include <uvm/uvm_extern.h> | |
42 | 42 | |||
43 | #include <machine/reg.h> | 43 | #include <machine/reg.h> | |
44 | 44 | |||
45 | #include <compat/linux/common/linux_types.h> | 45 | #include <compat/linux/common/linux_types.h> | |
46 | #include <compat/linux/common/linux_ptrace.h> | 46 | #include <compat/linux/common/linux_ptrace.h> | |
@@ -152,49 +152,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | @@ -152,49 +152,51 @@ linux_sys_ptrace_arch(struct lwp *l, con | |||
152 | default: | 152 | default: | |
153 | error = EIO; | 153 | error = EIO; | |
154 | goto out; | 154 | goto out; | |
155 | } | 155 | } | |
156 | 156 | |||
157 | /* Find the process we are supposed to be operating on. */ | 157 | /* Find the process we are supposed to be operating on. */ | |
158 | mutex_enter(proc_lock); | 158 | mutex_enter(proc_lock); | |
159 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | 159 | if ((t = proc_find(SCARG(uap, pid))) == NULL) { | |
160 | mutex_exit(proc_lock); | 160 | mutex_exit(proc_lock); | |
161 | error = ESRCH; | 161 | error = ESRCH; | |
162 | goto out; | 162 | goto out; | |
163 | } | 163 | } | |
164 | mutex_enter(t->p_lock); | 164 | mutex_enter(t->p_lock); | |
165 | mutex_exit(proc_lock); | |||
166 | 165 | |||
167 | /* | 166 | /* | |
168 | * You cannot do what you want to the process if: | 167 | * You cannot do what you want to the process if: | |
169 | * 1. It is not being traced at all, | 168 | * 1. It is not being traced at all, | |
170 | */ | 169 | */ | |
171 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | 170 | if (!ISSET(t->p_slflag, PSL_TRACED)) { | |
172 | mutex_exit(t->p_lock); | 171 | mutex_exit(t->p_lock); | |
172 | mutex_exit(proc_lock); | |||
173 | error = EPERM; | 173 | error = EPERM; | |
174 | goto out; | 174 | goto out; | |
175 | } | 175 | } | |
176 | /* | 176 | /* | |
177 | * 2. It is being traced by procfs (which has different signal | 177 | * 2. It is being traced by procfs (which has different signal | |
178 | * delivery semantics), | 178 | * delivery semantics), | |
179 | * 3. It is not being traced by _you_, or | 179 | * 3. It is not being traced by _you_, or | |
180 | * 4. It is not currently stopped. | 180 | * 4. It is not currently stopped. | |
181 | */ | 181 | */ | |
182 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | 182 | if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p || | |
183 | t->p_stat != SSTOP || !t->p_waited) { | 183 | t->p_stat != SSTOP || !t->p_waited) { | |
184 | mutex_exit(t->p_lock); | 184 | mutex_exit(t->p_lock); | |
185 | mutex_exit(proc_lock); | |||
185 | error = EBUSY; | 186 | error = EBUSY; | |
186 | goto out; | 187 | goto out; | |
187 | } | 188 | } | |
189 | mutex_exit(proc_lock); | |||
188 | /* XXX: ptrace needs revamp for multi-threading support. */ | 190 | /* XXX: ptrace needs revamp for multi-threading support. */ | |
189 | if (t->p_nlwps > 1) { | 191 | if (t->p_nlwps > 1) { | |
190 | mutex_exit(t->p_lock); | 192 | mutex_exit(t->p_lock); | |
191 | error = ENOSYS; | 193 | error = ENOSYS; | |
192 | goto out; | 194 | goto out; | |
193 | } | 195 | } | |
194 | lt = LIST_FIRST(&t->p_lwps); | 196 | lt = LIST_FIRST(&t->p_lwps); | |
195 | *retval = 0; | 197 | *retval = 0; | |
196 | 198 | |||
197 | switch (request) { | 199 | switch (request) { | |
198 | case LINUX_PTRACE_GETREGS: | 200 | case LINUX_PTRACE_GETREGS: | |
199 | error = process_read_regs(lt, regs); | 201 | error = process_read_regs(lt, regs); | |
200 | mutex_exit(t->p_lock); | 202 | mutex_exit(t->p_lock); |