Skip to contentSkip to conversation

exec: don't turn PF_KTHREAD off when command not found

PATCH Superseded KOSAKI Motohiro 3 participants 3 messages Sep 9, 2010 – Sep 10, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec: don't turn PF_KTHREAD off when command not found

Now, do_execve() turn PF_KTHREAD off before search_binary_handler(). It has theorical risk of PF_KTHREAD lost. When ENOEXEC case, we don't have to turn PF_KTHREAD off.

This patch move this flag modification after founding execution file.

I guess this is only theorical issue because now any kthread don't call do_execve() directly. but anyway fixing would be better.

Cc Roland McGrath <[email protected]>
Cc Oleg Nesterov <[email protected]>
---
 fs/exec.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/exec.c +1 -2
index ef8b9dc..81d0d06 100644
@@ -1011,7 +1011,7 @@ int flush_old_exec(struct linux_binprm * bprm)
 	bprm->mm = NULL;		/* We're using it now */
 	set_exec_mm(NULL);
 
-	current->flags &= ~PF_RANDOMIZE;
+	current->flags &= ~(PF_RANDOMIZE | PF_KTHREAD);
 	flush_thread();
 	current->personality &= ~bprm->per_clear;
 
@@ -1421,7 +1421,6 @@ int do_execve(const char * filename,
 	if (retval < 0)
 		goto out;
 
-	current->flags &= ~PF_KTHREAD;
 	retval = search_binary_handler(bprm,regs);
 	if (retval < 0)
 		goto out;
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 3 lines · KOSAKI Motohiro

I guess this is only theorical issue because now any kthread don't call do_execve() directly.

Yes, I think that kthread should always exit if exec fails. Otherwise we can "trust" the thread, just suppose that exec fails after exec_mmap() succeeds.

But,

Quoted 1 line

but anyway fixing would be better.

Agreed. It looks better if we clear PF_KTHREAD after the point-of-no-return, and the patch saves one ->flags modification.

Oleg.