Skip to contentSkip to conversation

e2fsck: don't ignore return values in e2fsck_rewrite_extent_tree

PATCH Superseded Harshad Shirwadkar 3 participants 8 messages Feb 19, 2021 – Feb 23, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 e2fsck: don't ignore return values in e2fsck_rewrite_extent_tree

From: Harshad Shirwadkar <[email protected]>

Don't ignore return values of ext2fs_read/write_inode_full() in e2fsck_rewrite_extent_tree.

---
 e2fsck/extents.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
e2fsck/extents.c +6 -6
index 600dbc97..f48f14ff 100644
@@ -290,8 +290,10 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
 	errcode_t err;
 
 	memset(&inode, 0, sizeof(inode));
-	ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-				sizeof(inode));
+	err = ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+				     sizeof(inode));
+	if (err)
+		return err;
 
 	/* Skip deleted inodes and inline data files */
 	if (inode.i_flags & EXT4_INLINE_DATA_FL)
@@ -306,10 +308,8 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
 	if (err)
 		return err;
 	ext2fs_iblk_set(ctx->fs, EXT2_INODE(&inode), blk_count);
-	ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-		sizeof(inode));
-
-	return 0;
+	return ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+				       sizeof(inode));
 }
 
 errcode_t e2fsck_read_extents(e2fsck_t ctx, struct extent_list *extents)
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#1 lore raw

PATCH 2/4 ext2fs: don't ignore return value in ext2fs_count_blocks

From: Harshad Shirwadkar <[email protected]>

Don't ignore return value of ext2fs_get_array() in ext2fs_count_blocks().

---
 lib/ext2fs/extent.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
lib/ext2fs/extent.c +5 -2
index 1a87e68b..9e611038 100644
@@ -1824,8 +1824,11 @@ errcode_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
 	if (errcode)
 		goto out;
 
-	ext2fs_get_array(handle->max_depth, sizeof(blk64_t),
-				&intermediate_nodes);
+	errcode = ext2fs_get_array(handle->max_depth, sizeof(blk64_t),
+				   &intermediate_nodes);
+	if (errcode)
+		goto out;
+
 	blkcount = handle->level;
 	while (!errcode) {
 		if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) {
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#2 lore raw

PATCH 3/4 e2fsck: add fallthrough comment in fc replay switch case

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

During fast commit replay scan phase, in ext4_fc_replay_scan(), we want to fallthrough in switch case for EXT4_FC_TAG_ADD_RANGE case. Add a comment for that.

---
 e2fsck/journal.c | 1 +
 1 file changed, 1 insertion(+)
e2fsck/journal.c +1 -0
index 2708942a..a67ef745 100644
@@ -325,6 +325,7 @@ static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
 				ret = JBD2_FC_REPLAY_STOP;
 			else
 				ret = JBD2_FC_REPLAY_CONTINUE;
+			/* fallthrough */
 		case EXT4_FC_TAG_DEL_RANGE:
 		case EXT4_FC_TAG_LINK:
 		case EXT4_FC_TAG_UNLINK:
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#3 lore raw

PATCH 4/4 e2fsck: initialize variable before first use in fast commit replay

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first use.

---
 e2fsck/journal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
e2fsck/journal.c +1 -1
index a67ef745..8e7ba819 100644
@@ -289,7 +289,7 @@ static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
 	struct ext4_fc_tail *tail;
 	__u8 *start, *end;
 	struct ext4_fc_head *head;
-	struct ext2fs_extent ext2fs_ex;
+	struct ext2fs_extent ext2fs_ex = {0};
 
 	state = &ctx->fc_replay_state;
 
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#4 lore raw

Re: [PATCH 4/4] e2fsck: initialize variable before first use in fast commit replay

Quoted 6 lines · Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first use.

I wonder if we should make the following change to ext2fs_decode_extent(), which will prevent other future bugs to potential users of the function:

	to->e_pblk = ext2fs_le32_to_cpu(from->ee_start) +
		((__u64) ext2fs_le16_to_cpu(from->ee_start_hi)
			<< 32);
	to->e_lblk = ext2fs_le32_to_cpu(from->ee_block);
	to->e_len = ext2fs_le16_to_cpu(from->ee_len);

- to->e_flags |= EXT2_EXTENT_FLAGS_LEAF;
+ to->e_flags = EXT2_EXTENT_FLAGS_LEAF;

ext2fs_decode_extent() overwrites all other members of the structure, so we might as well just initialize e_flags as opposed to depending the caller to initiaize *to just for the sake of to->e_flags.

Cheers,

- Ted

#5 lore raw

Re: [PATCH 4/4] e2fsck: initialize variable before first use in fast commit replay

Thanks Ted, it makes sense, will fix this in V2.

- Harshad

Quoted 28 lines · Theodore Ts'o
Quoted 6 lines · Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first use.

I wonder if we should make the following change to ext2fs_decode_extent(), which will prevent other future bugs to potential users of the function:

        to->e_pblk = ext2fs_le32_to_cpu(from->ee_start) +
                ((__u64) ext2fs_le16_to_cpu(from->ee_start_hi)
                        << 32);
        to->e_lblk = ext2fs_le32_to_cpu(from->ee_block);
        to->e_len = ext2fs_le16_to_cpu(from->ee_len);
(quoted diff) +1 -1
-       to->e_flags |= EXT2_EXTENT_FLAGS_LEAF;
+       to->e_flags = EXT2_EXTENT_FLAGS_LEAF;

ext2fs_decode_extent() overwrites all other members of the structure, so we might as well just initialize e_flags as opposed to depending the caller to initiaize *to just for the sake of to->e_flags.

Cheers,

- Ted

#6 lore raw
In reply to Harshad Shirwadkar

Hello Harshad,

ext2fs_iblk_set in the same e2fsck_rewrite_extent_tee returns a return code, but code is ignored. Could you also add check there?

Best regards,
Artem Blagodarenko

Quoted 45 lines · Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Don't ignore return values of ext2fs_read/write_inode_full() in e2fsck_rewrite_extent_tree.

---
e2fsck/extents.c | 12 ++++++------

1 file changed, 6 insertions(+), 6 deletions(-)
e2fsck/extents.c +6 -6
index 600dbc97..f48f14ff 100644
@@ -290,8 +290,10 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
 	errcode_t err;
 
 	memset(&inode, 0, sizeof(inode));
-	ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-				sizeof(inode));
+	err = ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+				     sizeof(inode));
+	if (err)
+		return err;
 
 	/* Skip deleted inodes and inline data files */
 	if (inode.i_flags & EXT4_INLINE_DATA_FL)
@@ -306,10 +308,8 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
 	if (err)
 		return err;
 	ext2fs_iblk_set(ctx->fs, EXT2_INODE(&inode), blk_count);
-	ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-		sizeof(inode));
-
-	return 0;
+	return ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+				       sizeof(inode));
 }
 
 errcode_t e2fsck_read_extents(e2fsck_t ctx, struct extent_list *extents)
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#7 lore raw

Thanks Artem, will fix this in V2.

- Harshad

Quoted 55 lines · Благодаренко Артём

Hello Harshad,

ext2fs_iblk_set in the same e2fsck_rewrite_extent_tee returns a return code, but code is ignored. Could you also add check there?

Best regards,
Artem Blagodarenko

Quoted 45 lines · Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Don't ignore return values of ext2fs_read/write_inode_full() in e2fsck_rewrite_extent_tree.

---
e2fsck/extents.c | 12 ++++++------

1 file changed, 6 insertions(+), 6 deletions(-)
e2fsck/extents.c +6 -7
index 600dbc97..f48f14ff 100644
@@ -290,8 +290,10 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
      errcode_t err;
 
      memset(&inode, 0, sizeof(inode));
-     ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-                             sizeof(inode));
+     err = ext2fs_read_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+                                  sizeof(inode));
+     if (err)
+             return err;
 
      /* Skip deleted inodes and inline data files */
      if (inode.i_flags & EXT4_INLINE_DATA_FL)
@@ -306,10 +308,8 @@ errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx, struct extent_list *list)
      if (err)
              return err;
      ext2fs_iblk_set(ctx->fs, EXT2_INODE(&inode), blk_count);
-     ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
-             sizeof(inode));
-
-     return 0;
+     return ext2fs_write_inode_full(ctx->fs, list->ino, EXT2_INODE(&inode),
+                                    sizeof(inode));
 }
 
 errcode_t e2fsck_read_extents(e2fsck_t ctx, struct extent_list *extents)
--

2.30.0.617.g56c4b15f3c-goog