Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932196AbdCFWVu (ORCPT ); Mon, 6 Mar 2017 17:21:50 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:36212 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754154AbdCFWVb (ORCPT ); Mon, 6 Mar 2017 17:21:31 -0500 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Nobuhiro Iwamatsu , Qiuxu Zhuo , Ard Biesheuvel , Anton Vorontsov , Colin Cross , Tony Luck , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Rafael J. Wysocki" , Len Brown , Matt Fleming , Nathan Fontenot , Pan Xinhui , Daniel Axtens , Paul Gortmaker , Geliang Tang , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 13/18] pstore: Allocate records on heap instead of stack Date: Mon, 6 Mar 2017 13:55:27 -0800 Message-Id: <1488837332-71582-14-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488837332-71582-1-git-send-email-keescook@chromium.org> References: <1488837332-71582-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1803 Lines: 66 In preparation for handling records off to pstore_mkfile(), allocate the record instead of reusing stack. This still always frees the record, though, since pstore_mkfile() isn't yet keeping it. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index d897e2f11b6a..072326625629 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -818,8 +818,7 @@ static void decompress_record(struct pstore_record *record) void pstore_get_records(int quiet) { struct pstore_info *psi = psinfo; - struct pstore_record record = { .psi = psi, }; - int failed = 0, rc; + int failed = 0; if (!psi) return; @@ -833,19 +832,34 @@ void pstore_get_records(int quiet) * may reallocate record.buf. On success, pstore_mkfile() will keep * the record.buf, so free it only on failure. */ - while ((record.size = psi->read(&record)) > 0) { - decompress_record(&record); - rc = pstore_mkfile(&record); + for (;;) { + struct pstore_record *record; + int rc; + + record = kzalloc(sizeof(*record), GFP_KERNEL); + if (!record) { + pr_err("out of memory creating record\n"); + break; + } + record->psi = psi; + + record->size = psi->read(record); + + /* No more records left in backend? */ + if (record->size <= 0) + break; + + decompress_record(record); + rc = pstore_mkfile(record); if (rc) { /* pstore_mkfile() did not take buf, so free it. */ - kfree(record.buf); + kfree(record->buf); if (rc != -EEXIST || !quiet) failed++; } /* Reset for next record. */ - memset(&record, 0, sizeof(record)); - record.psi = psi; + kfree(record); } if (psi->close) psi->close(psi); -- 2.7.4