Re: [PATCH] shm: fix a race between shm_exit() and shm_init()

Linus Torvalds
2011-08-04T00:36:09Z

[-- Attachment #1: Type: text/plain, Size: 683 bytes --]

On Wed, Aug 3, 2011 at 12:30 AM, Marc Zyngier <marc.zyngier@arm.com> wrote:
>
> driver_init() is called from do_basic_setup(), before any initcall...

Ok, thanks everybody. I think the proper fix is the attached patch.
It's crazy to have usermode helpers enabled early during boot when
init etc haven't even been set up.

So does this finally fix the problem (I realize that there are other
patches floating around that *also* fix it, so please test this
without those other patches).

I'm planning on also applying the patch that optimizes the case of no
shm attaches, which would also hide the oops, but I think this
attached patch is the RightThing(tm).

Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1110 bytes --]

init/main.c | 5 ++++-
kernel/kmod.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/init/main.c b/init/main.c
index 1952d37e4ecb..9c51ee7adf3d 100644
--- a/init/main.c
+++ b/init/main.c
@@ -369,9 +369,12 @@ static noinline void __init_refok rest_init(void)
init_idle_bootup_task(current);
preempt_enable_no_resched();
schedule();
- preempt_disable();
+
+ /* At this point, we can enable user mode helper functionality */
+ usermodehelper_enable();

/* Call into cpu_idle with preempt disabled */
+ preempt_disable();
cpu_idle();
}

diff --git a/kernel/kmod.c b/kernel/kmod.c
index 47613dfb7b28..ddc7644c1305 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -274,7 +274,7 @@ static void __call_usermodehelper(struct work_struct *work)
* (used for preventing user land processes from being created after the user
* land has been frozen during a system-wide hibernation or suspend operation).
*/
-static int usermodehelper_disabled;
+static int usermodehelper_disabled = 1;

/* Number of helpers running */
static atomic_t running_helpers = ATOMIC_INIT(0);