Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp652466pxv; Thu, 15 Jul 2021 12:32:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEoNd35/CIu9G86/nxQ3ibUpI7QvapnanRGG8tR3hdSvFD02Ri4gYTxj1pfxW3cHI3LM+s X-Received: by 2002:aa7:cb03:: with SMTP id s3mr9217479edt.189.1626377521943; Thu, 15 Jul 2021 12:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377521; cv=none; d=google.com; s=arc-20160816; b=HMFkDtjHki4/fOc8xQ67TRVnwJ74jyWl1Oj7fzonQJk8m9k1cn7PyamUNBBWe7IV7m F0sCYjOKIETqMnCrb/IG8YQfba9tOY/7mooeioHmRvrviYjHaWyX9KhNjBzAyhc8VZey RN2OMEPiWYED/3Ni8lLmaiotpu9u9/1rqA13NeldXcjQmc2vdIpFvu7TBxKjpIJvvTa+ 7/YfZw1rraV4V9C9hIncL9PerqLd35gHhUUW01pmXyf2HLGGhj79tCsqel33CpHfonSk OXpU+5a0aAzx1HxyDuSuFjE7/sWPRRcHAWq5XKjbr2IhFpg48ScAblyjswNeoXAvbrSL mjqA== 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=gl1aYqNw1t46h8t4yKI4rGwtquoPwpzTb3rKBOKhh10=; b=Ft/dk4QKcyDWF7gT3RF5IIsmdJKz/2bspjJx7T9l8FFDzbUWDwfhDZhd6KXJFOEO4F CftbD3tpJ7tvd5Ekzd8mhaZ5QfCUe0O4soeqsCuuc7eauIPVD3QvA26HqH+CAuE04O5u /wLFYxIfXOaJHinImInmqRhfCIyr9wc/eGK4yyjSV1PvhMlSWcIDDYa+nv2q8/Sz2Aj/ hIZWgpI6hTUgpMIEMWtRaE+uuBftAsH1XVp+9XjAt9tF+ZKEV3w/7U5BPU6exREIkEaH cfL2NuWrRo1zw8ZGlP2SlZokajmGtheMZC57Az2o0yD9WxJtcCd9utXb8Vyy9d0TBY6X jCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BExJKMK4; 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 u19si9383677edo.288.2021.07.15.12.31.39; Thu, 15 Jul 2021 12:32:01 -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=BExJKMK4; 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 S242596AbhGOTc1 (ORCPT + 99 others); Thu, 15 Jul 2021 15:32:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:46412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242709AbhGOTIy (ORCPT ); Thu, 15 Jul 2021 15:08:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B2AB16140C; Thu, 15 Jul 2021 19:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375881; bh=SAJYWcgcH/e2eq5T9fBY2MEs3b92Zz95isfe+F+4SJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BExJKMK41jNMTld65oxA7jDPbHYpfLS67zBRLMk9DV0Mq6Dao/W3Ys0s6Ej/lRnvs I0/mE3FN1QUxbfx3+t1JyySuuusEpjGnEdWS69AF1ZOokrQaRH3E9spcAsUaNM2ORu y5xSnaeWPF+AyVDIICfvF7ckErn7JI4em7DCvUxg= 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.13 026/266] reiserfs: add check for invalid 1st journal block Date: Thu, 15 Jul 2021 20:36:21 +0200 Message-Id: <20210715182618.676769188@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 9edc8e2b154e..0834b101c316 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2758,6 +2758,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