Skip to content

Commit

Permalink
coredump: fix memleak in dump_vma_snapshot()
Browse files Browse the repository at this point in the history
dump_vma_snapshot() allocs memory for *vma_meta, when dump_vma_snapshot()
returns -EFAULT, the memory will be leaked, so we free it correctly.

Link: https://lkml.kernel.org/r/20210810020441.62806-1-qiuxi1@huawei.com
Fixes: a07279c ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot")
Signed-off-by: QiuXi <qiuxi1@huawei.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jann Horn <jannh@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
  • Loading branch information
QiuXi authored and Stephen Rothwell committed Aug 25, 2021
1 parent e7b81ca commit 6b33bde
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,10 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,

mmap_write_unlock(mm);

if (WARN_ON(i != *vma_count))
if (WARN_ON(i != *vma_count)) {
kvfree(*vma_meta);
return -EFAULT;
}

*vma_data_size_ptr = vma_data_size;
return 0;
Expand Down

0 comments on commit 6b33bde

Please sign in to comment.