[PATCH] [7/11] SYSCTL: Convert poweroff_command to proc_rcu_string

From: Andi Kleen
Date: Sun Dec 20 2009 - 20:20:40 EST



Avoids races with lockless sysctl.

Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>

---
include/linux/reboot.h | 2 +-
kernel/sys.c | 8 ++++++--
kernel/sysctl.c | 2 +-
3 files changed, 8 insertions(+), 4 deletions(-)

Index: linux-2.6.33-rc1-ak/kernel/sys.c
===================================================================
--- linux-2.6.33-rc1-ak.orig/kernel/sys.c
+++ linux-2.6.33-rc1-ak/kernel/sys.c
@@ -1595,7 +1595,7 @@ SYSCALL_DEFINE3(getcpu, unsigned __user
return err ? -EFAULT : 0;
}

-char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+char *poweroff_cmd = "/sbin/poweroff";

static void argv_cleanup(char **argv, char **envp)
{
@@ -1612,7 +1612,7 @@ static void argv_cleanup(char **argv, ch
int orderly_poweroff(bool force)
{
int argc;
- char **argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc);
+ char **argv;
static char *envp[] = {
"HOME=/",
"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
@@ -1621,6 +1621,10 @@ int orderly_poweroff(bool force)
int ret = -ENOMEM;
struct subprocess_info *info;

+ /* RCU protection for poweroff_cmd */
+ rcu_read_lock();
+ argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc);
+ rcu_read_unlock();
if (argv == NULL) {
printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n",
__func__, poweroff_cmd);
Index: linux-2.6.33-rc1-ak/include/linux/reboot.h
===================================================================
--- linux-2.6.33-rc1-ak.orig/include/linux/reboot.h
+++ linux-2.6.33-rc1-ak/include/linux/reboot.h
@@ -67,7 +67,7 @@ extern void kernel_power_off(void);
void ctrl_alt_del(void);

#define POWEROFF_CMD_PATH_LEN 256
-extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
+extern char *poweroff_cmd;

extern int orderly_poweroff(bool force);

Index: linux-2.6.33-rc1-ak/kernel/sysctl.c
===================================================================
--- linux-2.6.33-rc1-ak.orig/kernel/sysctl.c
+++ linux-2.6.33-rc1-ak/kernel/sysctl.c
@@ -871,7 +871,7 @@ static struct ctl_table kern_table[] = {
.data = &poweroff_cmd,
.maxlen = POWEROFF_CMD_PATH_LEN,
.mode = 0644,
- .proc_handler = proc_dostring,
+ .proc_handler = proc_rcu_string,
},
#ifdef CONFIG_KEYS
{
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/