aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sysctl_binary.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2009-11-12 03:35:55 -0500
committerEric W. Biederman <ebiederm@xmission.com>2009-11-12 04:25:43 -0500
commit63395b65972c07edce595c9cc8a983016738cdac (patch)
tree4ba406874098df734119d282ba634337c7541ba2 /kernel/sysctl_binary.c
parent2fb10732c3b3c9671b1a391996ce7e551876c25e (diff)
sysctl: sysctl_binary.c Fix compilation when !CONFIG_NET
dev_get_by_index does not exist when the network stack is not compiled in, so only include the code to follow wild card paths when the network stack is present. I have shuffled the code around a little to make it clear that dev_put is called after dev_get_by_index showing that there is no leak. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'kernel/sysctl_binary.c')
-rw-r--r--kernel/sysctl_binary.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index bf0a4b06782a..0cf60400542d 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -12,6 +12,7 @@
12#include <linux/pid_namespace.h> 12#include <linux/pid_namespace.h>
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/netdevice.h>
15 16
16#ifdef CONFIG_SYSCTL_SYSCALL 17#ifdef CONFIG_SYSCTL_SYSCALL
17 18
@@ -1250,9 +1251,12 @@ out:
1250static const struct bin_table *get_sysctl(const int *name, int nlen, char *path) 1251static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
1251{ 1252{
1252 const struct bin_table *table = &bin_root_table[0]; 1253 const struct bin_table *table = &bin_root_table[0];
1253 struct net *net = current->nsproxy->net_ns;
1254 int ctl_name; 1254 int ctl_name;
1255 1255
1256 /* The binary sysctl tables have a small maximum depth so
1257 * there is no danger of overflowing our path as it PATH_MAX
1258 * bytes long.
1259 */
1256 memcpy(path, "sys/", 4); 1260 memcpy(path, "sys/", 4);
1257 path += 4; 1261 path += 4;
1258 1262
@@ -1263,30 +1267,31 @@ repeat:
1263 name++; 1267 name++;
1264 nlen--; 1268 nlen--;
1265 for ( ; table->convert; table++) { 1269 for ( ; table->convert; table++) {
1266 struct net_device *dev = NULL; 1270 int len = 0;
1267 const char *procname = NULL;
1268 1271
1269 /* Use the well known sysctl number to proc name mapping */ 1272 /* Use the well known sysctl number to proc name mapping */
1270 if (ctl_name == table->ctl_name) 1273 if (ctl_name == table->ctl_name) {
1271 procname = table->procname; 1274 len = strlen(table->procname);
1272 1275 memcpy(path, table->procname, len);
1276 }
1277#ifdef CONFIG_NET
1273 /* 1278 /*
1274 * For a wild card entry map from ifindex to network 1279 * For a wild card entry map from ifindex to network
1275 * device name. 1280 * device name.
1276 */ 1281 */
1277 else if (!table->ctl_name) { 1282 else if (!table->ctl_name) {
1283 struct net *net = current->nsproxy->net_ns;
1284 struct net_device *dev;
1278 dev = dev_get_by_index(net, ctl_name); 1285 dev = dev_get_by_index(net, ctl_name);
1279 if (dev) 1286 if (dev) {
1280 procname = dev->name; 1287 len = strlen(dev->name);
1288 memcpy(path, dev->name, len);
1289 dev_put(dev);
1290 }
1281 } 1291 }
1282 if (procname) { 1292#endif
1283 int len; 1293 if (len) {
1284
1285 len = strlen(procname);
1286 memcpy(path, procname, len);
1287 path += len; 1294 path += len;
1288 if (dev)
1289 dev_put(dev);
1290 if (table->child) { 1295 if (table->child) {
1291 *path++ = '/'; 1296 *path++ = '/';
1292 table = table->child; 1297 table = table->child;