From patchwork Mon Mar 6 21:55:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9607749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A82B56046A for ; Mon, 6 Mar 2017 22:19:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8D3528477 for ; Mon, 6 Mar 2017 22:19:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC05B2847B; Mon, 6 Mar 2017 22:19:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BE1028477 for ; Mon, 6 Mar 2017 22:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932203AbdCFWTB (ORCPT ); Mon, 6 Mar 2017 17:19:01 -0500 Received: from mail-pg0-f47.google.com ([74.125.83.47]:36821 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932200AbdCFWTB (ORCPT ); Mon, 6 Mar 2017 17:19:01 -0500 Received: by mail-pg0-f47.google.com with SMTP id 187so17057117pgb.3 for ; Mon, 06 Mar 2017 14:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v7Av9cxlr82YzrkWuXj9OTggN+J7P+hDywB1LxqU9Xw=; b=XHo+SJN0ZakCxhvlqqjnAGcBsXhxs5AfSbdLADUe5kjHP6eURiEh4HVaOLmYMMYoLO nrhDryiznWP+Q5c7d8iuHkeQWHul/n9giyXzMWfXdHPHxBIIQoWeO1mcmAB1iDjMDM7e 8kAklsJyastDP7XBO1UdKg/TUOgkCDPEFL1ac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v7Av9cxlr82YzrkWuXj9OTggN+J7P+hDywB1LxqU9Xw=; b=OMSDsNR2HWZYHdCAnJQXYh8NsbEC6psQzFci/2YY2yAmQB+SAu7FZGsD/1OOOdcQLr lflBVG/pXOsRUb9WS2pAzfgFrtB/gJvUsYMuXuz3hjL6n52+DDzAsJne/AgTY6Z6egr9 BMqz8T4BHzCl41lJltxluqTkxlcvqHLvHrEU3jDJ5+7+n8D6+fFxEuI1DFjFnZiIKolc hFmD3RAOCimxxY1oISEhGNdb4J8pnvmkXUBKIKLoyTvRHuJFoXJlHz3TnjSNqLPzD35P rgjfPFgbjYyfSfkLn6ECmtPtcy3sBY3RfM//Gq0KCuSxgEG4fkBMIZlDlXBTsuJr2EhZ iDSg== X-Gm-Message-State: AMke39mlOb/sBubAFYnkWW9qnuWiBpYYTC22Q/paH4XjBS7r+F8mo6W8x5UewIz2QzohMJbl X-Received: by 10.84.215.155 with SMTP id l27mr29542855pli.31.1488837341996; Mon, 06 Mar 2017 13:55:41 -0800 (PST) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id w123sm41401245pfb.44.2017.03.06.13.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 13:55:41 -0800 (PST) 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);