Skip to content

Commit a74374c

Browse files
Wang Haigregkh
authored andcommitted
dccp: Fix possible memleak in dccp_init and dccp_fini
[ Upstream commit c96b6ac ] There are some memory leaks in dccp_init() and dccp_fini(). In dccp_fini() and the error handling path in dccp_init(), free lhash2 is missing. Add inet_hashinfo2_free_mod() to do it. If inet_hashinfo2_init_mod() failed in dccp_init(), percpu_counter_destroy() should be called to destroy dccp_orphan_count. It need to goto out_free_percpu when inet_hashinfo2_init_mod() failed. Fixes: c92c81d ("net: dccp: fix kernel crash on module load") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Wang Hai <wanghai38@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3e62100 commit a74374c

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎include/net/inet_hashtables.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ static inline spinlock_t *inet_ehash_lockp(
185185

186186
int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo);
187187

188+
static inline void inet_hashinfo2_free_mod(struct inet_hashinfo *h)
189+
{
190+
kfree(h->lhash2);
191+
h->lhash2 = NULL;
192+
}
193+
188194
static inline void inet_ehash_locks_free(struct inet_hashinfo *hashinfo)
189195
{
190196
kvfree(hashinfo->ehash_locks);

‎net/dccp/proto.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,14 @@ static int __init dccp_init(void)
11391139
inet_hashinfo_init(&dccp_hashinfo);
11401140
rc = inet_hashinfo2_init_mod(&dccp_hashinfo);
11411141
if (rc)
1142-
goto out_fail;
1142+
goto out_free_percpu;
11431143
rc = -ENOBUFS;
11441144
dccp_hashinfo.bind_bucket_cachep =
11451145
kmem_cache_create("dccp_bind_bucket",
11461146
sizeof(struct inet_bind_bucket), 0,
11471147
SLAB_HWCACHE_ALIGN, NULL);
11481148
if (!dccp_hashinfo.bind_bucket_cachep)
1149-
goto out_free_percpu;
1149+
goto out_free_hashinfo2;
11501150

11511151
/*
11521152
* Size and allocate the main established and bind bucket
@@ -1242,6 +1242,8 @@ static int __init dccp_init(void)
12421242
free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order);
12431243
out_free_bind_bucket_cachep:
12441244
kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
1245+
out_free_hashinfo2:
1246+
inet_hashinfo2_free_mod(&dccp_hashinfo);
12451247
out_free_percpu:
12461248
percpu_counter_destroy(&dccp_orphan_count);
12471249
out_fail:
@@ -1265,6 +1267,7 @@ static void __exit dccp_fini(void)
12651267
kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
12661268
dccp_ackvec_exit();
12671269
dccp_sysctl_exit();
1270+
inet_hashinfo2_free_mod(&dccp_hashinfo);
12681271
percpu_counter_destroy(&dccp_orphan_count);
12691272
}
12701273

0 commit comments

Comments
 (0)