Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754237AbdGSJrS (ORCPT ); Wed, 19 Jul 2017 05:47:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38446 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753529AbdGSJrO (ORCPT ); Wed, 19 Jul 2017 05:47:14 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Anderson , Kees Cook Subject: [PATCH 4.12 77/84] pstore: Fix leaked pstore_record in pstore_get_backend_records() Date: Wed, 19 Jul 2017 11:44:23 +0200 Message-Id: <20170719092325.376108435@linuxfoundation.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170719092322.362625377@linuxfoundation.org> References: <20170719092322.362625377@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1089 Lines: 38 4.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Douglas Anderson commit f6525b96dd9f68efe374e5aef864975e628de991 upstream. When the "if (record->size <= 0)" test is true in pstore_get_backend_records() it's pretty clear that nobody holds a reference to the allocated pstore_record, yet we don't free it. Let's free it. Fixes: 2a2b0acf768c ("pstore: Allocate records on heap instead of stack") Signed-off-by: Douglas Anderson Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- fs/pstore/platform.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -846,8 +846,10 @@ void pstore_get_backend_records(struct p record->size = psi->read(record); /* No more records left in backend? */ - if (record->size <= 0) + if (record->size <= 0) { + kfree(record); break; + } decompress_record(record); rc = pstore_mkfile(root, record);