add patch create-function-to-read-journal-inode
[ext4-patch-queue.git] / fix-memory-leak-in-ext4_insert_range
blob8ab66d5f5cba6a00f10b2a4b9da9e868adca3928
1 From: Fabian Frederick <fabf@skynet.be>
3 ext4: fix memory leak in ext4_insert_range()
5 Running xfstests generic/013 with kmemleak gives the following:
7 unreferenced object 0xffff8801d3d27de0 (size 96):
8   comm "fsstress", pid 4941, jiffies 4294860168 (age 53.485s)
9   hex dump (first 32 bytes):
10     00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00  ................
11     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
12   backtrace:
13     [<ffffffff818eaaf3>] kmemleak_alloc+0x23/0x40
14     [<ffffffff81179805>] __kmalloc+0xf5/0x1d0
15     [<ffffffff8122ef5c>] ext4_find_extent+0x1ec/0x2f0
16     [<ffffffff8123530c>] ext4_insert_range+0x34c/0x4a0
17     [<ffffffff81235942>] ext4_fallocate+0x4e2/0x8b0
18     [<ffffffff81181334>] vfs_fallocate+0x134/0x210
19     [<ffffffff8118203f>] SyS_fallocate+0x3f/0x60
20     [<ffffffff818efa9b>] entry_SYSCALL_64_fastpath+0x13/0x8f
21     [<ffffffffffffffff>] 0xffffffffffffffff
23 Problem seems mitigated by dropping refs and freeing path
24 when there's no path[depth].p_ext
26 Signed-off-by: Fabian Frederick <fabf@skynet.be>
27 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
28 ---
29  fs/ext4/extents.c | 3 +++
30  1 file changed, 3 insertions(+)
32 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
33 index 5b0913d..2774df4 100644
34 --- a/fs/ext4/extents.c
35 +++ b/fs/ext4/extents.c
36 @@ -5711,6 +5711,9 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
37                         up_write(&EXT4_I(inode)->i_data_sem);
38                         goto out_stop;
39                 }
40 +       } else {
41 +               ext4_ext_drop_refs(path);
42 +               kfree(path);
43         }
45         ret = ext4_es_remove_extent(inode, offset_lblk,
46 -- 
47 2.8.1