Skip to contentSkip to conversation

: ipset kernel memory allocations

PATCH In review Jones Desougi 2 participants 2 messages Nov 18, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : ipset kernel memory allocations

Hi,

The kernel ipset code in patch-o-matic-ng has code like this in three places:

tmp = kmalloc(...);
if (!map) { ... }

i.e. checking the wrong variable. Map cannot be false here, it is used in the size calculation for kmalloc. Probably all of these originate from a single source. The patch below fixes them.

/Jones

set/linux/net/ipv4/netfilter/ip_set_iphash.c +1 -1
Index: patchlets/set/linux/net/ipv4/netfilter/ip_set_iphash.c
===================================================================
@@ -171,7 +171,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_iphash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_iphash)
 		   + map->probes * sizeof(uint32_t));
set/linux/net/ipv4/netfilter/ip_set_ipporthash.c +1 -1
Index: patchlets/set/linux/net/ipv4/netfilter/ip_set_ipporthash.c
===================================================================
@@ -270,7 +270,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_ipporthash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_ipporthash)
 		   + map->probes * sizeof(uint32_t));
set/linux/net/ipv4/netfilter/ip_set_nethash.c +1 -1
Index: patchlets/set/linux/net/ipv4/netfilter/ip_set_nethash.c
===================================================================
@@ -234,7 +234,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_nethash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_nethash)
 		   + map->probes * sizeof(uint32_t));
set/linux-2.6/net/ipv4/netfilter/ip_set_iphash.c +1 -1
Index: patchlets/set/linux-2.6/net/ipv4/netfilter/ip_set_iphash.c
===================================================================
@@ -170,7 +170,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_iphash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_iphash)
 		   + map->probes * sizeof(uint32_t));
set/linux-2.6/net/ipv4/netfilter/ip_set_ipporthash.c +1 -1
Index: patchlets/set/linux-2.6/net/ipv4/netfilter/ip_set_ipporthash.c
===================================================================
@@ -269,7 +269,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_ipporthash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_ipporthash)
 		   + map->probes * sizeof(uint32_t));
set/linux-2.6/net/ipv4/netfilter/ip_set_nethash.c +1 -1
Index: patchlets/set/linux-2.6/net/ipv4/netfilter/ip_set_nethash.c
===================================================================
@@ -233,7 +233,7 @@
 
 	tmp = kmalloc(sizeof(struct ip_set_nethash) 
 		      + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-	if (!map) {
+	if (!tmp) {
 		DP("out of memory for %d bytes",
 		   sizeof(struct ip_set_nethash)
 		   + map->probes * sizeof(uint32_t));
#1 lore raw
Quoted 10 lines · Jones Desougi

The kernel ipset code in patch-o-matic-ng has code like this in three places:

tmp = kmalloc(...);
if (!map) { ... }

i.e. checking the wrong variable. Map cannot be false here, it is used in the size calculation for kmalloc. Probably all of these originate from a single source. The patch below fixes them.

Nice example of a copy-paste bug handed down from one module to the next one :-(. Thank you the good catch and the patch!

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