Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43973C43387 for ; Tue, 8 Jan 2019 19:35:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B85C20645 for ; Tue, 8 Jan 2019 19:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976144; bh=5K3AQf9nBd2u5AMUgDnVaccA5h3MaE67QuoYrE0+jBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hSb4K/cZVWscLupdqxiubLc+tMDaJ9tmu2R0N5P0yAN1Ucts7L59n8cV9q0ztssEh 6kvfqAyvjuioUNFQCiX7HLkNtcoLrain+PIn0LZn2yEk5UoHbehpWJflTOgMqeHjWa QwMLy3aYgd91+S1VTP39qD13LpfF9ShxhEOQ6BsE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732339AbfAHTfn (ORCPT ); Tue, 8 Jan 2019 14:35:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:44514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732322AbfAHTfk (ORCPT ); Tue, 8 Jan 2019 14:35:40 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE4842063F; Tue, 8 Jan 2019 19:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976139; bh=5K3AQf9nBd2u5AMUgDnVaccA5h3MaE67QuoYrE0+jBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KKev8gspL9ImC7lOmNyGPAehSfzoASZPM8EjQWaX6yK7XyniRDg3noR/HSStuob1f T7pIuZvTxQCYKRgtwRgQAkzWYalpWQvrrEz0ecCh5J57BJ/x7KK7pjR+QuapZv/wwh U2m5MvIw2L6SOyfJxFXSgRZrMJSX6KkllxMNDcUA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Joel Fernandes (Google)" , Kees Cook , Sasha Levin Subject: [PATCH AUTOSEL 3.18 04/19] pstore/ram: Do not treat empty buffers as valid Date: Tue, 8 Jan 2019 14:35:16 -0500 Message-Id: <20190108193534.124555-4-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108193534.124555-1-sashal@kernel.org> References: <20190108193534.124555-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Joel Fernandes (Google)" [ Upstream commit 30696378f68a9e3dad6bfe55938b112e72af00c2 ] The ramoops backend currently calls persistent_ram_save_old() even if a buffer is empty. While this appears to work, it is does not seem like the right thing to do and could lead to future bugs so lets avoid that. It also prevents misleading prints in the logs which claim the buffer is valid. I got something like: found existing buffer, size 0, start 0 When I was expecting: no valid data in buffer (sig = ...) This bails out early (and reports with pr_debug()), since it's an acceptable state. Signed-off-by: Joel Fernandes (Google) Co-developed-by: Kees Cook Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/pstore/ram_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 288ce45f613e..5ffbf60f5c88 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -484,6 +484,11 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, sig ^= PERSISTENT_RAM_SIG; if (prz->buffer->sig == sig) { + if (buffer_size(prz) == 0) { + pr_debug("found existing empty buffer\n"); + return 0; + } + if (buffer_size(prz) > prz->buffer_size || buffer_start(prz) > buffer_size(prz)) pr_info("found existing invalid buffer, size %zu, start %zu\n", -- 2.19.1