Re: [PATCH] Fix race in process_vm_rw_core

From: Oleg Nesterov
Date: Mon Jan 16 2012 - 14:05:32 EST


On 01/16, Christopher Yeoh wrote:
>
> +struct mm_struct *get_check_task_mm(struct task_struct *task, unsigned int mode)
> +{
> + struct mm_struct *mm;
> + int err;
> +
> + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
> + if (err)
> + return ERR_PTR(err);
> +
> + task_lock(task);
> + mm = task->mm;
> + if (mm != current->mm && __ptrace_may_access(task, mode)) {
> + mm = ERR_PTR(-EACCES);
> + goto out;
> + }
> +
> + if (mm) {
> + if (task->flags & PF_KTHREAD)
> + mm = NULL;
> + else
> + atomic_inc(&mm->mm_users);
> + }

This still looks a bit strange, we call __ptrace_may_access()
before we check ->mm != NULL even if this is safe... Really, we
would simply fix the bug then try to microoptimize this code.

But OK, I promised I won't argue ;)

I believe the patch is correct and fixes the problem.

Oleg.

--
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/