Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp90052yba; Mon, 20 May 2019 05:32:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJ5haa7dx1JffhblDEBCV9RTwXTUqf2MprQ2QKEpaB5TOrgT6D20OJAIE1vDTTbSNnKbi6 X-Received: by 2002:a17:902:ca:: with SMTP id a68mr50667023pla.7.1558355533147; Mon, 20 May 2019 05:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355533; cv=none; d=google.com; s=arc-20160816; b=VsRGcqrpzIn3OpLe/zqE5ZybmiovYNeU7VvSM7YofAJJKwcuDvsXCSl8VhoLtmwlow Oy3zJ4oX5y1uC51QGYG8Akl3uuxpFIrUZevKm0hbgEN3xh7dACzdXT78azIlD0Eftq31 lMBjRMO9fLjf5WkfEjf13YGcgO6tofOizfEbsZTsg5y5tHpDz+VJPlk2jgAe+F3QI7OV doeXrZXZSqcP51Ze/r1KIarPIxN7cip/ARNE41/Q8t74eBiMxUonDwMX2FVlA+4wosKb hC4mCdZ3OcEn+zs8/hHTFWLZ4sL2xJTbgSzAJ1XwTVXjGBVd8t5IjkCnSIkz7obvkQQS i5Xg== 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=QRTd0Ac+xwlBZPySzHKnUqQfruoZcX1e+nVZa5+LToez+CieRofjf9eE/vhWppO78N +W/038sMvRpcbz9p0fWLKBeXO1ycQAD6No6O0DA2q4Dcr125qSFGo5iejsT6wlLwViyi eoWn91K+5CKJEoU84bXvI6HTZsXH1GU+kEhSiHBQ8l0WHmX5tWJBR0YO5EPvYuauF2tu SVcbUFL5x4HZJHZavhoFiTrr/hWp4JmfN17OcKzpYie+sCLzpYXwUNkYz0wkfrFhILcZ eUFz8IjNC7AA3pp6RNBuLQ3MN9Nblau/d5rJzhO/a1fTFCqxzjNACRrBXJaxXDeko9oY dz1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U2obDETV; 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 c20si445842pgw.378.2019.05.20.05.31.58; Mon, 20 May 2019 05:32: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=U2obDETV; 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 S2389811AbfETM3F (ORCPT + 99 others); Mon, 20 May 2019 08:29:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:45066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389790AbfETM3E (ORCPT ); Mon, 20 May 2019 08:29:04 -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 0FB0F20815; Mon, 20 May 2019 12:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355343; bh=iT4yjMJcKkltvxB7A3R4I/OGGLjYhEBIkJulcqRNo5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2obDETVcTUBGN11Eao5tiGCq+pBZBKHUVE2aM2PEJgxJd2zlZCIngYqeE0MTEzdl dcqaz/pg2iHxPq7ICRgzdg076ntL+gF/BdUBCoUjr8g/t0kEmKf9mu8toACdB70978 pGT/r8IDGzpf8BY+uKSeokzB8y1p3lT4eYLrU4fI= 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 5.0 083/123] ext4: protect journal inodes blocks using block_validity Date: Mon, 20 May 2019 14:14:23 +0200 Message-Id: <20190520115250.362769006@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@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,