net/ipv4/fib_hash.c: check kmem_cache_create()
Subsystems (3)
From: Francois Romieu <[email protected]>
kmem_cache_create leak.
Note: fib_hash_init() can be called many times.
---
linux-2.6.7-max/net/ipv4/fib_hash.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
net/ipv4/fib_hash.c renamed from net/ipv4/fib_hash.c~ipv4_fib_hash_check +14 -5
@@ -871,15 +871,18 @@ struct fib_table * __init fib_hash_init( {struct fib_table *tb; -if (fn_hash_kmem ==NULL ) + tb =kmalloc (sizeof (struct fib_table ) +sizeof (struct fn_hash ),GFP_KERNEL ); +if (!tb) + goto err_out; + +if (!fn_hash_kmem) { fn_hash_kmem =kmem_cache_create ("ip_fib_hash" ,sizeof (struct fib_node ),0 ,SLAB_HWCACHE_ALIGN ,NULL ,NULL ); - - tb =kmalloc (sizeof (struct fib_table ) +sizeof (struct fn_hash ),GFP_KERNEL ); -if (tb ==NULL ) -return NULL ; +if (!fn_hash_kmem) + goto err_free; + } tb->tb_id = id; tb->tb_lookup = fn_hash_lookup;
@@ -889,7 +892,13 @@ struct fib_table * __init fib_hash_init( tb->tb_select_default = fn_hash_select_default; tb->tb_dump = fn_hash_dump;memset (tb->tb_data,0 ,sizeof (struct fn_hash )); +err_out:return tb; + +err_free: +kfree (tb); + tb =NULL ; + goto err_out; }/* ------------------------------------------------------------------------ */
_
In article <[email protected]> (at Mon, 21 Jun 2004 19:18:32 +0200), maximilian attems <[email protected]> says:
Quoted 7 lines
From: Francois Romieu <[email protected]>
kmem_cache_createleak.Note:
fib_hash_init()can be called many times.Signed-off-by Maximilian Attems <[email protected]>
Please tell us what kind of leakage do you see?
Is it just enough to return NULL if kmem_cache_create() fails like this?
net/ipv4/fib_hash.c +4 -2
@@ -871,12 +871,14 @@ {struct fib_table *tb; -if (fn_hash_kmem ==NULL ) +if (fn_hash_kmem ==NULL ) { fn_hash_kmem =kmem_cache_create ("ip_fib_hash" ,sizeof (struct fib_node ),0 ,SLAB_HWCACHE_ALIGN ,NULL ,NULL ); - +if (fn_hash_kmem ==NULL ) +return NULL ; + } tb =kmalloc (sizeof (struct fib_table ) +sizeof (struct fn_hash ),GFP_KERNEL );if (tb ==NULL )return NULL ;
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]> GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
Quoted 23 lines · On Tue, 22 Jun 2004, YOSHIFUJI Hideaki / ?$B5HF#1QL@ wrote:
In article <[email protected]> (at Mon, 21 Jun 2004 19:18:32 +0200), maximilian attems <[email protected]> says:
Quoted 7 lines
From: Francois Romieu <[email protected]>
kmem_cache_createleak.Note:
fib_hash_init()can be called many times.Signed-off-by Maximilian Attems <[email protected]>Please tell us what kind of leakage do you see?
Is it just enough to return NULL ifkmem_cache_create()fails like this?net/ipv4/fib_hash.c +1
-1@@ -871,12 +871,14 @@ {struct fib_table *tb; -if (fn_hash_kmem ==NULL ) +if (fn_hash_kmem ==NULL ) { fn_hash_kmem = kmem_cache_create("ip_fib_hash",
net/ipv4/fib_hash.c line 884
Quoted 10 lines
net/ipv4/fib_hash.c +3
-1sizeof (struct fib_node ),0 ,SLAB_HWCACHE_ALIGN , NULL, NULL); - +if (fn_hash_kmem ==NULL ) +return NULL ; + } tb =kmalloc (sizeof (struct fib_table ) +sizeof (struct fn_hash ),GFP_KERNEL );if (tb ==NULL )return NULL ;
doesn't seem to be enough,
because if (tb == NULL) fn_hash_kmem won't be freed, or am i overseeing something?
a++ maks
In article <[email protected]> (at Mon, 21 Jun 2004 22:04:20 +0200), maximilian attems <[email protected]> says:
Quoted 3 lines
doesn't seem to be enough,
because if (tb == NULL)fn_hash_kmemwon't be freed, or am i overseeing something?
I believe fn_hash_kmem is not required to (and should not) be freed even if kmalloc() fails for the new table.
Users in existing table should be able to continue using fn_hash_kmem.
--yoshfuji