Messages in this thread | | | Subject | Re: [PATCH 2/2] Yama: add PTRACE exception tracking | From | Tetsuo Handa <> | Date | Thu, 1 Jul 2010 06:39:05 +0900 |
| |
Kees Cook wrote: > @@ -41,18 +41,30 @@ static DEFINE_SPINLOCK(ptracer_relations_lock); > static int yama_ptracer_add(struct task_struct *tracer, > struct task_struct *tracee) > { > - struct ptrace_relation *relation; > + int rc = 0; > + struct ptrace_relation *entry, *relation = NULL; > > - relation = kmalloc(sizeof(*relation), GFP_KERNEL); > - if (!relation) > - return -ENOMEM; > - relation->tracer = tracer; > - relation->tracee = tracee; > spin_lock(&ptracer_relations_lock); > - list_add(&relation->node, &ptracer_relations); > + list_for_each_entry(entry, &ptracer_relations, node) > + if (entry->tracee == tracee) { > + relation = entry; > + break; > + } > + if (!relation) { > + relation = kmalloc(sizeof(*relation), GFP_KERNEL);
You can't use GFP_KERNEL here because a spinlock is held.
> + if (!relation) { > + rc = -ENOMEM; > + goto unlock_out; > + } > + relation->tracee = tracee; > + list_add(&relation->node, &ptracer_relations); > + } > + relation->tracer = tracer; > + > +unlock_out: > spin_unlock(&ptracer_relations_lock); > > - return 0; > + return rc; > }
| |