Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1994310imu; Fri, 14 Dec 2018 04:13:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/X56QYywQFOdpHQiEFXvuhPx32ZqVW52E2x3uiLWTXVHfsIyD4C0Qw0aTwSzQa/K3ICz4/Q X-Received: by 2002:a63:db48:: with SMTP id x8mr2394623pgi.365.1544789587815; Fri, 14 Dec 2018 04:13:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789587; cv=none; d=google.com; s=arc-20160816; b=BOEAdMUBZH9mAF5Lt7yhs0kovCvdv+P7ABRLOZrln45anzKo3xbZc6UGDAeiVSCu5v mYqFhxNHgf9bQxaHSNq9fY0lg49xMbVRiR9GDXErBn7eRT+1thwv7Vk44HkDo7BP6NNw 6WJnQrpab2Hn0SXkIb9wR7dXWZWzBWpx6YmaQiVEAe0v6rZoR3zrTlEYeM4WRpLqb7aN /9qkFHQeIFu3CE+KVAFdjLtoGId9n+M6/JDfhGDZoh+BhoRRGMSxI2q732/y8TyubAvm zrvEu9B2gd7eBHM8jc8qeYY7AeDqrQmOMOUbh55Aqc0dfoau1m+NSF46tGziSYmNX1Vk xouA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RWhKfemGEpzJVcZ+Ey09ND0/47Zf0KRVdvvYiEvDElY=; b=hQLNVvjzxkTStEoIqPNw6S48b6LcBNpUqgQNFwYMGq80+p7pNLF1EuJU3JIVyAk16t VLA7Y2YJZmpGoDKzLpt/G+wkDItYFjrou6b9poQ47uZz4PBYR4hO+c2wlmutUN4jJuYd qIQkSuMhpt11sZ+EdcZkWOpOfGFMEOiED9pgfcRnH0xsNycTm/OvxplNfuHL2g5IDcBI ugBZkSnkOYpyjWsCPaL+Fs5W00RLD0st1I7vc96R45Sy4Tk8rKgla2XbzEAtz8LS/5x/ BqXf0vng19TWdsR/hSsJPNffU11z9Wwj3sQaijgDM25VmHSR2HsW4daj0DysmIFW8lVG s4QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V3kLjnof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 88si3943119plb.288.2018.12.14.04.12.53; Fri, 14 Dec 2018 04:13:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V3kLjnof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731694AbeLNMKz (ORCPT + 99 others); Fri, 14 Dec 2018 07:10:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:57266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731129AbeLNMKw (ORCPT ); Fri, 14 Dec 2018 07:10:52 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1DEE5214C4; Fri, 14 Dec 2018 12:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789451; bh=erUjdBhFaVtMihlA3rEFO33zvHJd6gmcscXkhuMQ6xE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V3kLjnofOj6sBGE686N6W1u0cpPlM7VXlpWfmn4KIZ7Tiqkl3BTu5LmmvHQLYwldQ IhvxC1oHxnJEqSfICrav4GecSRlBIPtCMYuupQYWy5+p64pxY5vIQ2cKS1kvWxNZmW 8erX+zd59FPf9jWMv/XxyUJvZyw61Ps+OIRiD9GU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joel Fernandes , Kees Cook , Sasha Levin Subject: [PATCH 4.14 68/89] pstore/ram: Correctly calculate usable PRZ bytes Date: Fri, 14 Dec 2018 13:00:21 +0100 Message-Id: <20181214115733.037963108@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115729.658859279@linuxfoundation.org> References: <20181214115729.658859279@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 89d328f637b9904b6d4c9af73c8a608b8dd4d6f8 ] The actual number of bytes stored in a PRZ is smaller than the bytes requested by platform data, since there is a header on each PRZ. Additionally, if ECC is enabled, there are trailing bytes used as well. Normally this mismatch doesn't matter since PRZs are circular buffers and the leading "overflow" bytes are just thrown away. However, in the case of a compressed record, this rather badly corrupts the results. This corruption was visible with "ramoops.mem_size=204800 ramoops.ecc=1". Any stored crashes would not be uncompressable (producing a pstorefs "dmesg-*.enc.z" file), and triggering errors at boot: [ 2.790759] pstore: crypto_comp_decompress failed, ret = -22! Backporting this depends on commit 70ad35db3321 ("pstore: Convert console write to use ->write_buf") Reported-by: Joel Fernandes Fixes: b0aad7a99c1d ("pstore: Add compression support to pstore") Signed-off-by: Kees Cook Reviewed-by: Joel Fernandes (Google) Signed-off-by: Sasha Levin --- fs/pstore/ram.c | 15 ++++++--------- include/linux/pstore.h | 5 ++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 7125b398d312..9f7e546d7050 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -804,17 +804,14 @@ static int ramoops_probe(struct platform_device *pdev) cxt->pstore.data = cxt; /* - * Console can handle any buffer size, so prefer LOG_LINE_MAX. If we - * have to handle dumps, we must have at least record_size buffer. And - * for ftrace, bufsize is irrelevant (if bufsize is 0, buf will be - * ZERO_SIZE_PTR). + * Since bufsize is only used for dmesg crash dumps, it + * must match the size of the dprz record (after PRZ header + * and ECC bytes have been accounted for). */ - if (cxt->console_size) - cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */ - cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize); - cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL); + cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size; + cxt->pstore.buf = kzalloc(cxt->pstore.bufsize, GFP_KERNEL); if (!cxt->pstore.buf) { - pr_err("cannot allocate pstore buffer\n"); + pr_err("cannot allocate pstore crash dump buffer\n"); err = -ENOMEM; goto fail_clear; } diff --git a/include/linux/pstore.h b/include/linux/pstore.h index 61f806a7fe29..170bb981d2fd 100644 --- a/include/linux/pstore.h +++ b/include/linux/pstore.h @@ -90,7 +90,10 @@ struct pstore_record { * * @buf_lock: spinlock to serialize access to @buf * @buf: preallocated crash dump buffer - * @bufsize: size of @buf available for crash dump writes + * @bufsize: size of @buf available for crash dump bytes (must match + * smallest number of bytes available for writing to a + * backend entry, since compressed bytes don't take kindly + * to being truncated) * * @read_mutex: serializes @open, @read, @close, and @erase callbacks * @flags: bitfield of frontends the backend can accept writes for -- 2.19.1