Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8172ybl; Tue, 7 Jan 2020 13:03:43 -0800 (PST) X-Google-Smtp-Source: APXvYqyVCuYNMyMLtqdWnZvfgSSPPDHa9VHmvtbbXKOEPQ3OYuoqUh+LPHk1HjjR/YkmwcwZ00tt X-Received: by 2002:a9d:588c:: with SMTP id x12mr1667210otg.2.1578431023267; Tue, 07 Jan 2020 13:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578431023; cv=none; d=google.com; s=arc-20160816; b=XXo9yReLutN+XU4t3K8ekeTReAVVn1NdhJ0PmiiudnlNlxAkOHCKGv+5q/cG6H+KL9 W4jC3hVp/hYTCHjOCYcxF8bAQaBi9BwSMAaYfWG32rSh4F6TX6zQZ4xh9+PiDCYmHkPm b+bVLnF2u4i2ZO2W8WHc9GncpjLD1fAne+hvWpNrgmuuRjm8MvVdn6m4bRkG8uOgYNGo BQqAESzigXF7JWLvcWkkKgPsE1t9hLQAwGc0BXdLWaDfmGwzsfmrzlhmMqAFs/19BCX7 +1wFRnmb7JfLcKdGmpUMlWkc/vNOkyD1fCOOm6U7xHeu4bCCPhpvwpwUZaxW9NrDNwUh ZXIw== 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=3PI264s85gQdMt+TP0qQZygmqLhk5DTPryg9ld1YfB4=; b=T0CUlugy1GrVSdEjkQwTSgVvfdYbPG/SYXbWVTECnsemQEKXS0HNCwfryGLXmmi33H 87P5rsP3flgXdVfT0pov8iOMJlYvHxYKnaaijhe/2AEy3kNsjyzOLN/lbLSgNdHIQ8zt If175kEEcmIlR5VV8XnaKrQ/nfuMJ3XCnl05nmkhV3fjq5EVg0aHId0YbRkdHAlqokEQ DAFBV/NVqLDE6zk+8WCXwrnPnZFytqVIHpO8SeAi2l79M9wMRhKT0uzmcqR4Yi0CMtlH AvslsJiZlcnTQaODjfrBtD1Wr9Rwo5fJ9GjrdiqbH7Qb2EyCgrcQSYyoUK1JXvQ+7fiP IgKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X3a71wNq; 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 u191si650060oia.86.2020.01.07.13.03.30; Tue, 07 Jan 2020 13:03:43 -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=X3a71wNq; 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 S1728508AbgAGVBN (ORCPT + 99 others); Tue, 7 Jan 2020 16:01:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:37424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728477AbgAGVBA (ORCPT ); Tue, 7 Jan 2020 16:01:00 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 B06D021744; Tue, 7 Jan 2020 21:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430860; bh=ghJPWWuvqI+2W+7yB5CB5Xw2G0Ec0DSRSw0S2VlnfGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X3a71wNqP4FKYb30vhBZ5xFe05xen1sQDC2TyFBGX4RzXD8ejyn3X9OoHqjbgqk5N 6ShPbOxNouJgv7RYu3tEvKI1jkUemHQKvrFk9MxrDCalluP/56mQALZ4GgICY/+UT7 Nz5Tl3t1piIjS01evoz4/vV6dOwdzE05WEV+7eoA= 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 Subject: [PATCH 5.4 089/191] pstore/ram: Write new dumps to start of recycled zones Date: Tue, 7 Jan 2020 21:53:29 +0100 Message-Id: <20200107205337.761682618@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@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 commit 9e5f1c19800b808a37fb9815a26d382132c26c3d upstream. 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") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- fs/pstore/ram.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -407,6 +407,17 @@ static int notrace ramoops_pstore_write( prz = cxt->dprzs[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); + /* Build header and append record contents. */ hlen = ramoops_write_kmsg_hdr(prz, record); if (!hlen)