Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1838900pxb; Fri, 24 Sep 2021 13:11:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9+SN4H5kouSC6WUaRKGMaQEhCq/x8bmuJao2Oy1zKhumYI/dNYAZaVLzfNQ6i1pPc39FV X-Received: by 2002:a17:906:1d41:: with SMTP id o1mr13302930ejh.232.1632514312466; Fri, 24 Sep 2021 13:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632514312; cv=none; d=google.com; s=arc-20160816; b=OvBUxTZrPPEhMltyvnEoQejyWcjVh1+VyNwHa+iSkLgQmb048afRfuhgdyRK8wYVfR ao+EAlEB4WIIm+lHBbYSgW/ugS3bKiuNVQPPxg9kHMxFPO4nlebNnRfxeh7DgV+BZ4/c M/v8CuJUug50eqih/s+Td7b7Zagrao9vfguONGGWCGU6oeX85LJtskmdiJIq9moDINQM 9PfDHmTVrrg8sfnSePz73KSWxbCwkh2mXk15Yw270w5Etv/zEOJ87w/NHEKJJ3jg6EiG 5ickYSjYiyn3NzgU/fGGLkmm6ZEoN9Y+LXXFXxZi+vgjbPfeq7nI1FLOdHgZIO1gk0At JS8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vOK5/WPTujCCAcAwyi2/KrCICYe7Hx7FC7Z5qYfB0uw=; b=QZZioq7/QBgUoaSlrQIVPWzT2dpZ+IbT8YiKxGpUMebRXMSzhjcDdxRZRWNSboZSZQ 6p+WzH1I29MjoCbwmpzZdOh50EN9Ov6v9fHzqiDgAacq9TjHw5JKYigwfJr3DKfNK/VV iyda4ViUCE4AdaWWNzCb8zSABM4/T1Cgyt2/iE5y1d/IUNruFfzbH884N60ijoAuWO6M eMGjYangxVxp/oh6c5r0w+b7TssGHXtKOK7q2DhRtpgROcwcy8aLmk9IA38Ww9aWXJj+ YoKa8Ft39XsrNc1zkHePPKBLmfkgXLSfIjvOvVz/t/JqeHs46LPd8xtBvU4UNH6b81Gc +W8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vZNybrZ8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si8223085ejy.432.2021.09.24.13.11.28; Fri, 24 Sep 2021 13:11:52 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vZNybrZ8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345298AbhIXNJm (ORCPT + 99 others); Fri, 24 Sep 2021 09:09:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:34410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346223AbhIXNGV (ORCPT ); Fri, 24 Sep 2021 09:06:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1959261241; Fri, 24 Sep 2021 12:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632488176; bh=7zNtomcHqy43NEHXfaSG6YR1AYxyRSJZFjLKEt1qjlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vZNybrZ8uDHZLRMq4DBe6A1i8WM9O/UHkUqbTzN7iIWOCVJhc8DIbT8DheYdb5FSN yHojuGEz5RahuIXPYWJXlJf0prtbcJepMb0rZypx7V0mteVRftvirlMqzKuHTB2okp vDFXGkI4bI8oo0WO6+QA4UGOWxxON0fA0PsiWO+I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, QiuXi , Al Viro , Jann Horn , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 14/63] coredump: fix memleak in dump_vma_snapshot() Date: Fri, 24 Sep 2021 14:44:14 +0200 Message-Id: <20210924124334.737620736@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124334.228235870@linuxfoundation.org> References: <20210924124334.228235870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: QiuXi commit 6fcac87e1f9e5b27805a2a404f4849194bb51de8 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- fs/coredump.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/coredump.c +++ b/fs/coredump.c @@ -1111,8 +1111,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;