Re: [PATCH] Avoid dereferencing a possibly NULL mm

From: Oleg Nesterov
Date: Sat Jun 02 2012 - 13:43:46 EST


On 06/02, Siddhesh Poyarekar wrote:
>
> The NULL check for mm in exit_mm occurs after mm_release is
> called. This looks wrong because mm_release dereferences mm:
>
> ...
> if (!(tsk->flags & PF_SIGNALED) &&
> atomic_read(&mm->mm_users) > 1) {
> /*
> ...

Yes, this looks wrong, but the task without ->mm shouldn't have
->clear_child_tid != NULL, so this is harmless.

> This dereference seems unsafe and hence is fixed by moving the NULL
> check above mm_release.

And this is wrong,

> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -640,9 +640,11 @@ static void exit_mm(struct task_struct * tsk)
> struct mm_struct *mm = tsk->mm;
> struct core_state *core_state;
>
> - mm_release(tsk, mm);
> if (!mm)
> return;
> +
> + mm_release(tsk, mm);
> +

mm_release()->complete_vfork_done() should be called even if
->mm == NULL. See kthread_stop().

Probably this needs some cleanups or comments, but lets do
this on top of pending fixes in -mm tree.

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/