Re: [PATCH 2/2] Yama: add PTRACE exception tracking

From: Tetsuo Handa
Date: Wed Jun 30 2010 - 17:39:16 EST


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;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/