Skip to contentSkip to conversation

ipset: usage of unitialized variable ip_to in ip_set_hash_ipportnet.c

DISCUSSION Witold Baryluk 3 participants 6 messages Nov 7, 2011 – Nov 9, 2011 netfilter

lore
Share & tools
lore
#0 lore raw

Hello,

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ‘hash_ipportnet4_uadt’:
include/net/tcp.h:266:28: warning: ‘ip_to’ may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ‘ip_to’ was declared here

I think this should be fixed be properly initializing / using ip_to, or by telling compiler that some of paths will end in initialization.

Also why on earth a before(a,b) function is used
to compare IP addresses? Shouldn't before(seq1,seq2) function be used only to compare TCP sequnce numbers?!

Regards,
Witek

Signature · 6 lines
Witold Baryluk
JID: witold.baryluk // jabster.pl
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

Hi,

Quoted 6 lines · Witold Baryluk

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {
Quoted 7 lines

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ?hash_ipportnet4_uadt?:
include/net/tcp.h:266:28: warning: ?ip_to? may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ?ip_to? was declared here

Which ipset version you are looking at? What gcc version are you running?

ip_to is explicitly initialized to zero in line 187 in the current ipset version.

Quoted 6 lines

I think this should be fixed be properly initializing / using ip_to, or by telling compiler that some of paths will end in initialization.

Also why on earth a before(a,b) function is used
to compare IP addresses? Shouldn't before(seq1,seq2) function be used only to compare TCP sequnce numbers?!

That's a quick way to avoid wraparound in the for loop.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#2 lore raw
Quoted 13 lines · Jozsef Kadlecsik

Hi,

Quoted 9 lines · Witold Baryluk

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

Quoted 6 lines
Quoted 4 lines

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ?hash_ipportnet4_uadt?:
include/net/tcp.h:266:28: warning: ?ip_to? may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ?ip_to? was declared here

Which ipset version you are looking at? What gcc version are you running?

Hi,

sorry to not mention it.

I'm compiling on 32-bit Intel x86, using gcc 4.6.2-4 with -march=pentium-m. I'm using current/today mainline Linus' tree.
Last significant ipset change in this tree is from Jul 21, 2011.

Quoted 4 lines

ip_to is explicitly initialized to zero in line 187 in the current ipset version.

Quoted 9 lines
Quoted 6 lines

I think this should be fixed be properly initializing / using ip_to, or by telling compiler that some of paths will end in initialization.

Also why on earth a before(a,b) function is used
to compare IP addresses? Shouldn't before(seq1,seq2) function be used only to compare TCP sequnce numbers?!

That's a quick way to avoid wraparound in the for loop.

It's somehow ugly. I agree that same method should be used, but this just leaks a abstraction and who knows in the future if this will not make problems.

Regards,
WItek

Signature · 2 lines
Witold Baryluk
JID: witold.baryluk // jabster.pl
#3 lore raw
Quoted 18 lines · Witold Baryluk
Quoted 17 lines · Jozsef Kadlecsik
Quoted 13 lines · Witold Baryluk

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ?hash_ipportnet4_uadt?:
include/net/tcp.h:266:28: warning: ?ip_to? may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ?ip_to? was declared here

Quoted 7 lines
Quoted 1 line

Which ipset version you are looking at? What gcc version are you running?

sorry to not mention it.

I'm compiling on 32-bit Intel x86, using gcc 4.6.2-4 with -march=pentium-m. I'm using current/today mainline Linus' tree.
Last significant ipset change in this tree is from Jul 21, 2011.

Oops, that patch was not submitted to kernel inclusion. The merge window has just opened up, I'm going to send it in the next day.

Quoted 10 lines
Quoted 10 lines

ip_to is explicitly initialized to zero in line 187 in the current ipset version.

Quoted 6 lines

I think this should be fixed be properly initializing / using ip_to, or by telling compiler that some of paths will end in initialization.

Also why on earth a before(a,b) function is used
to compare IP addresses? Shouldn't before(seq1,seq2) function be used only to compare TCP sequnce numbers?!

Quoted 5 lines
Quoted 1 line

That's a quick way to avoid wraparound in the for loop.

It's somehow ugly. I agree that same method should be used, but this just leaks a abstraction and who knows in the future if this will not make problems.

The net/tcp.h header file says

/*
* The next routines deal with comparing 32 bit unsigned ints
* and worry about wraparound (automatic with unsigned arithmetic). */

static inline int before(__u32 seq1, __u32 seq2)
...

Neither the comment, nor the function names imply that the routines should be used only for TCP sequence numbers.

Maybe the routines should be relocated into a more generic header file.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#4 lore raw
Quoted 22 lines · Jozsef Kadlecsik
Quoted 20 lines · Witold Baryluk
Quoted 18 lines · Jozsef Kadlecsik
Quoted 6 lines · Witold Baryluk

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {
Quoted 7 lines

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ?hash_ipportnet4_uadt?:
include/net/tcp.h:266:28: warning: ?ip_to? may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ?ip_to? was declared here

Which ipset version you are looking at? What gcc version are you running?

Quoted 8 lines
Quoted 5 lines

sorry to not mention it.

I'm compiling on 32-bit Intel x86, using gcc 4.6.2-4 with -march=pentium-m. I'm using current/today mainline Linus' tree.
Last significant ipset change in this tree is from Jul 21, 2011.

Oops, that patch was not submitted to kernel inclusion. The merge window has just opened up, I'm going to send it in the next day.

I'll be happy to take that patch.

#5 lore raw
Quoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · Jozsef Kadlecsik
Quoted 22 lines · Witold Baryluk
Quoted 12 lines · Jozsef Kadlecsik
Quoted 9 lines · Witold Baryluk

in file et/netfilter/ipset/ip_set_hash_ipportnet.c in functionhash_ipportnet4_uadt(...) variable u32 ip_to, can be used uninitialized in line 283

	for (; !before(ip_to, ip); ip++) {

because, if both tb[IPSET_ATTR_IP_TO] and tb[IPSET_ATTR_CIDR] are false, then there is no initialization of ip_to.

Quoted 6 lines
Quoted 4 lines

CC [M] net/netfilter/ipset/ip_set_hash_ipportnet.o
net/netfilter/ipset/ip_set_hash_ipportnet.c: In function ?hash_ipportnet4_uadt?:
include/net/tcp.h:266:28: warning: ?ip_to? may be used uninitialized in this function [-Wuninitialized] net/netfilter/ipset/ip_set_hash_ipportnet.c:187:10: note: ?ip_to? was declared here

Which ipset version you are looking at? What gcc version are you running?

sorry to not mention it.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I'm compiling on 32-bit Intel x86, using gcc 4.6.2-4 with -march=pentium-m. I'm using current/today mainline Linus' tree.
Last significant ipset change in this tree is from Jul 21, 2011.

Oops, that patch was not submitted to kernel inclusion. The merge window has just opened up, I'm going to send it in the next day.

I'll be happy to take that patch.

It's a single patch, I'm sending it separatedly. Thanks!

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary