Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp638381pxv; Thu, 15 Jul 2021 12:09:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW5TJQLrkkgbKZreQmj9mQTkoiFVhP/1ark3rk1TFReGszny0nlv7WeYWX71yf1M3at/Nv X-Received: by 2002:a05:6402:111a:: with SMTP id u26mr8979867edv.260.1626376180762; Thu, 15 Jul 2021 12:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376180; cv=none; d=google.com; s=arc-20160816; b=H1jPB6sKlyBxYbAZMxpJnGvxTCgKdsj7kQOwAx6ayOQii7y9oCANrqlKSlN4AhVjdp N+fxMcysZDluzPjpyfp5/+8zSWB9zdm2cEhGNynuC+btUSj6KXohtMbS86j9aCGtFihj ku8dc4W9hypBlSBH/Z3XzjYtShnNhOtuY2nROyIjCkNq5gnzdHmGx3Xf8I1EKEi8Y3RH Q46DgsRK7erWcpOUYk4NOpstD5m+mPe7/StRQnjeSOGxpWz5hMqzpEHUj/ZnGXnXT6YJ WGA49qMqklngo2CPsMIXMTqfuZbcz4nkgpFHc+eeA9Av2QDbCj4urPQ7Ky5JFJ8qt+3q 7L6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G6G98W28HGtkmefuVRMWdveIK1r99JhOgKXCaIRpVNY=; b=UoEqAZ/ShqPtNhO3bPGDTWxB/A60CPIBsnQBLWp6BMikeNAosZ1WEGUpHEzpQk35IJ Mc12SgGZQ0sgR3UpNZgUBuj7I1Tay8QkaEV6/7FdNrHKXL6Bxb9nXFHKuSlzj2djoyUL GPpAk3oiGsxDpK+vdZP1HjbB9EJf/ijR4q7p67jZFMr3hNXG6bGw63DiKYCUNnw4z7yy IlFvm5qzJO8AWx1lmupOX2BvOZ/+2lwvQQf7Ih00MVWntrtPZx5GmW94diJrpmx7dVm6 3CEXDpqXO8H00Af4fLQuTbDZoET9wmZX9h9o09qCEANXexk1Ewyp9RNiXEZ76iKkruNK f1Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=myVBYTjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 88si8575666edc.402.2021.07.15.12.09.17; Thu, 15 Jul 2021 12:09:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=myVBYTjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240935AbhGOTID (ORCPT + 99 others); Thu, 15 Jul 2021 15:08:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:33848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241834AbhGOS5d (ORCPT ); Thu, 15 Jul 2021 14:57:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 65499613CF; Thu, 15 Jul 2021 18:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375279; bh=TAJ0SnSUpJfc+Cqj1aFA6K5OlqU8tHyKbd/ynWD3xIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=myVBYTjkikRMjEpdYiYM1rpfoMoFzIQ5Jg+640eCe229IkGzXrm9c5fsFSNhC7uYX oi602T3Am+pjrtZt0Dalk9JeGmYVodhIJnES63usGYaWWEOi2VVvjGKnHaczifN8A5 nqL3p/WjousVGpRFc2o14eWlxlBpKak2uMiTFWzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com, Pavel Skripkin , Jan Kara , Sasha Levin Subject: [PATCH 5.12 020/242] reiserfs: add check for invalid 1st journal block Date: Thu, 15 Jul 2021 20:36:22 +0200 Message-Id: <20210715182555.293599963@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit a149127be52fa7eaf5b3681a0317a2bbb772d5a9 ] syzbot reported divide error in reiserfs. The problem was in incorrect journal 1st block. Syzbot's reproducer manualy generated wrong superblock with incorrect 1st block. In journal_init() wasn't any checks about this particular case. For example, if 1st journal block is before superblock 1st block, it can cause zeroing important superblock members in do_journal_end(). Link: https://lore.kernel.org/r/20210517121545.29645-1-paskripkin@gmail.com Reported-by: syzbot+0ba9909df31c6a36974d@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/reiserfs/journal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index e98f99338f8f..df5fc12a6cee 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2760,6 +2760,20 @@ int journal_init(struct super_block *sb, const char *j_dev_name, goto free_and_return; } + /* + * Sanity check to see if journal first block is correct. + * If journal first block is invalid it can cause + * zeroing important superblock members. + */ + if (!SB_ONDISK_JOURNAL_DEVICE(sb) && + SB_ONDISK_JOURNAL_1st_BLOCK(sb) < SB_JOURNAL_1st_RESERVED_BLOCK(sb)) { + reiserfs_warning(sb, "journal-1393", + "journal 1st super block is invalid: 1st reserved block %d, but actual 1st block is %d", + SB_JOURNAL_1st_RESERVED_BLOCK(sb), + SB_ONDISK_JOURNAL_1st_BLOCK(sb)); + goto free_and_return; + } + if (journal_init_dev(sb, journal, j_dev_name) != 0) { reiserfs_warning(sb, "sh-462", "unable to initialize journal device"); -- 2.30.2