Skip to contentSkip to conversation

[2.6.13] task_struct->fs_excl, kernel_thread and jffs2

PATCH Giancarlo Formicuccia 2 participants 2 messages Sep 8, 2005

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

Hi,
[please CC me in any reply]
I'm not sure that dup_task_struct() must copy the fs_excl field. This can leads to problems if do_fork() is somehow called while fs_excl!=0.
For example, the jffs2 code creates a kernel thread (jffs2_garbage_collect_thread) in a path where lock_super() is held (i.e. by do_remount_sb, during -o remount,rw). When the new thread expires, a badness happens (kernel/exit.c:787). This problem was observed by a couple of people and can be easily reproduced:
http://lists.infradead.org/pipermail/linux-mtd/2005-August/013487.html
http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel/2005-September/031109.html

At first glance, I'd simply set fs_excl to 0 for every new thread in dup_task_struct:

kernel/fork.c +1 -0
@@ -173,6 +173,7 @@ static struct task_struct *dup_task_stru
 	*tsk = *orig;
 	tsk->thread_info = ti;
 	ti->task = tsk;
+	atomic_set(&tsk->fs_excl, 0);
 
 	/* One for us, one for whoever does the "release_task()" (usually parent) */
 	atomic_set(&tsk->usage,2);

but I've a doubt about the WARN_ON in exit.c being actually here to report these kernel_thread() users (like jffs2)...

Any comment/suggestion?

Thanks,

Giancarlo

Acked-by
#1 lore raw
Quoted 24 lines · Giancarlo Formicuccia

Hi,
[please CC me in any reply]
I'm not sure that dup_task_struct() must copy the fs_excl field. This can leads to problems if do_fork() is somehow called while fs_excl!=0.
For example, the jffs2 code creates a kernel thread (jffs2_garbage_collect_thread) in a path where lock_super() is held (i.e. by do_remount_sb, during -o remount,rw). When the new thread expires, a badness happens (kernel/exit.c:787). This problem was observed by a couple of people and can be easily reproduced:
http://lists.infradead.org/pipermail/linux-mtd/2005-August/013487.html
http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel/2005-September/031109.html

At first glance, I'd simply set fs_excl to 0 for every new thread in dup_task_struct:

kernel/fork.c +1 -0
@@ -173,6 +173,7 @@ static struct task_struct *dup_task_stru
 	*tsk = *orig;
 	tsk->thread_info = ti;
 	ti->task = tsk;
+	atomic_set(&tsk->fs_excl, 0);
 
 	/* One for us, one for whoever does the "release_task()" (usually parent) */
 	atomic_set(&tsk->usage,2);
Quoted 4 lines

but I've a doubt about the WARN_ON in exit.c being actually here to report these kernel_thread() users (like jffs2)...

Any comment/suggestion?

Patch is correct, that is definitely an oversight!

Signature · 1 line
Jens Axboe