* [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot()
@ 2021-08-10 2:04 QiuXi
2021-08-10 18:56 ` Jann Horn
0 siblings, 1 reply; 2+ messages in thread
From: QiuXi @ 2021-08-10 2:04 UTC (permalink / raw)
To: viro, akpm, jannh, linux-fsdevel, linux-kernel
Cc: gregkh, xiekunxun, young.liuyang
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: stable@vger.kernel.org # v5.10
Signed-off-by: QiuXi <qiuxi1@huawei.com>
---
fs/coredump.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/coredump.c b/fs/coredump.c
index 07afb5ddb1c4..19fe5312c10f 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot()
2021-08-10 2:04 [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot() QiuXi
@ 2021-08-10 18:56 ` Jann Horn
0 siblings, 0 replies; 2+ messages in thread
From: Jann Horn @ 2021-08-10 18:56 UTC (permalink / raw)
To: QiuXi
Cc: viro, akpm, linux-fsdevel, linux-kernel, gregkh, xiekunxun,
young.liuyang
On Tue, Aug 10, 2021 at 4:04 AM QiuXi <qiuxi1@huawei.com> wrote:
> dump_vma_snapshot() allocs memory for *vma_meta, when dump_vma_snapshot()
> returns -EFAULT, the memory will be leaked, so we free it correctly.
The change itself looks reasonable to me.
> Fixes: a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot")
> Cc: stable@vger.kernel.org # 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.
> Signed-off-by: QiuXi <qiuxi1@huawei.com>
> ---
> fs/coredump.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index 07afb5ddb1c4..19fe5312c10f 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-08-10 18:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 2:04 [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot() QiuXi
2021-08-10 18:56 ` Jann Horn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).