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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 DFA60C282C7 for ; Thu, 24 Jan 2019 19:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A60C5218A6 for ; Thu, 24 Jan 2019 19:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358126; bh=w4SC/e+AlAiUScLgvlf2rv0l4T0yNeuxWoq0TY5s1L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TiFfJJgLej6ow5LWSm2USvLxkSOV5NfQqLDscCPrPdm2xask01XdbP/Ipu8HDQMVF 8jrEgTfA+dYSyXYWpq61S8AjXYxxXgNgSsajsMIvBH4Zph3uKMFhKd8D8ay7x3lNnF Z/M80oloHdFODkq2px9YWrf6l6/AQxRUe66la/bA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730569AbfAXT2p (ORCPT ); Thu, 24 Jan 2019 14:28:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:55604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730440AbfAXT2o (ORCPT ); Thu, 24 Jan 2019 14:28:44 -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 11595218FC; Thu, 24 Jan 2019 19:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358123; bh=w4SC/e+AlAiUScLgvlf2rv0l4T0yNeuxWoq0TY5s1L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BRDzjLd8pELtOLVSaAN+lX4bRV6CujRSw0qZLcKa3XAXIBv4ubcasbtuct6eCMFiW bp5LfZLqjj5meJdgTwCP7hcN7bEhWNV3RBMeJGWXDh0aOcMOnVch4eC50JQX0QZhGk wOUfx6oGcKDRkMC4OhbyNsDbQsOBPh3pRD7Xrffc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Joel Fernandes (Google)" , Kees Cook , Sasha Levin Subject: [PATCH 4.4 083/104] pstore/ram: Do not treat empty buffers as valid Date: Thu, 24 Jan 2019 20:20:12 +0100 Message-Id: <20190124190204.269355030@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190154.968308875@linuxfoundation.org> References: <20190124190154.968308875@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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 bd21795ce657..679d75a864d0 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -445,6 +445,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