Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137889303
D30481.id89924.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D30481.id89924.diff
View Options
Index: sys/kern/kern_ktrace.c
===================================================================
--- sys/kern/kern_ktrace.c
+++ sys/kern/kern_ktrace.c
@@ -1006,7 +1006,7 @@
int facs = uap->facs & ~KTRFAC_ROOT;
int ops = KTROP(uap->ops);
int descend = uap->ops & KTRFLAG_DESCEND;
- int nfound, ret = 0;
+ int ret = 0;
int flags, error = 0;
struct nameidata nd;
struct ktr_io_params *kiop, *old_kiop;
@@ -1080,42 +1080,31 @@
error = ESRCH;
goto done;
}
+
/*
* ktrops() may call vrele(). Lock pg_members
* by the proctree_lock rather than pg_mtx.
*/
PGRP_UNLOCK(pg);
- nfound = 0;
+ if (LIST_EMPTY(&pg->pg_members)) {
+ sx_sunlock(&proctree_lock);
+ error = ESRCH;
+ goto done;
+ }
LIST_FOREACH(p, &pg->pg_members, p_pglist) {
PROC_LOCK(p);
- if (p->p_state == PRS_NEW ||
- p_cansee(td, p) != 0) {
- PROC_UNLOCK(p);
- continue;
- }
- nfound++;
if (descend)
ret |= ktrsetchildren(td, p, ops, facs, kiop);
else
ret |= ktrops(td, p, ops, facs, kiop);
}
- if (nfound == 0) {
- sx_sunlock(&proctree_lock);
- error = ESRCH;
- goto done;
- }
} else {
/*
* by pid
*/
p = pfind(uap->pid);
- if (p == NULL)
+ if (p == NULL) {
error = ESRCH;
- else
- error = p_cansee(td, p);
- if (error) {
- if (p != NULL)
- PROC_UNLOCK(p);
sx_sunlock(&proctree_lock);
goto done;
}
@@ -1187,8 +1176,20 @@
PROC_UNLOCK(p);
return (0);
}
- if (p->p_flag & P_WEXIT) {
- /* If the process is exiting, just ignore it. */
+ if ((ops == KTROP_SET && p->p_state == PRS_NEW) || !p_cansee(td, p)) {
+ /*
+ * Disallow setting trace points if the process is being born.
+ * This avoids races with trace point inheritance in
+ * ktrprocfork().
+ */
+ PROC_UNLOCK(p);
+ return (0);
+ }
+ if ((p->p_flag & P_WEXIT) != 0) {
+ /*
+ * There's nothing to do if the process is exiting, but avoid
+ * signaling an error.
+ */
PROC_UNLOCK(p);
return (1);
}
@@ -1240,16 +1241,18 @@
* otherwise do any siblings, and if done with this level,
* follow back up the tree (but not past top).
*/
- if (!LIST_EMPTY(&p->p_children))
+ if (!LIST_EMPTY(&p->p_children)) {
p = LIST_FIRST(&p->p_children);
- else for (;;) {
- if (p == top)
- return (ret);
- if (LIST_NEXT(p, p_sibling)) {
- p = LIST_NEXT(p, p_sibling);
- break;
+ } else {
+ for (;;) {
+ if (p == top)
+ return (ret);
+ if (LIST_NEXT(p, p_sibling) != NULL) {
+ p = LIST_NEXT(p, p_sibling);
+ break;
+ }
+ p = p->p_pptr;
}
- p = p->p_pptr;
}
PROC_LOCK(p);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 27, 10:18 PM (5 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26264359
Default Alt Text
D30481.id89924.diff (2 KB)
Attached To
Mode
D30481: ktrace: Fix a race with fork()
Attached
Detach File
Event Timeline
Log In to Comment