History

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.

Eric W. Biederman committed 17 years ago

Commit 63395b61 parent 2fb10731 file · +20 −15Browse files

Showing the changes to kernel/sysctl_binary.c (1 of 1 file). Show all

Unified · Split

kernel/sysctl_binary.c+20−15
@@ -12,6 +12,7 @@ · 11 unmodified lines
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_SYSCALL17#ifdef CONFIG_SYSCTL_SYSCALL
17 18
@@ -1250,9 +1251,12 @@ out: · 1232 unmodified lines
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: · 4 unmodified lines
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 network1279 * 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;