Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp924961ybe; Fri, 13 Sep 2019 08:25:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaNZadc3vwZ8efPUYuJstYRPOZ+0bCNxUk+wIFgW6oraRLsKKTQglXHAYQrc5BJkIg9M1S X-Received: by 2002:a17:906:688d:: with SMTP id n13mr26237422ejr.65.1568388313731; Fri, 13 Sep 2019 08:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568388313; cv=none; d=google.com; s=arc-20160816; b=J7uMYjyOGjENOVF4mvnuP5uCALdk0Bbayem8eQ4XuOy/zx/dRowyO958emET4T/ZM7 aOYPocj1YwVvQBn8jnMqgC1j5x4oDdOAeAoSUqbu0PF62IhqeFES39S18j9GIuLGnBFf VBUYR29330gu7VWfm0X3BFh8HGtcp/IkOuN+PC/gbx/ZcRZli2gaf2mfVGwKqLWFNUy8 mcfq/uBmViFQchZgXiR/ou1hhARBHC4wesp1R5yBDVVCpETZcBpWyIo0zVHj4w6DPqcP 8K8UrYtGCUK01LH+AdaJW7jWa4k+DSv/BwH3LnLOvAEQC/cjSov0P1YKDB2dP9mvwZ1A qXKw== 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=bmR96nhCc8ofUS8luj2bFsAHqXHmv2Y6MPgXwVF7uw0=; b=m+q1Q0/I8xXAoFeBFtSLAhgiiwHewxCve9WIdPrVQCXtZA9ColjKVu9PwqKO3r2mH2 LWVU5mnZouRuUaLiQnNqhE35QlH9LYJXz5zXcaL1xJouN6P/pIypVgZEpGG7cyGamLER Y0LlbhYqwGg/r4OG9vWJdnggCoXBUOKgc6yZiucuB3mn/NAXsFclci51+oC7+e7ivfwT rMwSP3FioXz4LC3Wl/LM3PIpLcu/VxEPr6qzkHzb2PImUG8czPNGtYc2Q9s0Q5EI9m3j WgT0xhM1Xyt4D8gFhGi665+scx0HqMdmalY1Wd2p7n0f9FuMgiKU1z6kJH9FcJMmj4KD oIXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AdWx7okd; 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 z15si17972402edd.431.2019.09.13.08.24.50; Fri, 13 Sep 2019 08:25:13 -0700 (PDT) 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=AdWx7okd; 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 S2391659AbfIMNaF (ORCPT + 99 others); Fri, 13 Sep 2019 09:30:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:45334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389218AbfIMNR4 (ORCPT ); Fri, 13 Sep 2019 09:17:56 -0400 Received: from localhost (unknown [104.132.45.99]) (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 EB4CF214AE; Fri, 13 Sep 2019 13:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380675; bh=lnJVnALC+xXmKEp6Di4Baj2+s1u4pjqDGx/Y+jtrYPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AdWx7okdkVlhmVOSaW2tJtq3PH+jHu6hfhAsoSfiMdZFeecYd5vDYFR6Ui2iM40j5 n0T0IFoutS/rI0jqmBsK6EoS0U5nGAHbXKiGTxJ+VH0oAZkLbaTtvbLUtWRdNLv1pK qR60GbBp6aHNYWTlvjI+LDNXgLKKTz1widk9fuWA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org, Sasha Levin Subject: [PATCH 4.19 118/190] ext4: protect journal inodes blocks using block_validity Date: Fri, 13 Sep 2019 14:06:13 +0100 Message-Id: <20190913130609.260876778@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@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 [ Upstream commit 345c0dbf3a30872d9b204db96b5857cd00808cae ] Add the blocks which belong to the journal inode to block_validity's system zone so attempts to deallocate or overwrite the journal due a corrupted file system where the journal blocks are also claimed by another inode. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202879 Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Sasha Levin --- fs/ext4/block_validity.c | 48 ++++++++++++++++++++++++++++++++++++++++ fs/ext4/inode.c | 4 ++++ 2 files changed, 52 insertions(+) diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c index 913061c0de1b3..9409b1e11a22e 100644 --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c @@ -137,6 +137,48 @@ static void debug_print_tree(struct ext4_sb_info *sbi) printk(KERN_CONT "\n"); } +static int ext4_protect_reserved_inode(struct super_block *sb, u32 ino) +{ + struct inode *inode; + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_map_blocks map; + u32 i = 0, err = 0, num, n; + + if ((ino < EXT4_ROOT_INO) || + (ino > le32_to_cpu(sbi->s_es->s_inodes_count))) + return -EINVAL; + inode = ext4_iget(sb, ino, EXT4_IGET_SPECIAL); + if (IS_ERR(inode)) + return PTR_ERR(inode); + num = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; + while (i < num) { + map.m_lblk = i; + map.m_len = num - i; + n = ext4_map_blocks(NULL, inode, &map, 0); + if (n < 0) { + err = n; + break; + } + if (n == 0) { + i++; + } else { + if (!ext4_data_block_valid(sbi, map.m_pblk, n)) { + ext4_error(sb, "blocks %llu-%llu from inode %u " + "overlap system zone", map.m_pblk, + map.m_pblk + map.m_len - 1, ino); + err = -EFSCORRUPTED; + break; + } + err = add_system_zone(sbi, map.m_pblk, n); + if (err < 0) + break; + i += n; + } + } + iput(inode); + return err; +} + int ext4_setup_system_zone(struct super_block *sb) { ext4_group_t ngroups = ext4_get_groups_count(sb); @@ -171,6 +213,12 @@ int ext4_setup_system_zone(struct super_block *sb) if (ret) return ret; } + if (ext4_has_feature_journal(sb) && sbi->s_es->s_journal_inum) { + ret = ext4_protect_reserved_inode(sb, + le32_to_cpu(sbi->s_es->s_journal_inum)); + if (ret) + return ret; + } if (test_opt(sb, DEBUG)) debug_print_tree(sbi); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e65559bf77281..cff6277f7a9ff 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -399,6 +399,10 @@ static int __check_block_validity(struct inode *inode, const char *func, unsigned int line, struct ext4_map_blocks *map) { + if (ext4_has_feature_journal(inode->i_sb) && + (inode->i_ino == + le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum))) + return 0; if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk, map->m_len)) { ext4_error_inode(inode, func, line, map->m_pblk, -- 2.20.1