Commit 0704298b authored by Linus Torvalds's avatar Linus Torvalds

Don't allow user-level helpers to be run when our infrastructure

isn't ready for it (either during early boot, or at shutdown)
parent 41421468
......@@ -82,6 +82,12 @@ extern void tc_init(void);
extern void ipc_init(void);
#endif
/*
* Are we up and running (ie do we have all the infrastructure
* set up)
*/
int system_running = 0;
/*
* Boot command-line arguments
*/
......@@ -559,6 +565,7 @@ static int init(void * unused)
*/
free_initmem();
unlock_kernel();
system_running = 1;
kstat.pgfree = 0;
......
......@@ -32,7 +32,7 @@
#include <asm/uaccess.h>
extern int max_threads;
extern int max_threads, system_running;
static inline void
use_init_fs_context(void)
......@@ -158,6 +158,9 @@ static int exec_modprobe(void * module_name)
char *argv[] = { modprobe_path, "-s", "-k", "--", (char*)module_name, NULL };
int ret;
if (!system_running)
return -EBUSY;
ret = exec_usermodehelper(modprobe_path, argv, envp);
if (ret) {
static unsigned long last;
......@@ -197,10 +200,9 @@ int request_module(const char * module_name)
unsigned long saved_policy = current->policy;
current->policy = SCHED_NORMAL;
/* Don't allow request_module() before the root fs is mounted! */
if ( ! current->fs->root ) {
printk(KERN_ERR "request_module[%s]: Root fs not mounted\n",
module_name);
/* Don't allow request_module() when the system isn't set up */
if ( ! system_running ) {
printk(KERN_ERR "request_module[%s]: not ready\n", module_name);
ret = -EPERM;
goto out;
}
......@@ -357,6 +359,9 @@ int call_usermodehelper(char *path, char **argv, char **envp)
.data = &sub_info,
};
if (!system_running)
return -EBUSY;
if (path[0] == '\0')
goto out;
......
......@@ -323,6 +323,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
switch (cmd) {
case LINUX_REBOOT_CMD_RESTART:
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
system_running = 0;
device_shutdown();
printk(KERN_EMERG "Restarting system.\n");
machine_restart(NULL);
......@@ -338,6 +339,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
case LINUX_REBOOT_CMD_HALT:
notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
system_running = 0;
device_shutdown();
printk(KERN_EMERG "System halted.\n");
machine_halt();
......@@ -346,6 +348,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
case LINUX_REBOOT_CMD_POWER_OFF:
notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
system_running = 0;
device_shutdown();
printk(KERN_EMERG "Power down.\n");
machine_power_off();
......@@ -360,6 +363,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
buffer[sizeof(buffer) - 1] = '\0';
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
system_running = 0;
device_shutdown();
printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
machine_restart(buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment