Skip to contentSkip to conversation

OOps in exec_usermodehelper

DISCUSSION Petr Vandrovec 3 participants 3 messages Nov 27, 2000 – Nov 28, 2000 Scheduler

lore
Share & tools
lore
#0 lore raw

Hi,
I have one small problem with 2.4.0-test11 and exec_usermodehelper.
When vmware modules shutdown (specifically vmnet-netifup), kernel tries to load some module through call_usermodehelper, but unfortunately from task which has current->files == NULL.

So it prints message:

waitpid(19457) failed, -512

and then it oopses in

for (i = 0; i < current->files->max_fds; i++) {
if (current->files->fd[i]) close(i);
}

(In log, there is first waitpid, and then oopses from current->files == NULL, which I do not quite understand).

Should I look into this more deeply, or is correct fix just add

if (current->files) {
for (i = 0; ..... ) ...
}

into exec_usermodehelper?
Best regards,
Petr Vandrovec [email protected]
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw
Quoted 20 lines · Petr Vandrovec

Hi,
I have one small problem with 2.4.0-test11 and exec_usermodehelper.
When vmware modules shutdown (specifically vmnet-netifup), kernel tries to load some module through call_usermodehelper, but unfortunately from task which has current->files == NULL.

So it prints message:

waitpid(19457) failed, -512

and then it oopses in

for (i = 0; i < current->files->max_fds; i++) {
if (current->files->fd[i]) close(i);
}

(In log, there is first waitpid, and then oopses from current->files == NULL, which I do not quite understand).

Quoted 7 lines

Should I look into this more deeply, or is correct fix just add

if (current->files) {
for (i = 0; ..... ) ...
}

into exec_usermodehelper?

No. Then it just blows up somewhere else.

The root cause here is that we're starting a kernel thread from within a half-exitted parent. I'll be coding a fix
later today.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
In reply to Petr Vandrovec
Quoted 6 lines · Petr Vandrovec

Hi,
I have one small problem with 2.4.0-test11 and exec_usermodehelper.
When vmware modules shutdown (specifically vmnet-netifup), kernel tries to load some module through call_usermodehelper, but unfortunately from task which has current->files == NULL.

hmm.. Quite a few things fixed here.

Could you please test this patch? It's against 2.4.0-test12-pre2, should be OK against test11.

The basic problem is that we are launching kernel threads from within half-exitted parents.

	do_exit->__exit_files->ppp_destroy_interface->...

I don't think it's a good idea to teach the kernel how to fork from half-dead parents, so this patch moves /sbin/hotplug so it's parented by [k]eventd, not by whoever called [un]register_netdevice.

Changes:

- rename eventd' to keventd'

- start_context_thread() is now called explicitly prior to doing the initcalls. This is to prevent the possibility of an initcall function getting permanently blocked because keventd hasn't started.

- Don't call net_notifier_init until we've mounted the root fs. This prevents the "no root fs" warnings.

- Make the call to net_notifier_init dependent on CONFIG_NET, so netless kernels don't fail at link time.

- call_usermodehelper() now asks keventd to parent the usermode app. In fact keventd is the grandparent because we need an intermediate thread to wait on the usermode app. We don't want keventd to block while /sbin/hotplug does its thing.

- Fix exec_helper so it returns the exit code of the child. Error values are now correctly propagated as described in the comments.

- In schedule_task(), drop a log if keventd isn't running yet.

- Fix call_usermodehelper() so it blocks SIGCHLD. This was the reason for the waitpid() calls failing with ERESTARTSYS.

- Will now correctly find /sbin/hotplug if the caller of [un]register_netdevice is chrooted.

- keventd is now capable of reaping dead children. I will be all ears if someone can tell me how to get a kernel thread to accept signals without having to install a handler with

    sa.sa_handler = (__sighandler_t)100;
include/linux/sched.h +1 -0
@@ -150,6 +150,7 @@
 asmlinkage void schedule(void);
 
 extern void schedule_task(struct tq_struct *task);
+extern int start_context_thread(void);
 
 /*
  * The default fd array needs to be at least BITS_PER_LONG,
kernel/kmod.c +103 -22

150 lines not on this page · raw message

kernel/context.c +28 -11
@@ -6,16 +6,23 @@
  * [email protected]
  */
 
+#define __KERNEL_SYSCALLS__
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/init.h>
+#include <linux/unistd.h>
+#include <linux/signal.h>
 
 static DECLARE_TASK_QUEUE(tq_context);
 static DECLARE_WAIT_QUEUE_HEAD(context_task_wq);
+static int keventd_running;
 
 void schedule_task(struct tq_struct *task)
 {
+	if (keventd_running == 0)
+		printk(KERN_ERR "schedule_task(): keventd has not started\n");
 	queue_task(task, &tq_context);
 	wake_up(&context_task_wq);
 }
@@ -24,18 +31,24 @@
 
 static int context_thread(void *dummy)
 {
-	DECLARE_WAITQUEUE(wait, current);
+	struct task_struct *curtask = current;
+	DECLARE_WAITQUEUE(wait, curtask);
+	struct k_sigaction sa;
 
 	daemonize();
-	strcpy(current->comm, "eventd");
+	strcpy(curtask->comm, "keventd");
+	keventd_running = 1;
 
-        spin_lock_irq(&current->sigmask_lock);
-        sigfillset(&current->blocked);
-        recalc_sigpending(current);
-        spin_unlock_irq(&current->sigmask_lock);
+	spin_lock_irq(&curtask->sigmask_lock);
+	siginitsetinv(&curtask->blocked, sigmask(SIGCHLD));
+	recalc_sigpending(curtask);
+	spin_unlock_irq(&curtask->sigmask_lock);
+	sa.sa.sa_handler = (__sighandler_t)100;		/* Surely there's a better way? */
+	sa.sa.sa_flags = 0;
+	do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
 
 	for (;;) {
-		current->state = TASK_INTERRUPTIBLE;
+		__set_task_state(curtask, TASK_INTERRUPTIBLE);
 		add_wait_queue(&context_task_wq, &wait);
 
 		/*
@@ -46,15 +59,19 @@
 			schedule();
 
 		remove_wait_queue(&context_task_wq, &wait);
-		current->state = TASK_RUNNING;
+		__set_task_state(curtask, TASK_RUNNING);
 		run_task_queue(&tq_context);
+		if (signal_pending(curtask)) {
+			while (waitpid(-1, (unsigned int *)0, __WALL|WNOHANG) > 0)
+				;
+			flush_signals(curtask);
+			recalc_sigpending(curtask);
+		}
 	}
 }
 
-static int __init start_context_thread(void)
+int start_context_thread(void)
 {
 	kernel_thread(context_thread, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
 	return 0;
 }
-
-module_init(start_context_thread);
init/main.c +5 -5
@@ -702,6 +702,7 @@
 	else mount_initrd =0;
 #endif
 
+	start_context_thread();
 	do_initcalls();
 
 	/* .. filesystems .. */
@@ -714,16 +715,16 @@
 	init_pcmcia_ds();		/* Do this last */
 #endif
 
-#ifdef CONFIG_HOTPLUG
+	/* Mount the root filesystem.. */
+	mount_root();
+
+#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
 	/* do this after other 'do this last' stuff, because we want
 	 * to minimize spurious executions of /sbin/hotplug
 	 * during boot-up
 	 */
 	net_notifier_init();
 #endif
-
-	/* Mount the root filesystem.. */
-	mount_root();
 
 	mount_devfs_fs ();
-

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/