netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipcomp: double free at ipcomp_destroy()
@ 2010-02-14 14:44 Alexey Dobriyan
  2010-02-15  0:18 ` Herbert Xu
  0 siblings, 1 reply; 12+ messages in thread
From: Alexey Dobriyan @ 2010-02-14 14:44 UTC (permalink / raw)
  To: davem; +Cc: netdev, herbert

Consider using ipcomp with tunnel mode:

	pfkey_add -> xfrm_state_init -> x->type->init_state() == ipcomp4_init_state

1. If ipcomp_tunnel_attach() fails, xfrm_state private data (x->data) are freed
   first time (synchronously), but stale pointer is left.
2. xfrm_state_init() failed, all right, we're going to do error unwind
   but this time asynchronously and we're going to double free x->data
   asynchronously.

Fix by clearing x->data pointer, so second time it'll be fine.

Note, second time can happen in quite arbitrary time, double free
messages were seen in completely irrelevant functions, e. g. 

	INFO: Allocated in icmp_sk_init
	INFO: Freed in icmp_sk_exit

	[<ffffffff810b5ceb>] kfree+0xab/0x140
	[<ffffffff810719ae>] free_sect_attrs	(!)
	[<ffffffff81072353>] free_module

The only common thing was kmalloc-16 cache.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 net/xfrm/xfrm_ipcomp.c |    1 +
 1 file changed, 1 insertion(+)

--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -332,6 +332,7 @@ void ipcomp_destroy(struct xfrm_state *x)
 	ipcomp_free_data(ipcd);
 	mutex_unlock(&ipcomp_resource_mutex);
 	kfree(ipcd);
+	x->data = NULL;
 }
 EXPORT_SYMBOL_GPL(ipcomp_destroy);
 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-02-16 23:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-14 14:44 [PATCH] ipcomp: double free at ipcomp_destroy() Alexey Dobriyan
2010-02-15  0:18 ` Herbert Xu
2010-02-15  7:32   ` Alexey Dobriyan
2010-02-15  8:08     ` Herbert Xu
2010-02-15  8:10       ` Herbert Xu
2010-02-15 15:50         ` Alexey Dobriyan
2010-02-16  5:29           ` Herbert Xu
2010-02-15 17:28         ` Alexey Dobriyan
2010-02-16  5:24           ` Herbert Xu
2010-02-16 23:14             ` David Miller
2010-02-16  6:00       ` Herbert Xu
2010-02-16 23:14         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).