Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp85041yba; Mon, 20 May 2019 05:26:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxF08xkuTgXZoH9mhuRNV622U6Aw/Mg4cXlMm9IS2VHawt9IL/kiCArM7coUTi1ny7vPvnP X-Received: by 2002:a65:624f:: with SMTP id q15mr75383877pgv.436.1558355207035; Mon, 20 May 2019 05:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355207; cv=none; d=google.com; s=arc-20160816; b=vBbKZ6aaVNU5cILcnFS85vMmKsqxA8cg1Go7ITky0ieVTaR/TgEW94Ed4ohwASyyzD Aveobz6CSdlySAUAHIhDM6YYWruxLhfFr1PFKDFiBx+J8dolJdUVa0+UUlzOzqe+FKqL 3BupaUy2jOPJyWt0uAOU2VIjLdzd43VFsj6484Y2vpyYVU+IZjZnGNv/48Gj9328bGgG 0WDO318XzZcbXBKXsl5KDVCvHOvRVzY0aK+cGY4E0wflg/zVlJXHe2nEzKKFhGzMBeEX dlTLZiy+Kpzerq1JQTqSJ96AK5iPM6I5Olq+5VvUpY542vgIAr8pB95Ng/P5X4YabcJr q++g== 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=SbqgAJnN2NCI2tcooXxipJGpnx7R37aUjxiFH5rEg44=; b=idS4/6/eegLSdiKKqREn3/Rl+QC+/6p2Pv5WzX8nS1qOzoYILmYRKB5LmYPYEpgdF/ 06u/c2iCzAMhZnhQlydZ5SVIvy5xVYvo83LIwkfWYlCI4LblFsoyhLjlyBsxuSKeVGre MQyH1W/2L5QswzHJIfv46U7XkwmTee47rR64Ys8O2wt6/yS/oDS3QODeExquq2e+q/kq yxrrdY98VKWwIArgz6FsXV2shw6spHK+KQINy0ggUw+gIUWtYNpjqF5lYbRPB5Ad7I5Y DM2cH8GWcxekaktADmKPwFwddJnHkcwBsc2qT0SX2NLtpAantSfyILPrEACopUe3pHdE MOQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0kc0qPmM; 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 n63si17817860pgn.511.2019.05.20.05.26.32; Mon, 20 May 2019 05:26:47 -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=0kc0qPmM; 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 S2388684AbfETMXr (ORCPT + 99 others); Mon, 20 May 2019 08:23:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388637AbfETMXm (ORCPT ); Mon, 20 May 2019 08:23:42 -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 9C56420675; Mon, 20 May 2019 12:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355022; bh=iT4yjMJcKkltvxB7A3R4I/OGGLjYhEBIkJulcqRNo5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0kc0qPmMYznXmitgw2wDP/t/K+1UMCGsFOFkzxvJldjAgBI/+Z5ok0yPAE4Jq1KVT QOjrNNZKuGNFgYVzLPNBxWxQVuS6MPKtmbve2lZhRUxIWMVJW6NSxqUUUrLooRoXMQ 85Fb0KPWOOl1ZrOQOgiV/jm9f9MtUHgiU0AiVjL0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org Subject: [PATCH 4.19 067/105] ext4: protect journal inodes blocks using block_validity Date: Mon, 20 May 2019 14:14:13 +0200 Message-Id: <20190520115251.802050920@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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: 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 @@ -137,6 +137,48 @@ static void debug_print_tree(struct ext4 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_ 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); --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -399,6 +399,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,