coredump: fix memleak in dump_vma_snapshot()
PATCH 1/1 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.
Fixes a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot")
Cc [email protected] # v5.10
Signed-off-by QiuXi <[email protected]>
--- fs/coredump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/coredump.c +3 -1
@@ -1127,8 +1127,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 ;
Signature · 1 line
2.12.3
Quoted 2 lines · QiuXi
dump_vma_snapshot()allocs memory for*vma_meta, whendump_vma_snapshot()returns-EFAULT, the memory will be leaked, so we free it correctly.
The change itself looks reasonable to me.
Quoted 2 lines
Fixes a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot")Cc [email protected] # v5.10
But I think this shouldn't be "Cc: stable". The patch only removes a memory leak in a WARN_ON() path, and that WARN_ON() path can only be taken if there is a kernel bug; if we reach this branch, there's a good chance that kernel memory corruption has already occurred.
Quoted 24 lines
Signed-off-by QiuXi <[email protected]>--- fs/coredump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/coredump.c +3
-2@@ -1127,8 +1127,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 ; --2.12.3