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
1212 #include <linux/pid_namespace.h>
1313 #include <linux/file.h>
1414 #include <linux/ctype.h>
15+#include <linux/netdevice.h>
1516
1617 #ifdef CONFIG_SYSCTL_SYSCALL
1718
@@ -1250,9 +1251,12 @@ out: · 1232 unmodified lines
12501251 static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
12511252 {
12521253 const struct bin_table *table = &bin_root_table[0];
1253− struct net *net = current->nsproxy->net_ns;
12541254 int ctl_name;
12551255
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+ */
12561260 memcpy(path, "sys/", 4);
12571261 path += 4;
12581262
@@ -1263,30 +1267,31 @@ repeat: · 4 unmodified lines
12631267 name++;
12641268 nlen--;
12651269 for ( ; table->convert; table++) {
1266− struct net_device *dev = NULL;
1267− const char *procname = NULL;
1270+ int len = 0;
12681271
12691272 /* Use the well known sysctl number to proc name mapping */
1270− if (ctl_name == table->ctl_name)
1271− procname = table->procname;
1272−
1273+ if (ctl_name == table->ctl_name) {
1274+ len = strlen(table->procname);
1275+ memcpy(path, table->procname, len);
1276+ }
1277+#ifdef CONFIG_NET
12731278 /*
12741279 * For a wild card entry map from ifindex to network
12751280 * device name.
12761281 */
12771282 else if (!table->ctl_name) {
1283+ struct net *net = current->nsproxy->net_ns;
1284+ struct net_device *dev;
12781285 dev = dev_get_by_index(net, ctl_name);
1279− if (dev)
1280− procname = dev->name;
1286+ if (dev) {
1287+ len = strlen(dev->name);
1288+ memcpy(path, dev->name, len);
1289+ dev_put(dev);
1290+ }
12811291 }
1282− if (procname) {
1283− int len;
1284−
1285− len = strlen(procname);
1286− memcpy(path, procname, len);
1292+#endif
1293+ if (len) {
12871294 path += len;
1288− if (dev)
1289− dev_put(dev);
12901295 if (table->child) {
12911296 *path++ = '/';
12921297 table = table->child;