Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp700389ybz; Fri, 1 May 2020 07:03:25 -0700 (PDT) X-Google-Smtp-Source: APiQypIHv5Ayq2p34Y/LFSx81AvqaAOqjXBwsDJry2PSqFh0e7HjwRuoDvggQCw6vIm9yKueeMAY X-Received: by 2002:a17:907:118b:: with SMTP id uz11mr3229061ejb.89.1588341805692; Fri, 01 May 2020 07:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588341805; cv=none; d=google.com; s=arc-20160816; b=gBmt08UkCxYCnRwdBDMaYPdn+jbDEpYC8Dw64+vfZmU94q0GumBnccYr0MXhZKcj+Z w9yAVj0enE03rpul8Ut1V2KjAQXmbfjSPavF8bg1Hvu+67VgMTN9ulMnpTkOhSA6lbxk qMTBOHxO0lGzcTSeuQyVmyhgPVLs243+2gJIe97GV23RFxB46iCOk55RCumEC+Fuq5+S hyMtipMXB4c9OFxVuM7f0pa4kmFGivXq7gPjbS7ijyvdEhk6ASBrmWSZLMiwd1cbnykS C8tCbxHUjyBuVqUWxTlIkWUVJI/kD5w9iW1grZmqkWMOj3w6nZUgtqTpI6MzvBZTKcbz HlHw== 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=8+QQwxUWan7bRNW7TJpI8xBpKMourWzKB5bJcI3BQgw=; b=uFSyS3dmy4qtKOpQ2euBKLpWfetwbvhPWRUr0REiLpLezMtEtAsU/25AwaMO5HTtQ0 i0DX0MKj9+DxfG6zCx/RdVbuaQ/yMtXbihZxFy8Fewd/tGV48cT0J/3vVXLThYvdZwKQ 2aCow+FEO2p1bvbQxzNWABlDZ2r3NJJSuceyhkUH6ze7fd87AFJ4JCqwdTWy9+nMkuL6 lvow6f1OHBpLphTGsYH5e0uo+cFrEb6tkfp8ZxsGJlUb+s4Xf06apiArsEH/MQEleAfB uut3jM+4+w8gMcReFetcgdu2LtCsSMp7q1wqQc2FRUS7t61VaZcrP+/4KOAAqxzcASWj gdmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iY7ccQJS; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si1754537ejc.7.2020.05.01.07.03.00; Fri, 01 May 2020 07:03:25 -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=@kernel.org header.s=default header.b=iY7ccQJS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729430AbgEAN1Q (ORCPT + 99 others); Fri, 1 May 2020 09:27:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:49306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbgEAN1K (ORCPT ); Fri, 1 May 2020 09:27:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 0DE6F2173E; Fri, 1 May 2020 13:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339630; bh=U6wHYmVZu4W0Y4oJMZtHvRQCNsTdCl3JZ6AqzKEvvNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iY7ccQJSUdO8mXFELtCSoqJhgU5NaJm4iYoZodpmUOPYYXhFjS72Xk7deBIBkzSJ7 /f6eK2u9wgwwCEu65zQD3Bse8ZW7HB1JpL8N2narEqdjhLDec5njADH0TOYyU7YutI 7bKpC6yQpLOzFMcrd0aX+AFhYfoJVZJEz8c8h/Fg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org, Ashwin H Subject: [PATCH 4.4 67/70] ext4: protect journal inodes blocks using block_validity Date: Fri, 1 May 2020 15:21:55 +0200 Message-Id: <20200501131533.478577998@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.302599262@linuxfoundation.org> References: <20200501131513.302599262@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: Theodore Ts'o commit 345c0dbf3a30872d9b204db96b5857cd00808cae upstream. 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: Ashwin H Signed-off-by: Greg Kroah-Hartman --- fs/ext4/block_validity.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/inode.c | 4 +++ 2 files changed, 52 insertions(+) --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c @@ -136,6 +136,48 @@ static void debug_print_tree(struct ext4 printk("\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); @@ -170,6 +212,12 @@ int ext4_setup_system_zone(struct super_ 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(EXT4_SB(sb)); --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -377,6 +377,10 @@ static int __check_block_validity(struct 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,