Skip to contentSkip to conversation

net/ipv4/multipath_wrandom.c: check kmalloc() return value.

PATCH In review Amit Choudhary 3 participants 3 messages Oct 23, 2006

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

PATCH 1/1 net/ipv4/multipath_wrandom.c: check kmalloc() return value.

Description: Check the return value of kmalloc() in function wrandom_set_nhinfo(), in file net/ipv4/multipath_wrandom.c.

net/ipv4/multipath_wrandom.c +7 -0
index 92b0482..bcdb1f1 100644
@@ -242,6 +242,9 @@ static void wrandom_set_nhinfo(__be32 ne
 		target_route = (struct multipath_route *)
 			kmalloc(size_rt, GFP_ATOMIC);
 
+		if (!target_route)
+			goto error;
+
 		target_route->gw = nh->nh_gw;
 		target_route->oif = nh->nh_oif;
 		memset(&target_route->rcu, 0, sizeof(struct rcu_head));
@@ -263,6 +266,9 @@ static void wrandom_set_nhinfo(__be32 ne
 		target_dest = (struct multipath_dest*)
 			kmalloc(size_dst, GFP_ATOMIC);
 
+		if (!target_dest)
+			goto error;
+
 		target_dest->nh_info = nh;
 		target_dest->network = network;
 		target_dest->netmask = netmask;
@@ -275,6 +281,7 @@ static void wrandom_set_nhinfo(__be32 ne
 	 * we are finished
 	 */
 
+ error:
 	spin_unlock_bh(&state[state_idx].lock);
 }
 
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Amit Choudhary

Description: Check the return value of kmalloc() in function wrandom_set_nhinfo(), in file net/ipv4/multipath_wrandom.c.

net/ipv4/multipath_wrandom.c static void wrandom_set_nhinfo(__be32 ne · line 243

Quoted 3 lines
net/ipv4/multipath_wrandom.c +0 -0
@@ -242,6 +242,9 @@ static void wrandom_set_nhinfo(__be32 ne
 		target_route = (struct multipath_route *)
 			kmalloc(size_rt, GFP_ATOMIC);

It'd be nice to see these casts removed in a future cleanup.

- James

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
In reply to Amit Choudhary
Quoted 30 lines · Amit Choudhary

Description: Check the return value of kmalloc() in function wrandom_set_nhinfo(), in file net/ipv4/multipath_wrandom.c.

net/ipv4/multipath_wrandom.c +6 -0
index 92b0482..bcdb1f1 100644
@@ -242,6 +242,9 @@ static void wrandom_set_nhinfo(__be32 ne
 		target_route = (struct multipath_route *)
 			kmalloc(size_rt, GFP_ATOMIC);
 
+		if (!target_route)
+			goto error;
+
 		target_route->gw = nh->nh_gw;
 		target_route->oif = nh->nh_oif;
 		memset(&target_route->rcu, 0, sizeof(struct rcu_head));
@@ -263,6 +266,9 @@ static void wrandom_set_nhinfo(__be32 ne
 		target_dest = (struct multipath_dest*)
 			kmalloc(size_dst, GFP_ATOMIC);
 
+		if (!target_dest)
+			goto error;
+
 
 		target_dest->nh_info = nh;
 		target_dest->network = network;
net/ipv4/multipath_wrandom.c +0 -0
 		target_dest->netmask = netmask;

net/ipv4/multipath_wrandom.c static void wrandom_set_nhinfo(__be32 ne · line 286

Quoted 6 lines
net/ipv4/multipath_wrandom.c +1 -0
@@ -275,6 +281,7 @@ static void wrandom_set_nhinfo(__be32 ne
 	 * we are finished
 	 */
 
+ error:
 	spin_unlock_bh(&state[state_idx].lock);
 }

Thats slightly better than before, but since no errors are propagated back to the routing code I think it would still crash later on. A better idea would be to mark this crap BROKEN until it is really fixed, so people won't accidentally enable it (which is enough to cause problems).

net/ipv4/Kconfig +2 -2
index 5572071..9ff5616 100644
@@ -124,8 +124,8 @@ config IP_ROUTE_MULTIPATH
 	  if a matching packet arrives.
 
 config IP_ROUTE_MULTIPATH_CACHED
-	bool "IP: equal cost multipath with caching support (EXPERIMENTAL)"
-	depends on IP_ROUTE_MULTIPATH
+	bool "IP: equal cost multipath with caching support (BROKEN)"
+	depends on IP_ROUTE_MULTIPATH && BROKEN
 	help
 	  Normally, equal cost multipath routing is not supported by the
 	  routing cache. If you say Y here, alternative routes are cached