Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1749738ybl; Sat, 11 Jan 2020 02:03:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzf3tZzOfkSJLM1EgBAaiah7Cv+I0BdQNa8qgevx+m/MRwamveTxRYgNbJz9wokWc/GGouA X-Received: by 2002:a9d:7ac9:: with SMTP id m9mr5920019otn.80.1578737027827; Sat, 11 Jan 2020 02:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578737027; cv=none; d=google.com; s=arc-20160816; b=xcqnxzHQZOshkcViR/Fifo5slEySZaW/kt33YItWen0N1+Buseg7qFhqi213nr+Cr4 mgatZOfZskDOIFXOKxIJxbG/usSYSVixridF22kIw+D6opKKchWnTI969zYqUt6VOtm6 nYe+HUbwhvmZRPl6NkQ4EAt2SZ3EVxQ3dGXs3YgA+a4c7h23iA3MXxFxfq3TyUe1yXNv 72NadA0DmBbcPflxv25P/wLPLZKrVDY90XVtwW2oJVc06BbfpmrGqCP2QgX+80ArV4rN 3XDDxRnSaafdYmfgw4FIZn6IhNriPUIPn8OULkom/vdVFf7qiA9O1D0sVTklWFcItvuD K1Cw== 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=ekaFMmChLTzC5SmCElph2EbBvpWtITB+o8b40pD7gqo=; b=xen1eAj5KCkr0N+8jA0ESZEcxr3IoFrfG6aIgDkS3cuDeMCBhKfxTT4qnTitKTiS15 xjVJJTf7FUXqo0z6Fv4jduPci9bV3z2PnTWD+fXoj/cAlH9yw9eYIdP9zhGNA/YCqZ6N 2rDAePEeTH5At5NKT9RwbkMgncmvgaT/pmI1bNbKePUKYHK/XBmXvSC9zb0p4OqjyRhp oQaGbknWFbosZGbigbqii0cE2R7OwIK+cMbxOXUKwbmiYOtapJ9euWMpcpG7Ujxzb6gP 68YNAgUH71KmH9WU+XVJ38Gub4RBoQgfwHahghw2885ZGt7x8g/uUZyEw+J39UNi/HTn OL6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="mieM/oC8"; 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 h22si3445518otk.18.2020.01.11.02.03.36; Sat, 11 Jan 2020 02:03:47 -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="mieM/oC8"; 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 S1729327AbgAKKCp (ORCPT + 99 others); Sat, 11 Jan 2020 05:02:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:33354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbgAKKCo (ORCPT ); Sat, 11 Jan 2020 05:02:44 -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 2B4BA20842; Sat, 11 Jan 2020 10:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578736964; bh=x46ZqZekimlPN+R+iky3j2yxrRSHk+gskssGOu7DI3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mieM/oC8o8mTXs8/+tEOxYWMgm/5sGb5Rc3JmB2P2dAppJNpaea6FziN9dxuPGJ7u 5mBldILUGuf/IELXiFfkcJqOvz7VTrwg8FIyVPzOfgzYVnDfm0PSWy9dBH17p6CImu 93UZ3joWutnbO1+NZQ/SOxGUy+m71b62NspBWjKY= 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.9 56/91] pstore/ram: Write new dumps to start of recycled zones Date: Sat, 11 Jan 2020 10:49:49 +0100 Message-Id: <20200111094905.956540988@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094844.748507863@linuxfoundation.org> References: <20200111094844.748507863@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] Link: https://lore.kernel.org/stable/157831399811194@kroah.com 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 8b09271e5d66..a73959e6ae32 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -321,6 +321,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