From patchwork Wed Sep 8 03:00:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12480079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88D32C433F5 for ; Wed, 8 Sep 2021 03:01:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51B456109F for ; Wed, 8 Sep 2021 03:01:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 51B456109F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EE47C940065; Tue, 7 Sep 2021 23:01:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9378940042; Tue, 7 Sep 2021 23:01:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAAC3940065; Tue, 7 Sep 2021 23:01:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id CC404940042 for ; Tue, 7 Sep 2021 23:01:34 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8F9E98249980 for ; Wed, 8 Sep 2021 03:01:34 +0000 (UTC) X-FDA: 78562905708.17.10DEC1C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf30.hostedemail.com (Postfix) with ESMTP id 388E0E00198C for ; Wed, 8 Sep 2021 03:00:34 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 34ACB61100; Wed, 8 Sep 2021 03:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1631070033; bh=k0D6Llvti4CGdvXoX7LC2nA6KQX7y4PlB2tB4YaUi9k=; h=Date:From:To:Subject:In-Reply-To:From; b=WXm+79qaWjhZZKJBhzkXYxsrlAJv9T52lKscVhqgkhsZtcMDfLkH329NHRbfo7rb1 FoUah9iBw2baCiej7Ro8fty9ecx/N1R+RANxhd7dgTotvEK8sUA2Xe3yRxm3az4FLm rls5Z/aHiNURNxlp1V/71PzMOw5pjzGP3sLd4oow= Date: Tue, 07 Sep 2021 20:00:32 -0700 From: Andrew Morton To: akpm@linux-foundation.org, gregkh@linuxfoundation.org, jannh@google.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, qiuxi1@huawei.com, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Subject: [patch 138/147] coredump: fix memleak in dump_vma_snapshot() Message-ID: <20210908030032.ciB5RdV6g%akpm@linux-foundation.org> In-Reply-To: <20210907195226.14b1d22a07c085b22968b933@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 388E0E00198C Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WXm+79qa; dmarc=none; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam01 X-Stat-Signature: sbh1w8r4s8dnkadt5gyegr7371u8nhgg X-HE-Tag: 1631070034-469506 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: QiuXi Subject: 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 --- fs/coredump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/coredump.c~coredump-fix-memleak-in-dump_vma_snapshot +++ a/fs/coredump.c @@ -1134,8 +1134,10 @@ int dump_vma_snapshot(struct coredump_pa 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;