From: QiuXi Date: Wed, 8 Sep 2021 03:00:32 +0000 (-0700) Subject: coredump: fix memleak in dump_vma_snapshot() X-Git-Tag: accepted/tizen/unified/20230118.172025~6428^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fcac87e1f9e5b27805a2a404f4849194bb51de8;p=platform%2Fkernel%2Flinux-rpi.git coredump: fix memleak in dump_vma_snapshot() 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: a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot") Signed-off-by: QiuXi Cc: Al Viro Cc: Jann Horn Cc: Greg Kroah-Hartman Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/fs/coredump.c b/fs/coredump.c index 4b3c757..3224dee 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -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;