From: Andi Kleen <andi@firstfloor.org>
To: ebiederm@xmission.com, paulmck@linux.vnet.ibm.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [6/9] SYSCTL: Convert modprobe_path to proc_rcu_string()
Date: Tue, 5 Jan 2010 03:15:31 +0100 (CET) [thread overview]
Message-ID: <20100105021531.3919FB17C2@basil.firstfloor.org> (raw)
In-Reply-To: <20100105315.789846878@firstfloor.org>
Avoids races with lockless sysctl
Also saves ~220 bytes in the data segment for default kernels.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
kernel/kmod.c | 36 ++++++++++++++++++++++++++++--------
kernel/sysctl.c | 4 ++--
2 files changed, 30 insertions(+), 10 deletions(-)
Index: linux-2.6.33-rc2-ak/kernel/kmod.c
===================================================================
--- linux-2.6.33-rc2-ak.orig/kernel/kmod.c
+++ linux-2.6.33-rc2-ak/kernel/kmod.c
@@ -35,6 +35,7 @@
#include <linux/resource.h>
#include <linux/notifier.h>
#include <linux/suspend.h>
+#include <linux/rcustring.h>
#include <asm/uaccess.h>
#include <trace/events/module.h>
@@ -48,7 +49,12 @@ static struct workqueue_struct *khelper_
/*
modprobe_path is set via /proc/sys.
*/
-char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
+char *modprobe_path = "/sbin/modprobe";
+
+static void free_arg(char **argv, char **env)
+{
+ kfree(argv[0]);
+}
/**
* __request_module - try to load a kernel module
@@ -71,7 +77,8 @@ int __request_module(bool wait, const ch
char module_name[MODULE_NAME_LEN];
unsigned int max_modprobes;
int ret;
- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
+ char *mp_copy;
+ char *argv[] = { NULL, "-q", "--", module_name, NULL };
static char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
@@ -80,15 +87,24 @@ int __request_module(bool wait, const ch
#define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
static int kmod_loop_msg;
+ /* Get a stable-over-sleeps private copy of modprobe_path */
+ mp_copy = access_rcu_string(&modprobe_path, KMOD_PATH_LEN,
+ wait ? GFP_KERNEL : GFP_ATOMIC);
+ if (!mp_copy)
+ return -ENOMEM;
+ argv[0] = mp_copy;
+
va_start(args, fmt);
ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
va_end(args);
- if (ret >= MODULE_NAME_LEN)
- return -ENAMETOOLONG;
+ if (ret >= MODULE_NAME_LEN) {
+ ret = -ENAMETOOLONG;
+ goto error;
+ }
ret = security_kernel_module_request(module_name);
if (ret)
- return ret;
+ goto error;
/* If modprobe needs a service that is in a module, we get a recursive
* loop. Limit the number of running kmod threads to max_threads/2 or
@@ -111,14 +127,18 @@ int __request_module(bool wait, const ch
"request_module: runaway loop modprobe %s\n",
module_name);
atomic_dec(&kmod_concurrent);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto error;
}
trace_module_request(module_name, wait, _RET_IP_);
- ret = call_usermodehelper(modprobe_path, argv, envp,
- wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
+ ret = call_usermodehelper_cleanup(mp_copy, argv, envp,
+ wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC, free_arg);
+ mp_copy = NULL; /* free_arg frees */
atomic_dec(&kmod_concurrent);
+error:
+ kfree(mp_copy);
return ret;
}
EXPORT_SYMBOL(__request_module);
Index: linux-2.6.33-rc2-ak/kernel/sysctl.c
===================================================================
--- linux-2.6.33-rc2-ak.orig/kernel/sysctl.c
+++ linux-2.6.33-rc2-ak/kernel/sysctl.c
@@ -121,7 +121,7 @@ static int min_percpu_pagelist_fract = 8
static int ngroups_max = NGROUPS_MAX;
#ifdef CONFIG_MODULES
-extern char modprobe_path[];
+extern char *modprobe_path;
extern int modules_disabled;
#endif
#ifdef CONFIG_CHR_DEV_SG
@@ -532,7 +532,7 @@ static struct ctl_table kern_table[] = {
.data = &modprobe_path,
.maxlen = KMOD_PATH_LEN,
.mode = 0644,
- .proc_handler = proc_dostring,
+ .proc_handler = proc_rcu_string,
},
{
.procname = "modules_disabled",
next prev parent reply other threads:[~2010-01-05 2:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-05 2:15 [PATCH] [0/9] SYSCTL: Use RCU to avoid races with string sysctls v2 Andi Kleen
2010-01-05 2:15 ` [PATCH] [1/9] Add rcustring ADT for RCU protected strings v2 Andi Kleen
2010-01-05 5:32 ` Paul E. McKenney
2010-01-05 10:47 ` Andi Kleen
2010-01-05 14:11 ` Paul E. McKenney
2010-01-05 14:19 ` Andi Kleen
2010-01-08 23:50 ` Andrew Morton
2010-01-11 12:12 ` Bert Wesarg
2010-01-11 14:26 ` Andi Kleen
2010-01-05 2:15 ` [PATCH] [2/9] Add a kernel_address() that works for data too Andi Kleen
2010-01-05 8:44 ` Russell King
2010-01-05 8:58 ` Sam Ravnborg
2010-01-05 19:04 ` Russell King
2010-01-05 19:15 ` Andi Kleen
2010-01-08 23:51 ` Andrew Morton
2010-01-05 2:15 ` [PATCH] [3/9] SYSCTL: Add proc_rcu_string to manage sysctls using rcu strings Andi Kleen
2010-01-05 2:15 ` [PATCH] [4/9] SYSCTL: Use RCU strings for core_pattern sysctl Andi Kleen
2010-01-05 6:56 ` Eric W. Biederman
2010-01-05 11:49 ` Andi Kleen
2010-01-05 2:15 ` [PATCH] [5/9] SYSCTL: Add call_usermodehelper_cleanup() Andi Kleen
2010-01-05 2:15 ` Andi Kleen [this message]
2010-01-05 2:15 ` [PATCH] [7/9] SYSCTL: Convert poweroff_command to proc_rcu_string Andi Kleen
2010-01-05 2:15 ` [PATCH] [8/9] SYSCTL: Convert hotplug helper string to proc_rcu_string() Andi Kleen
2010-01-05 2:15 ` [PATCH] [9/9] SYSCTL: Use RCU protected sysctl for ocfs group add helper Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100105021531.3919FB17C2@basil.firstfloor.org \
--to=andi@firstfloor.org \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox