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