Skip to contentSkip to conversation

PATCH: Fix poor pointer math in devinet_sysctl_register

PATCH Jordan Crouse 4 participants 5 messages Nov 16, 2005 – Nov 17, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

This patch fixes pointer math that under certain circumstances, results in really bad pointers. This was encountered on a system compiled for i486, so other compilers may differ, but I don't think it hurts anyone.

---

 net/ipv4/devinet.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv4/devinet.c +1 -1
index 4ec4b2c..7585fce 100644
@@ -1454,7 +1454,7 @@ static void devinet_sysctl_register(stru
 		return;
 	memcpy(t, &devinet_sysctl, sizeof(*t));
 	for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
-		t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
+		t->devinet_vars[i].data += (int)((char *)p - (char *)&ipv4_devconf);
 		t->devinet_vars[i].de = NULL;
 	}
 
#1 lore raw
Quoted 11 lines · Jordan Crouse

This patch fixes pointer math that under certain circumstances, results
in really bad pointers. This was encountered on a system compiled for i486, so other compilers may differ, but I don't think it hurts anyone.

---

  net/ipv4/devinet.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 4ec4b2c..7585fce 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1454,7 +1454,7 @@ static void devinet_sysctl_register(stru
return;
memcpy(t, &devinet_sysctl, sizeof(*t));
for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
- t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
+ t->devinet_vars[i].data += (int)((char *)p - (char *)&ipv4_devconf);

Confused. These appear to be equivalent (on 32-bit CPUs, anyway).

maintainer
#2 lore raw

From: Andrew Morton <[email protected]>
Date: Wed, 16 Nov 2005 22:14:12 -0800

Quoted 9 lines
Quoted 6 lines · Jordan Crouse

@@ -1454,7 +1454,7 @@ static void devinet_sysctl_register(stru
return;
memcpy(t, &devinet_sysctl, sizeof(*t));
for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
- t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
+ t->devinet_vars[i].data += (int)((char *)p - (char *)&ipv4_devconf);

Confused. These appear to be equivalent (on 32-bit CPUs, anyway).

Indeed, please describe the exact failure case when posting such patches.

#3 lore raw
In reply to Jordan Crouse
Quoted 15 lines · Jordan Crouse

This patch fixes pointer math that under certain circumstances, results in really bad pointers. This was encountered on a system compiled for i486, so other compilers may differ, but I don't think it hurts anyone.

---

 net/ipv4/devinet.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv4/devinet.c +0 -0
index 4ec4b2c..7585fce 100644

net/ipv4/devinet.c static void devinet_sysctl_register(stru · line 1459

Quoted 7 lines
net/ipv4/devinet.c +1 -1
@@ -1454,7 +1454,7 @@ static void devinet_sysctl_register(stru
 		return;
 	memcpy(t, &devinet_sysctl, sizeof(*t));
 	for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
-		t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
+		t->devinet_vars[i].data += (int)((char *)p - (char *)&ipv4_devconf);
 		t->devinet_vars[i].de = NULL;
 	}

This is the same code which broke due to a known gcc-4.0.0 bug:
<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21173>. If you're indeed using gcc-4.0.0, then it's time to upgrade.

/Mikael

#4 lore raw
Quoted 4 lines

This is the same code which broke due to a known gcc-4.0.0 bug:
<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21173>. If you're indeed using gcc-4.0.0, then it's time to upgrade.

Indeed, I am using 4.0.0, so may indeed be it. I'll upgrade and take another shot at it.

Thanks,

Jordan

Signature · 4 lines
Jordan Crouse
Senior Linux Engineer
AMD - Personal Connectivity Solutions Group
<www.amd.com/embeddedprocessors>