From mboxrd@z Thu Jan 1 00:00:00 1970 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,USER_AGENT_GIT autolearn=unavailable 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 E8D59C43387 for ; Tue, 8 Jan 2019 20:07:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4E7320660 for ; Tue, 8 Jan 2019 20:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546978041; bh=fypjMSS340+Ry3NFY1eYH6c89xR4iMXHmMMAD6Lr1JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Mf2P+E3X1l/TC+/a839BMfgNP7s2PY0XmZqWyBhJm4Iav5l/5AwkHYcJccH813pDo dJykxWBP15x9sM5UKY+aJlMXM7J91huB9NY+tjZxXl7NqDo0JiJ9GKNKn1X9hM9ozU qkLSdizUSZzeqf976XSspYYUXDmVsIDVpAmRp0Rc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729948AbfAHUHP (ORCPT ); Tue, 8 Jan 2019 15:07:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:34424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729763AbfAHT1y (ORCPT ); Tue, 8 Jan 2019 14:27:54 -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 2ACE72176F; Tue, 8 Jan 2019 19:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975673; bh=fypjMSS340+Ry3NFY1eYH6c89xR4iMXHmMMAD6Lr1JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bV7t0GsF+E+Z95sEUSlDi2+h7tQ0krYtS2I+b75ulPeIk4BbdE69D++VtkmkyQl3h QWSIAVJo91Rr9MXC2nKXg5OdHfM5NwN/uufH41UOEPk8+WEOToE5MRCle9QA/0YeUH ROo3OdcWGetJkQRSSjpsWWkSJKgQmHqL3jpfW120= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Joel Fernandes (Google)" , Kees Cook , Sasha Levin Subject: [PATCH AUTOSEL 4.20 045/117] pstore/ram: Do not treat empty buffers as valid Date: Tue, 8 Jan 2019 14:25:13 -0500 Message-Id: <20190108192628.121270-45-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-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 12e21f789194..79f0e183f135 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -497,6 +497,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