aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiaotian Feng2012-03-14 09:34:48 -0500
committerJens Axboe2012-03-14 09:34:48 -0500
commitff8c1474cc2f5e11414c71ec4d739c18e6e669c0 (patch)
treed498e6e97243a25d20100b9c5a1cee8c73920fb7 /block/blk-ioc.c
parentea5f4db8ece896c2ab9eafa0924148a2596c52e4 (diff)
downloadkernel-common-ff8c1474cc2f5e11414c71ec4d739c18e6e669c0.tar.gz
kernel-common-ff8c1474cc2f5e11414c71ec4d739c18e6e669c0.tar.xz
kernel-common-ff8c1474cc2f5e11414c71ec4d739c18e6e669c0.zip
block: fix ioc leak in put_io_context
When put_io_context is called, if ioc->icq_list is empty and refcount is 1, kernel will not free the ioc. This is caught by following kmemleak: unreferenced object 0xffff880036349fe0 (size 216): comm "sh", pid 2137, jiffies 4294931140 (age 290579.412s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 01 00 01 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N.......... backtrace: [<ffffffff8169f926>] kmemleak_alloc+0x26/0x50 [<ffffffff81195a9c>] kmem_cache_alloc_node+0x1cc/0x2a0 [<ffffffff81356b67>] create_io_context_slowpath+0x27/0x130 [<ffffffff81356d2b>] get_task_io_context+0xbb/0xf0 [<ffffffff81055f0e>] copy_process+0x188e/0x18b0 [<ffffffff8105609b>] do_fork+0x11b/0x420 [<ffffffff810247f8>] sys_clone+0x28/0x30 [<ffffffff816d3373>] stub_clone+0x13/0x20 [<ffffffffffffffff>] 0xffffffffffffffff ioc should be freed if ioc->icq_list is empty. Signed-off-by: Xiaotian Feng <dannyfeng@tencent.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-ioc.c')
-rw-r--r--block/blk-ioc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index 92bf55540d8..fb95dd2f889 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -130,6 +130,7 @@ static void ioc_release_fn(struct work_struct *work)
130void put_io_context(struct io_context *ioc) 130void put_io_context(struct io_context *ioc)
131{ 131{
132 unsigned long flags; 132 unsigned long flags;
133 bool free_ioc = false;
133 134
134 if (ioc == NULL) 135 if (ioc == NULL)
135 return; 136 return;
@@ -144,8 +145,13 @@ void put_io_context(struct io_context *ioc)
144 spin_lock_irqsave(&ioc->lock, flags); 145 spin_lock_irqsave(&ioc->lock, flags);
145 if (!hlist_empty(&ioc->icq_list)) 146 if (!hlist_empty(&ioc->icq_list))
146 schedule_work(&ioc->release_work); 147 schedule_work(&ioc->release_work);
148 else
149 free_ioc = true;
147 spin_unlock_irqrestore(&ioc->lock, flags); 150 spin_unlock_irqrestore(&ioc->lock, flags);
148 } 151 }
152
153 if (free_ioc)
154 kmem_cache_free(iocontext_cachep, ioc);
149} 155}
150EXPORT_SYMBOL(put_io_context); 156EXPORT_SYMBOL(put_io_context);
151 157