From patchwork Sat Oct 8 07:55:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 118493 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1421CB70D6 for ; Sat, 8 Oct 2011 19:02:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753815Ab1JHH5a (ORCPT ); Sat, 8 Oct 2011 03:57:30 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:52576 "EHLO e6.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752744Ab1JHH51 (ORCPT ); Sat, 8 Oct 2011 03:57:27 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p987Uthm004575; Sat, 8 Oct 2011 03:30:55 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p987t5Qi233102; Sat, 8 Oct 2011 03:55:05 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p987t304030007; Sat, 8 Oct 2011 01:55:05 -0600 Received: from elm3c44.beaverton.ibm.com ([9.47.69.44]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p987t3aW029951; Sat, 8 Oct 2011 01:55:03 -0600 Subject: [PATCH 12/28] ext4: Use i_generation in inode-related metadata checksums To: Andreas Dilger , Theodore Tso , "Darrick J. Wong" From: "Darrick J. Wong" Cc: Sunil Mushran , Martin K Petersen , Greg Freemyer , Amir Goldstein , linux-kernel , Andi Kleen , Mingming Cao , Joel Becker , linux-fsdevel , linux-ext4@vger.kernel.org, Coly Li Date: Sat, 08 Oct 2011 00:55:02 -0700 Message-ID: <20111008075502.20506.15728.stgit@elm3c44.beaverton.ibm.com> In-Reply-To: <20111008075343.20506.23155.stgit@elm3c44.beaverton.ibm.com> References: <20111008075343.20506.23155.stgit@elm3c44.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Whenever we are calculating a checksum for a piece of metadata that is associated with an inode, incorporate i_generation into that calculation so that old metadata blocks cannot be re-associated after a delete/create cycle. Signed-off-by: Darrick J. Wong --- fs/ext4/ialloc.c | 9 ++++++--- fs/ext4/inode.c | 9 ++++++--- fs/ext4/ioctl.c | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 6e5876a..d4b59e9 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1031,11 +1031,14 @@ got: /* Precompute second piece of crc */ if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) { + __u32 crc; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); __le32 inum = cpu_to_le32(inode->i_ino); - ei->i_uuid_inum_crc = ext4_chksum(sbi, sbi->s_uuid_crc, - (__u8 *)&inum, - sizeof(inum)); + __le32 gen = cpu_to_le32(inode->i_generation); + crc = ext4_chksum(sbi, sbi->s_uuid_crc, (__u8 *)&inum, + sizeof(inum)); + ei->i_uuid_inum_crc = ext4_chksum(sbi, crc, (__u8 *)&gen, + sizeof(gen)); } ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b00315d..593f3bf 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3492,10 +3492,13 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) { struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); + __u32 crc; __le32 inum = cpu_to_le32(inode->i_ino); - ei->i_uuid_inum_crc = ext4_chksum(sbi, sbi->s_uuid_crc, - (__u8 *)&inum, - sizeof(inum)); + __le32 gen = raw_inode->i_generation; + crc = ext4_chksum(sbi, sbi->s_uuid_crc, (__u8 *)&inum, + sizeof(inum)); + ei->i_uuid_inum_crc = ext4_chksum(sbi, crc, (__u8 *)&gen, + sizeof(gen)); } if (!ext4_inode_csum_verify(inode, raw_inode, ei)) { diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index f18bfe3..fdf0b1e 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -149,6 +149,10 @@ flags_out: if (!inode_owner_or_capable(inode)) return -EPERM; + if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, + EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) + return -ENOTTY; + err = mnt_want_write(filp->f_path.mnt); if (err) return err;