Skip to content

Commit 757010f

Browse files
committed
sysctl binary: Reorder the tests to process wild card entries first.
A malicious user could have passed in a ctl_name of 0 and triggered the well know ctl_name to procname mapping code, instead of the wild card matching code. This is a slight problem as wild card entries don't have procnames, and because in some alternate universe a network device might have ifindex 0. So test for and handle wild card entries first. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
1 parent 63395b6 commit 757010f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

kernel/sysctl_binary.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,17 +1269,12 @@ static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
12691269
for ( ; table->convert; table++) {
12701270
int len = 0;
12711271

1272-
/* Use the well known sysctl number to proc name mapping */
1273-
if (ctl_name == table->ctl_name) {
1274-
len = strlen(table->procname);
1275-
memcpy(path, table->procname, len);
1276-
}
1277-
#ifdef CONFIG_NET
12781272
/*
12791273
* For a wild card entry map from ifindex to network
12801274
* device name.
12811275
*/
1282-
else if (!table->ctl_name) {
1276+
if (!table->ctl_name) {
1277+
#ifdef CONFIG_NET
12831278
struct net *net = current->nsproxy->net_ns;
12841279
struct net_device *dev;
12851280
dev = dev_get_by_index(net, ctl_name);
@@ -1288,8 +1283,12 @@ static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
12881283
memcpy(path, dev->name, len);
12891284
dev_put(dev);
12901285
}
1291-
}
12921286
#endif
1287+
/* Use the well known sysctl number to proc name mapping */
1288+
} else if (ctl_name == table->ctl_name) {
1289+
len = strlen(table->procname);
1290+
memcpy(path, table->procname, len);
1291+
}
12931292
if (len) {
12941293
path += len;
12951294
if (table->child) {

0 commit comments

Comments
 (0)