Commit 63395b65972c07edce595c9cc8a983016738cdac

Authored by Eric W. Biederman
1 parent 2fb10732c3

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>

Showing 1 changed file with 20 additions and 15 deletions Side-by-side Diff

kernel/sysctl_binary.c
... ... @@ -12,6 +12,7 @@
12 12 #include <linux/pid_namespace.h>
13 13 #include <linux/file.h>
14 14 #include <linux/ctype.h>
  15 +#include <linux/netdevice.h>
15 16  
16 17 #ifdef CONFIG_SYSCTL_SYSCALL
17 18  
18 19  
... ... @@ -1250,9 +1251,12 @@
1250 1251 static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
1251 1252 {
1252 1253 const struct bin_table *table = &bin_root_table[0];
1253   - struct net *net = current->nsproxy->net_ns;
1254 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 1260 memcpy(path, "sys/", 4);
1257 1261 path += 4;
1258 1262  
1259 1263  
1260 1264  
1261 1265  
1262 1266  
1263 1267  
... ... @@ -1263,30 +1267,31 @@
1263 1267 name++;
1264 1268 nlen--;
1265 1269 for ( ; table->convert; table++) {
1266   - struct net_device *dev = NULL;
1267   - const char *procname = NULL;
  1270 + int len = 0;
1268 1271  
1269 1272 /* 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
1273 1278 /*
1274 1279 * For a wild card entry map from ifindex to network
1275 1280 * device name.
1276 1281 */
1277 1282 else if (!table->ctl_name) {
  1283 + struct net *net = current->nsproxy->net_ns;
  1284 + struct net_device *dev;
1278 1285 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 + }
1281 1291 }
1282   - if (procname) {
1283   - int len;
1284   -
1285   - len = strlen(procname);
1286   - memcpy(path, procname, len);
  1292 +#endif
  1293 + if (len) {
1287 1294 path += len;
1288   - if (dev)
1289   - dev_put(dev);
1290 1295 if (table->child) {
1291 1296 *path++ = '/';
1292 1297 table = table->child;