Skip to contentSkip to conversation

ext4: report error if things go wrong when do checksum

PATCH Applied Guo Chao 4 participants 9 messages Jan 5, 2013 – Jan 7, 2013 ext4 file system

lore
Share & tools
lore

Guo Chao

author
#0 lore raw

PATCH 1/3 ext4: report error if things go wrong when do checksum

In ext4_dx_csum_verify(), if we detect corrupted data, we do not compare checksum because checksum itself may be wrong, but we should report error in this case.

Cc Darrick J. Wong <[email protected]>
---
 fs/ext4/namei.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/namei.c +2 -2
index cac4482..843e29f 100644
@@ -370,14 +370,14 @@ static int ext4_dx_csum_verify(struct inode *inode,
 	c = get_dx_countlimit(inode, dirent, &count_offset);
 	if (!c) {
 		EXT4_ERROR_INODE(inode, "dir seems corrupt?  Run e2fsck -D.");
-		return 1;
+		return 0;
 	}
 	limit = le16_to_cpu(c->limit);
 	count = le16_to_cpu(c->count);
 	if (count_offset + (limit * sizeof(struct dx_entry)) >
 	    EXT4_BLOCK_SIZE(inode->i_sb) - sizeof(struct dx_tail)) {
 		warn_no_space_for_csum(inode);
-		return 1;
+		return 0;
 	}
 	t = (struct dx_tail *)(((struct dx_entry *)c) + limit);
 
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/3 ext4: release buffer in failed path in dx_probe()

If checksum fails, we should also release the buffer read from previous iteration.

Cc Darrick J. Wong <[email protected]>
---
 fs/ext4/namei.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +1 -1
index 843e29f..e249a47 100644
@@ -722,7 +722,7 @@ dx_probe(const struct qstr *d_name, struct inode *dir,
 			ext4_warning(dir->i_sb, "Node failed checksum");
 			brelse(bh);
 			*err = ERR_BAD_DX_DIR;
-			goto fail;
+			goto fail2;
 		}
 		set_buffer_verified(bh);
 
Signature · 1 line
1.7.9.5
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] ext4: release buffer in failed path in dx_probe()

Quoted 14 lines · Guo Chao

If checksum fails, we should also release the buffer read from previous iteration.

Cc Darrick J. Wong <[email protected]>
---
 fs/ext4/namei.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +0 -0
index 843e29f..e249a47 100644

fs/ext4/namei.c dx_probe(const struct qstr *d_name, struct inode *dir, · line 725

Quoted 5 lines
fs/ext4/namei.c +1 -1
@@ -722,7 +722,7 @@ dx_probe(const struct qstr *d_name, struct inode *dir,
 			ext4_warning(dir->i_sb, "Node failed checksum");
 			brelse(bh);
 			*err = ERR_BAD_DX_DIR;
-			goto fail;
+			goto fail2;

Good catch!

--D

Quoted 6 lines
fs/ext4/namei.c +0 -0
 		}
 		set_buffer_verified(bh);
 
Signature · 1 line
1.7.9.5
maintainer Applied
#3 lore raw

Re: [PATCH 2/3] ext4: release buffer in failed path in dx_probe()

Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Guo Chao

If checksum fails, we should also release the buffer read from previous iteration.

Cc Darrick J. Wong <[email protected]>

Thanks, applied.

Quoted 1 line

BTW, technically speaking it should be "Reviewed-by"; that's what I've used in the commit.

"Acked-by:" gets used when a commit touches multiple subsystem trees. For example, suppose someone changes a function in fs/direct-io.c, which also required changes in btrfs, xfs, and ext4. This commit might go through Al Viro's vfs tree, and might have an Acked-by from Chris Mason, Dave Chinner, and me, indicating that developers who are well versed in those trees have agreed that the patches which touched those other subsystems looked sane.

Since in this case the commit only touches ext4 code, and is going through the ext4 tree, "Reviewed-by" is what normally gets used.

Cheers,

- Ted

author
#4 lore raw

PATCH 3/3 ext4: remove duplicate assignment in ext4_init_new_dir()

In reply to Guo Chao

It should be a typo unless I miss something.

---
 fs/ext4/namei.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/namei.c +0 -1
index e249a47..db3b1e9 100644
@@ -2368,7 +2368,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
 	}
 
 	inode->i_size = EXT4_I(inode)->i_disksize = blocksize;
-	dir_block = ext4_bread(handle, inode, 0, 1, &err);
 	if (!(dir_block = ext4_bread(handle, inode, 0, 1, &err))) {
 		if (!err) {
 			err = -EIO;
Signature · 1 line
1.7.9.5
Acked-by on v1 3/3
#5 lore raw

Re: [PATCH 3/3] ext4: remove duplicate assignment in ext4_init_new_dir()

Quoted 4 lines · Guo Chao

It should be a typo unless I miss something.

oh, you are right. Thanks for the fix. And I really can't recall how I messed this up.

Quoted 17 lines
---
 fs/ext4/namei.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/namei.c +0 -1
index e249a47..db3b1e9 100644
@@ -2368,7 +2368,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
 	}
 
 	inode->i_size = EXT4_I(inode)->i_disksize = blocksize;
-	dir_block = ext4_bread(handle, inode, 0, 1, &err);
 	if (!(dir_block = ext4_bread(handle, inode, 0, 1, &err))) {
 		if (!err) {
 			err = -EIO;
#7 lore raw
In reply to Guo Chao
Quoted 18 lines · Guo Chao

In ext4_dx_csum_verify(), if we detect corrupted data, we do not compare checksum because checksum itself may be wrong, but we should report error in this case.

Cc Darrick J. Wong <[email protected]>
---
 fs/ext4/namei.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/namei.c +0 -0
index cac4482..843e29f 100644
@@ -370,14 +370,14 @@ static int ext4_dx_csum_verify(struct inode *inode,
 	c = get_dx_countlimit(inode, dirent, &count_offset);
 	if (!c) {
 		EXT4_ERROR_INODE(inode, "dir seems corrupt?  Run e2fsck -D.");

fs/ext4/namei.c static int ext4_dx_csum_verify(struct inode *inode, · line 380

Quoted 10 lines
fs/ext4/namei.c +2 -2
-		return 1;
+		return 0;
 	}
 	limit = le16_to_cpu(c->limit);
 	count = le16_to_cpu(c->count);
 	if (count_offset + (limit * sizeof(struct dx_entry)) >
 	    EXT4_BLOCK_SIZE(inode->i_sb) - sizeof(struct dx_tail)) {
 		warn_no_space_for_csum(inode);
-		return 1;
+		return 0;

In both of these cases we cannot figure out where the dx block checksum lives, and therefore we have no stored checksum to compare against. This can result from enabling checksums on a existing filesystem and ignoring tune2fs' request to run fsck -D to rebuild dx blocks that are completely full. However, since we haven't a checksum that we could use to decide if there's real corruption, there's no cause to return -EIO to the user. Therefore, we print a warning and trust the sanity checks to catch totally bogus blocks, which is the best we can hope for.

Sorry, but this doesn't seem necessary.

--D

Quoted 6 lines
fs/ext4/namei.c +0 -0
 	}
 	t = (struct dx_tail *)(((struct dx_entry *)c) + limit);
 
Signature · 1 line
1.7.9.5
author
#8 lore raw

Hello, Darrick,

Quoted 39 lines · Darrick J. Wong
Quoted 18 lines · Guo Chao

In ext4_dx_csum_verify(), if we detect corrupted data, we do not compare checksum because checksum itself may be wrong, but we should report error in this case.

Cc Darrick J. Wong <[email protected]>
---
 fs/ext4/namei.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/namei.c +0 -0
index cac4482..843e29f 100644
@@ -370,14 +370,14 @@ static int ext4_dx_csum_verify(struct inode *inode,
 	c = get_dx_countlimit(inode, dirent, &count_offset);
 	if (!c) {
 		EXT4_ERROR_INODE(inode, "dir seems corrupt?  Run e2fsck -D.");

fs/ext4/namei.c static int ext4_dx_csum_verify(struct inode *inode, · line 380

Quoted 10 lines
fs/ext4/namei.c +2 -2
-		return 1;
+		return 0;
 	}
 	limit = le16_to_cpu(c->limit);
 	count = le16_to_cpu(c->count);
 	if (count_offset + (limit * sizeof(struct dx_entry)) >
 	    EXT4_BLOCK_SIZE(inode->i_sb) - sizeof(struct dx_tail)) {
 		warn_no_space_for_csum(inode);
-		return 1;
+		return 0;

In both of these cases we cannot figure out where the dx block checksum lives, and therefore we have no stored checksum to compare against. This can result from enabling checksums on a existing filesystem and ignoring tune2fs' request to run fsck -D to rebuild dx blocks that are completely full. However, since we haven't a checksum that we could use to decide if there's real corruption, there's no cause to return -EIO to the user. Therefore, we print a warning and trust the sanity checks to catch totally bogus blocks, which is the best we can hope for.

Quoted 1 line

Sorry, but this doesn't seem necessary.

Thanks for the explaination.

I think ext4_dirent_csum_verify() can encounter similar problem but return error. But I'm not sure it's the same case.

Thanks,
Guo Chao

Quoted 7 lines

--D

Quoted 6 lines
fs/ext4/namei.c +0 -0
 	}
 	t = (struct dx_tail *)(((struct dx_entry *)c) + limit);
 
Signature · 1 line
1.7.9.5