2003-02-23 12:50:08

by Mikael Pettersson

[permalink] [raw]
Subject: [BUG] 2.5.62 kmod rewrite broke modprobe's install command

In kernel 2.5.62, modprobe logs "FATAL: Error -1" when invoked
via request_module() to run a trivial /bin/true "install" command.
This problem did not exist in 2.5.61 or earlier kernels.

Repeat-by: Build a kernel without the RTC driver, put
"install char-major-10-135 /bin/true" in /etc/modprobe.conf
(new ugly way of saying "alias ... off"), od -c /dev/rtc,
and observe the modprobe error in /var/log/messages.
This will trigger the problem with 100% repeatability for me.

The reason this happens is that in 2.5.62, modprobe is started
with SIGCHLD set to SIG_IGN and not blocked. The "install"
command is run by system(), but due to SIGCHLD being SIG_IGN,
the child (which terminates quickly) is reaped automatically.
The parent process (modprobe) does a wait or waitpid, which fails
with ECHILD since the child is already gone. system() returns -1,
and modprobe logs a fatal error.

In 2.5.61 and earlier kernels, modprobe is started with SIGCHLD
set to SIG_DFL and not blocked, and system() works normally.

/Mikael


2003-02-24 02:50:52

by Rusty Russell

[permalink] [raw]
Subject: Re: [BUG] 2.5.62 kmod rewrite broke modprobe's install command

In message <[email protected]> you write:
> The reason this happens is that in 2.5.62, modprobe is started
> with SIGCHLD set to SIG_IGN and not blocked. The "install"
> command is run by system(), but due to SIGCHLD being SIG_IGN,
> the child (which terminates quickly) is reaped automatically.
> The parent process (modprobe) does a wait or waitpid, which fails
> with ECHILD since the child is already gone. system() returns -1,
> and modprobe logs a fatal error.

Yes. Fixed below.

Thanks for the report!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Enable signals for usermode helpers
Author: Linus Torvalds
Status: Experimental

D: Stelian Pop reported that all signals are blocked in processes
D: execed from the kernel as usermode helpers.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.62-bk6/kernel/kmod.c working-2.5.62-bk6-usermode-sig/kernel/kmod.c
--- linux-2.5.62-bk6/kernel/kmod.c 2003-02-18 11:18:57.000000000 +1100
+++ working-2.5.62-bk6-usermode-sig/kernel/kmod.c 2003-02-24 12:18:55.000000000 +1100
@@ -152,6 +152,14 @@ static int ____call_usermodehelper(void
struct subprocess_info *sub_info = data;
int retval;

+ /* Unblock all signals. */
+ flush_signals(curtask);
+ flush_signal_handlers(curtask);
+ spin_lock_irq(&curtask->sighand->siglock);
+ sigemptyset(&curtask->blocked);
+ recalc_sigpending();
+ spin_unlock_irq(&curtask->sighand->siglock);
+
retval = -EPERM;
if (current->fs->root)
retval = execve(sub_info->path, sub_info->argv,sub_info->envp);

2003-02-24 12:48:59

by Mikael Pettersson

[permalink] [raw]
Subject: Re: [BUG] 2.5.62 kmod rewrite broke modprobe's install command

On Mon, 24 Feb 2003 13:52:18 +1100, Rusty Russell wrote:
>--- linux-2.5.62-bk6/kernel/kmod.c 2003-02-18 11:18:57.000000000 +1100
>+++ working-2.5.62-bk6-usermode-sig/kernel/kmod.c 2003-02-24 12:18:55.000000000 +1100
>@@ -152,6 +152,14 @@ static int ____call_usermodehelper(void
> struct subprocess_info *sub_info = data;
> int retval;
>
>+ /* Unblock all signals. */
>+ flush_signals(curtask);
>+ flush_signal_handlers(curtask);
>+ spin_lock_irq(&curtask->sighand->siglock);
>+ sigemptyset(&curtask->blocked);
>+ recalc_sigpending();
>+ spin_unlock_irq(&curtask->sighand->siglock);
>+
> retval = -EPERM;
> if (current->fs->root)
> retval = execve(sub_info->path, sub_info->argv,sub_info->envp);
>

Doesn't compile (curtask undeclared) and doesn't work (SIGCHLD is
still SIG_IGN causing system() to fail). The problem is that
kernel/workqueue.c:worker_thread() [which is what runs modprobe now]
sets SIGCHLD to SIG_IGN, and your patch doesn't unbreak that.

The patch below, applied on top of your patch, makes it work for me.

/Mikael

--- linux-2.5.62/kernel/kmod.c.~2~ 2003-02-24 12:39:01.000000000 +0100
+++ linux-2.5.62/kernel/kmod.c 2003-02-24 13:27:51.000000000 +0100
@@ -150,10 +150,12 @@
static int ____call_usermodehelper(void *data)
{
struct subprocess_info *sub_info = data;
+ struct task_struct *curtask = current;
int retval;

/* Unblock all signals. */
flush_signals(curtask);
+ curtask->sighand->action[SIGCHLD-1].sa.sa_handler = SIG_DFL;
flush_signal_handlers(curtask);
spin_lock_irq(&curtask->sighand->siglock);
sigemptyset(&curtask->blocked);