Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1021263ybz; Wed, 29 Apr 2020 13:34:12 -0700 (PDT) X-Google-Smtp-Source: APiQypIjsZZfHSPl5kODslyI7WyGDiuPWhfZPRG2wK9QXdvOPcOYlGbbGVg5DMKXEPVF66oQ3uEy X-Received: by 2002:a17:906:8152:: with SMTP id z18mr4268765ejw.4.1588192452424; Wed, 29 Apr 2020 13:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588192452; cv=none; d=google.com; s=arc-20160816; b=ZBvHpBsIF3tXcHZ4wSTjtt+crQUiWrPhZmh4TsOyg+FTIR0uuXneFanMZdk9ZXoakt syqpJydA/4OWNTZXj9+7VfP4UeGGbW1PzCP1ub9SwpYHVwoVGC3dYbUw+V0IGEFUqRlc z+Zg+GjBISjO96R1rDDptXkVnEqFURcg8FCwKHgsUv/tq2vIMnc1NTJVSiAmH6qwp17e EOUV3Uq90xfamKs6n329q+cFaP7AjaRgKKYD+XFLmdjnbnm4jTNGIupEb5ChJHCtahUr cEixQ7s80IFisPXfNDpibb0fxK2L6efb1oliEJ/OucPOXhIdKeENIU3SvIxhgIE4zBLN pxXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=vdUMSOMykym+IFC1hDtmGrgPJf0Kae+rGXreyjLLCjY=; b=pTEkC1Rm3z5wMZ2UB+sshtzLyhoPM2ylL51g0kiSfe8wMBVTaRD3MZ6QBtQivHGQdn NBz8f3zZWV3Q6EVzD85d5VRIBSsMWgJd/alOmyUwU3DdiSz1eUKKGkZUKDncO1jah9zT s9+r/2y0lt3HsdvjBSA1C9XeojRRqvOtNEifX4x2JeKYcRU3jfK2OU+G4ERqUM7gGR1S Plxuv/Icf5IW+rgsZmL0OQLD7Wy2s+lFuSLT/uiwahHBFMiOFprBlmfzHM5lMCr8hSf7 aCBRTP+eov3hn4AijN1purVq/tyMp9QxYGIzj5k3KTl1SD4gAKEnfQsmdrBCFZGJS0kK 0Tdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd8si4981858ejb.486.2020.04.29.13.33.48; Wed, 29 Apr 2020 13:34:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbgD2Udh (ORCPT + 99 others); Wed, 29 Apr 2020 16:33:37 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:13784 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbgD2Udh (ORCPT ); Wed, 29 Apr 2020 16:33:37 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Wed, 29 Apr 2020 13:33:33 -0700 Received: from localhost.localdomain (ashwinh-vm-1.vmware.com [10.110.19.225]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 55D6240F60; Wed, 29 Apr 2020 13:33:33 -0700 (PDT) From: ashwin-h To: , CC: , , , , , , , , , Ashwin H Subject: [PATCH 2/5] ext4: protect journal inode's blocks using block_validity Date: Thu, 30 Apr 2020 09:52:04 +0530 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: ashwinh@vmware.com does not designate permitted sender hosts) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@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 Signed-off-by: Ashwin H Cc: stable@kernel.org --- 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 bee888e..2370dfd 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(EXT4_SB(sb)); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07476c1..390431d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -407,6 +407,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.7.4