Re: [PATCH v3] exec: do not sleep in TASK_TRACED under->cred_guard_mutex
From: Andrew Morton
Date: Fri Sep 04 2009 - 15:45:15 EST
On Fri, 4 Sep 2009 19:26:48 +0200
Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> Tom Horsley reports that his debugger hangs when it tries to read
> /proc/pid_of_tracee/maps, this happens since
> "mm_for_maps: take ->cred_guard_mutex to fix the race with exec"
> commit in 2.6.31.
> But the root of the problem lies in the fact that do_execve() path calls
> tracehook_report_exec() which can stop if the tracer sets PT_TRACE_EXEC.
> The tracee must not sleep in TASK_TRACED holding this mutex. Even if we
> remove ->cred_guard_mutex from mm_for_maps() and proc_pid_attr_write(),
> another task doing PTRACE_ATTACH should not hang until it is killed or
> the tracee resumes.
> With this patch do_execve() does not use ->cred_guard_mutex directly and
> we do not hold it throughout, instead:
> - introduce prepare_bprm_creds() helper, it locks the mutex
> and calls prepare_exec_creds() to initialize bprm->cred.
> - install_exec_creds() drops the mutex after commit_creds(),
> and thus before tracehook_report_exec()->ptrace_stop().
> or, if exec fails,
> free_bprm() drops this mutex when bprm->cred != NULL which
> indicates install_exec_creds() was not called.
> Reported-by: Tom Horsley <tom.horsley@xxxxxxx>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> Acked-by: David Howells <dhowells@xxxxxxxxxx>
I get a reject in binfmts.h because your kernel has `extern void
set_binfmt' and mine has `extern int set_binfmt'.
Hopefully this patch works OK in mainline as well as in whatever kernel
you tested against!
I see a Cc:stable in the mail headers, but not in the changelog. I
don't think the patch is applicable to -stable unless we miss 2.6.31.
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/