Skip to contentSkip to conversation

devinet: sysctl setup off by one

PATCH David Miller 3 participants 3 messages May 26, 2008 – May 27, 2008 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

David Miller

author maintainer
#1 lore raw
In reply to a message not in the archive

From: Stephen Hemminger <[email protected]>
Date: Fri, 23 May 2008 15:35:59 -0700

Quoted 7 lines

It look like the code to setup /proc/sys/net/ipv4/conf/XXX has an off by one bug that causes the last entry (arp_accept) not to be adjusted properly. This causes changes to the value to occur in the default namespace not the clone? Don't use network namespaces myself, but this looks like a bug.

Yikes, that is a very strange expression to be there by accident.

Pavel, can you take a look at this? Thanks.

#2 lore raw
In reply to a message not in the archive
Quoted 11 lines · Stephen Hemminger

It look like the code to setup /proc/sys/net/ipv4/conf/XXX has an off by one bug that causes the last entry (arp_accept) not to be adjusted properly. This causes changes to the value to occur in the default namespace not the clone? Don't use network namespaces myself, but this looks like a bug.

net/ipv4/devinet.c static int __devinet_sysctl_register(str · line 1472

Quoted 8 lines
net/ipv4/devinet.c +1 -1
@@ -1466,7 +1466,7 @@ static int __devinet_sysctl_register(str
 	if (!t)
 		goto out;
 
-	for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
+	for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) {
 		t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
 		t->devinet_vars[i].extra1 = p;
 		t->devinet_vars[i].extra2 = net;

This off-by-one is required, since the very last element of this array is used as a sentinel, that shows sysctl engine when to stop processing the table.

Look, the sizeof(t->devinet_vars) is __NET_IPV4_CONF_MAX == 22, thus entries 0, 1, ... 20 are tables and the 21-st is this sentinel, so the initialization of this last entry, whose index is (this_sizeof() - 1), is not required.

Thanks,
Pavel

#3 lore raw
Quoted 25 lines · On Mon, 26 May 2008 11:39:21 +0400 Pavel Emelyanov <[email protected]> wrote:
Quoted 11 lines · Stephen Hemminger

It look like the code to setup /proc/sys/net/ipv4/conf/XXX has an off by one bug that causes the last entry (arp_accept) not to be adjusted properly. This causes changes to the value to occur in the default namespace not the clone? Don't use network namespaces myself, but this looks like a bug.

net/ipv4/devinet.c static int __devinet_sysctl_register(str · line 1472

Quoted 8 lines
net/ipv4/devinet.c +1 -1
@@ -1466,7 +1466,7 @@ static int __devinet_sysctl_register(str
 	if (!t)
 		goto out;
 
-	for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
+	for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) {
 		t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
 		t->devinet_vars[i].extra1 = p;
 		t->devinet_vars[i].extra2 = net;

This off-by-one is required, since the very last element of this array is used as a sentinel, that shows sysctl engine when to stop processing the table.

Quoted 7 lines

Look, the sizeof(t->devinet_vars) is __NET_IPV4_CONF_MAX == 22, thus entries 0, 1, ... 20 are tables and the 21-st is this sentinel, so the initialization of this last entry, whose index is (this_sizeof() - 1), is not required.

Thanks,
Pavel

okay, so that means there is one extra entry in the vars than needed? which is harmless.