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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,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 6D61EC33C9E for ; Sat, 11 Jan 2020 09:54:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DDBC2077C for ; Sat, 11 Jan 2020 09:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578736483; bh=YifGFmuHCJnKvVu31HrpEi2c+jHaN5s8ZBCC9Uc/+yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0iVW6QT7xpcIbPaMjEHjWGWzzpstB2OJ0jAznXp+DLVu5+9rppEH1ny0YQ25fFb7M epzq3w5eHjxesFIKR9w0AGXUetE3AeUFh/WQ5niA/0fq+Po0Ndo8H3gQWQUPkbBd5H 4zzkygpcE1DdFPycxLx4+iO0Vb4fHbZSisRekr2k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729111AbgAKJym (ORCPT ); Sat, 11 Jan 2020 04:54:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:43532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728807AbgAKJyk (ORCPT ); Sat, 11 Jan 2020 04:54:40 -0500 Received: from localhost (unknown [62.119.166.9]) (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 4FAFE2072E; Sat, 11 Jan 2020 09:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578736480; bh=YifGFmuHCJnKvVu31HrpEi2c+jHaN5s8ZBCC9Uc/+yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzuJsB4O6EPK2WKrpBC8eGoU8LyyVrg0V1n5zH6FYeKjtXJ7H359rd8k8Dj7S5+VC o7anAf8kCJPlc6qrmDx/rMhaAOeMu34USZBlwlWo/FcBXkkQ/KcDzEoGjjWbTOWxj6 En1staket0mxcviv2GdRg55SliqvAUJ4CY0J1B1s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aleksandr Yashkin , Nikolay Merinov , Ariel Gilman , Kees Cook , Sasha Levin Subject: [PATCH 4.4 33/59] pstore/ram: Write new dumps to start of recycled zones Date: Sat, 11 Jan 2020 10:49:42 +0100 Message-Id: <20200111094844.943026669@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094835.417654274@linuxfoundation.org> References: <20200111094835.417654274@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Aleksandr Yashkin [ Upstream commit 9e5f1c19800b808a37fb9815a26d382132c26c3d ] The ram_core.c routines treat przs as circular buffers. When writing a new crash dump, the old buffer needs to be cleared so that the new dump doesn't end up in the wrong place (i.e. at the end). The solution to this problem is to reset the circular buffer state before writing a new Oops dump. Signed-off-by: Aleksandr Yashkin Signed-off-by: Nikolay Merinov Signed-off-by: Ariel Gilman Link: https://lore.kernel.org/r/20191223133816.28155-1-n.merinov@inango-systems.com Fixes: 896fc1f0c4c6 ("pstore/ram: Switch to persistent_ram routines") [kees: backport to v4.9] Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/pstore/ram.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 59d93acc29c7..fa0e89edb62d 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -319,6 +319,17 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type, prz = cxt->przs[cxt->dump_write_cnt]; + /* + * Since this is a new crash dump, we need to reset the buffer in + * case it still has an old dump present. Without this, the new dump + * will get appended, which would seriously confuse anything trying + * to check dump file contents. Specifically, ramoops_read_kmsg_hdr() + * expects to find a dump header in the beginning of buffer data, so + * we must to reset the buffer values, in order to ensure that the + * header will be written to the beginning of the buffer. + */ + persistent_ram_zap(prz); + hlen = ramoops_write_kmsg_hdr(prz, compressed); if (size + hlen > prz->buffer_size) size = prz->buffer_size - hlen; -- 2.20.1