Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3788717pxv; Mon, 19 Jul 2021 08:46:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysQzPOsFuMZHKVPjpmx57f+Cf2SRsZWWroXICXojS1k+9FBd92QyuBVY2+lpD/vkFc+SqV X-Received: by 2002:a17:906:cc15:: with SMTP id ml21mr28809182ejb.49.1626709599597; Mon, 19 Jul 2021 08:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626709599; cv=none; d=google.com; s=arc-20160816; b=tIE/Vkil4BvwkZFpbDFP56lKVtlWdiCaRvW3EQgQjpH2mSySCmcXFQy4tl9RqmHsN5 uuaj6xB5smEHXRkAPoq7v2Svz/x7cOLMUUXN1hAOCslLANr2zcPRfVOLhYSJ4vGb6GnU zJ+CT/oNnca2lwbDnahpKMJ8pbpY2bASzbS+04iZ604Y3A3BpHDAc6CfG+OycfrQZLJz a8NdOtKUN2uYdf1BgBBELdfrL7Q5JZAA/P3I/h0jOFIrOKT/b0l4LAdxmdsvZyF6mYEN H3P93/e67xCS5cg8mSTuXF/EZAwrWzecwge8u3k2hNnyQXXKQRKv7Yfh95natXdso5FC ltzw== 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=Uq86kur07vqu3uOx3KoeVta9Ffm7CT98CEmBngnbOX8=; b=WBP+dMa3oPm15Q82+/BojGWr4nVVja4U1lvokMKDbr6zu/Z7SZKfkHUUGVMYXbyyfG gXHNpjm2cE06AlJzkpuf7xRhfUZ5YsDgBwBqEwH23spqLGhbkvYYHs5g9RWKuHEGC8KO 0D7BuR6KILEmQPHjWUH7mgoLzDNhA++KRfdmUdz6gVBGLmueQZ4Yb65Z3z5WIzy/OXC1 LWHvi3F9pC7jM/i+Pz4tG8eFtOBP0tKaQm+KLa2Mit3vEZ4lD1S9oQuaOsc3xH6CyTWO UIVtEegMDv3DusexDujF4cw7acs2cV0L3m4WPcOsaU4BmjwcUodDmCldAsTwhrT8aohO NEGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MAKgDCB7; 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 26si21295135ejz.171.2021.07.19.08.46.15; Mon, 19 Jul 2021 08:46:39 -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=MAKgDCB7; 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 S1343949AbhGSPDB (ORCPT + 99 others); Mon, 19 Jul 2021 11:03:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244264AbhGSOkc (ORCPT ); Mon, 19 Jul 2021 10:40:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EEBF26120A; Mon, 19 Jul 2021 15:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708071; bh=dVBJfQRirVoOIzRNPs88vxExJ0Go3B8dpqE3QDSy/mw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MAKgDCB7pIFR6KJ8ss09KSjjuwKQ7eWng02FUkmTR52jppi0N+OOOR6Z8A1uzhWIE ekg+9qdj3g/05zRtS/NPn905GmF9GqiQhPVtCHlgJ9wOml+ux3k1kbr81Ig1YFaMce NYEZiPtMLdTTM4WK3DvxTG7He3yAmrCz1vnD5MLk= 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 4.14 169/315] reiserfs: add check for invalid 1st journal block Date: Mon, 19 Jul 2021 16:50:58 +0200 Message-Id: <20210719144948.450052538@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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 2be907231375..1a6e6343fed3 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2769,6 +2769,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