Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3273656pxt; Mon, 9 Aug 2021 22:52:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9mBP/WFrsj37WURslkkcTXSlZ0im1JwjZcZhQBIqHKWN0JuujOjvkBkVy/paMTDcdVKWt X-Received: by 2002:a17:907:2d0f:: with SMTP id gs15mr23185853ejc.23.1628574726227; Mon, 09 Aug 2021 22:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628574726; cv=none; d=google.com; s=arc-20160816; b=OCvvSoJXrRiFIP/jiNaN406W0CWviVi3oIatzD2p/cqHG39YTHC8jctqOC4lMENu/k uQoOKXzcjxt2mLSMx/PL5HXSWY7W3GjrA9eh7KgonssatRfOlEnm06KKu26RDowmVn2P 96bEP0Of+PK1DwurIyuuElS90X1jArfQ7E3F/kAOqJk7O5v+nf6Nt6xEL6qqX7sKCZm+ +BMIITmINBFDQn3eFEKYtbOSpnd6b+pZ3NTVWy84iuPq/Ni5dy6awokZaIhhWQovN2RC Bf0EMVYfbJ5jBNjmKICVLZZ5RsIjUrUzHJxmGbP21HYoOgI7CEG62JTqMAPVtcr9Rh2p el+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=R+84kWv6TU/SmLeN0hMmN79GR2p8XHCPq/83iZLP5KQ=; b=yNcVk1DBBjSw5R8nq/G40pzVaaYkQ5wP66ZWiwGEYDXxCdjvvc5a3NVPidBI4ErYYx 8+6Gl7us8fj+B3MkH6HfUNx0XqhyfP96vaKqBlxnM6xri0x1P3JHlVW8ZghU2BE5pAUy A12KAcCu+K53sQdUBvhEAZFkbaHUkHmWZ7+uXcs5gVtBlhPfnwysbzV7pleYNBxF3xf1 bPbsSzYtJTCoqNYhQoYAlSq6tYvF15H4NLbwL5xdyUGC3AwIbKSZ3CZiK3VJwwrYX2Bq U6oSap1U8WLs0ubaWZPo0wwisvUqG1sghFPMpDFmN6I7buVkBwd55WyeIyK0FTDPaItK ULlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si21021098edp.87.2021.08.09.22.51.41; Mon, 09 Aug 2021 22:52:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237308AbhHJCFL (ORCPT + 99 others); Mon, 9 Aug 2021 22:05:11 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:13408 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231716AbhHJCFK (ORCPT ); Mon, 9 Aug 2021 22:05:10 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GkGQF3rqLzcmH6; Tue, 10 Aug 2021 10:01:09 +0800 (CST) Received: from dggpeml500013.china.huawei.com (7.185.36.41) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 10 Aug 2021 10:04:47 +0800 Received: from huawei.com (10.67.189.17) by dggpeml500013.china.huawei.com (7.185.36.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 10 Aug 2021 10:04:47 +0800 From: QiuXi To: , , , , CC: , , Subject: [PATCH 1/1] coredump: fix memleak in dump_vma_snapshot() Date: Tue, 10 Aug 2021 10:04:41 +0800 Message-ID: <20210810020441.62806-1-qiuxi1@huawei.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.17] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500013.china.huawei.com (7.185.36.41) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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