From d6ca0491a138168cdf9e1f00d82b74fbffebea43 Mon Sep 17 00:00:00 2001 From: Weifeng Su Date: Sun, 25 Jun 2023 15:31:56 +0000 Subject: [PATCH] Backport patches from upstream Signed-off-by: Weifeng Su (cherry picked from commit 4134e45e6faaa91830048ba67cc0a8f5482d948e) --- ...-fs-freed-in-ext2fs_run_ext3_journal.patch | 69 ++++++----- ...e2fs-avoid-memory-leak-on-error-path.patch | 46 +++++++ ...mory-leak-in-error-path-while-openin.patch | 43 +++++++ ...oretical-null-dereference-in-end_pro.patch | 42 +++++++ ...tial-out-of-bounds-read-in-inc_ea_in.patch | 56 +++++++++ ...-of-bounds-write-for-very-deep-exten.patch | 71 +++++++++++ ...tial-fencepost-error-in-e2fsck_shoul.patch | 55 +++++++++ ...tential-integer-overflow-in-bitmap-a.patch | 53 ++++++++ 0034-tune2fs-fix-an-error-message.patch | 36 ++++++ ...ow-journal-inode-to-have-encrypt-fla.patch | 113 ++++++++++++++++++ ...nbalanced-mutex-unlock-for-BOUNCE_MT.patch | 31 +++++ ...ix-ext2fs_compare_generic_bmap-logic.patch | 41 +++++++ 0038-Quiet-unused-variable-warnings.patch | 72 +++++++++++ ...t-lseek-when-_FILE_OFFSET_BITS-is-64.patch | 40 +++++++ e2fsprogs.spec | 18 ++- 15 files changed, 750 insertions(+), 36 deletions(-) create mode 100644 0027-dumpe2fs-resize2fs-avoid-memory-leak-on-error-path.patch create mode 100644 0028-libext2fs-fix-memory-leak-in-error-path-while-openin.patch create mode 100644 0029-e2fsck-avoid-theoretical-null-dereference-in-end_pro.patch create mode 100644 0030-e2fsck-fix-potential-out-of-bounds-read-in-inc_ea_in.patch create mode 100644 0031-e2fsck-avoid-out-of-bounds-write-for-very-deep-exten.patch create mode 100644 0032-e2fsck-fix-potential-fencepost-error-in-e2fsck_shoul.patch create mode 100644 0033-libext2fs-fix-potential-integer-overflow-in-bitmap-a.patch create mode 100644 0034-tune2fs-fix-an-error-message.patch create mode 100644 0035-e2fsck-don-t-allow-journal-inode-to-have-encrypt-fla.patch create mode 100644 0036-lib-ext2fs-fix-unbalanced-mutex-unlock-for-BOUNCE_MT.patch create mode 100644 0037-libext2fs-fix-ext2fs_compare_generic_bmap-logic.patch create mode 100644 0038-Quiet-unused-variable-warnings.patch create mode 100644 0039-ext2fs-Use-64bit-lseek-when-_FILE_OFFSET_BITS-is-64.patch diff --git a/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch b/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch index 501120b..93f620a 100644 --- a/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch +++ b/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch @@ -1,35 +1,34 @@ -From 3d967e53033c85ad5d3af1a42efb2c4f7501c356 Mon Sep 17 00:00:00 2001 -From: lijinlin3@huawei.com -Date: Fri, 16 Sep 2022 18:15:02 +0200 -Subject: [PATCH] tune2fs: exit directly when fs freed in ext2fs_run_ext3_journal - -In ext2fs_run_ext3_journal(), fs will be free and reallocate. But -reallocating by ext2fs_open() may fail in some cases, such as device -being offline at the same time. In these cases, goto closefs will -cause segfault, fix it by exiting directly. - -Signed-off-by: Li Jinlin ---- - misc/tune2fs.c | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/misc/tune2fs.c b/misc/tune2fs.c -index 088f87e5..ee57dc7c 100644 ---- a/misc/tune2fs.c -+++ b/misc/tune2fs.c -@@ -3344,8 +3344,11 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" - com_err("tune2fs", retval, - "while recovering journal.\n"); - printf(_("Please run e2fsck -fy %s.\n"), argv[1]); -- rc = 1; -- goto closefs; -+ if (fs) { -+ rc = 1; -+ goto closefs; -+ } -+ exit(1); - } - sb = fs->super; - } --- -2.23.0 +From 47ab1faccb228e10869898c8a02b06f5a91a9174 Mon Sep 17 00:00:00 2001 +From: Li Jinlin +Date: Fri, 16 Sep 2022 15:42:23 +0800 +Subject: tune2fs: exit directly when fs freed in ext2fs_run_ext3_journal + +In ext2fs_run_ext3_journal(), fs will be freed and reallocated. +However, the reallocation by ext2fs_open() may fail in some cases --- +for example, when the device becomes offline. To avoid a segfault, +exit if fs is NULL. + +[ Simplified the patch by by simply exiting if fs is NULL -TYT ] + +Signed-off-by: Li Jinlin +Signed-off-by: Theodore Ts'o +--- + misc/tune2fs.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index bed3d95b..f566ed81 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -3106,6 +3106,8 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + com_err("tune2fs", retval, + "while recovering journal.\n"); + printf(_("Please run e2fsck -fy %s.\n"), argv[1]); ++ if (!fs) ++ exit(1); + rc = 1; + goto closefs; + } +-- +cgit + diff --git a/0027-dumpe2fs-resize2fs-avoid-memory-leak-on-error-path.patch b/0027-dumpe2fs-resize2fs-avoid-memory-leak-on-error-path.patch new file mode 100644 index 0000000..d63ff28 --- /dev/null +++ b/0027-dumpe2fs-resize2fs-avoid-memory-leak-on-error-path.patch @@ -0,0 +1,46 @@ +From ba18f6efec62a1706b4bcf8fffd27611022260b8 Mon Sep 17 00:00:00 2001 +From: zhanchengbin +Date: Fri, 31 Dec 2021 15:42:40 +0800 +Subject: dumpe2fs, resize2fs: avoid memory leak on error path + +Link: https://lore.kernel.org/r/cbfd9852-bc89-1e83-f101-36fd29a0e70e@huawei.com +Signed-off-by: zhanchengbin +Signed-off-by: Theodore Ts'o +--- + misc/dumpe2fs.c | 1 + + resize/resize2fs.c | 4 ++-- + 2 files changed, 3 insertions(+), 2 deletions(-) + +diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c +index 3f4fc4ed..ef6d1cb8 100644 +--- a/misc/dumpe2fs.c ++++ b/misc/dumpe2fs.c +@@ -338,6 +338,7 @@ static void list_bad_blocks(ext2_filsys fs, int dump) + if (retval) { + com_err("ext2fs_badblocks_list_iterate_begin", retval, + "%s", _("while printing bad block list")); ++ ext2fs_badblocks_list_free(bb_list); + return; + } + if (dump) { +diff --git a/resize/resize2fs.c b/resize/resize2fs.c +index d69cb01e..916b1f4b 100644 +--- a/resize/resize2fs.c ++++ b/resize/resize2fs.c +@@ -1781,11 +1781,11 @@ static errcode_t block_mover(ext2_resize_t rfs) + fs->inode_blocks_per_group, + &rfs->itable_buf); + if (retval) +- return retval; ++ goto errout; + } + retval = ext2fs_create_extent_table(&rfs->bmap, 0); + if (retval) +- return retval; ++ goto errout; + + /* + * The first step is to figure out where all of the blocks +-- +cgit + diff --git a/0028-libext2fs-fix-memory-leak-in-error-path-while-openin.patch b/0028-libext2fs-fix-memory-leak-in-error-path-while-openin.patch new file mode 100644 index 0000000..0243466 --- /dev/null +++ b/0028-libext2fs-fix-memory-leak-in-error-path-while-openin.patch @@ -0,0 +1,43 @@ +From 1c966c9dffef7e823a020a2f3982e9b9b1953e8b Mon Sep 17 00:00:00 2001 +From: zhanchengbin +Date: Fri, 31 Dec 2021 15:43:36 +0800 +Subject: libext2fs: fix memory leak in error path while opening test_io + manager + +Link: https://lore.kernel.org/r/d0632bbc-9713-38a9-c914-137b702f6ae1@huawei.com +Signed-off-by: zhanchengbin +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/test_io.c | 2 ++ + lib/ext2fs/undo_io.c | 2 ++ + 2 files changed, 4 insertions(+) + +diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c +index 480e68fc..6843edbc 100644 +--- a/lib/ext2fs/test_io.c ++++ b/lib/ext2fs/test_io.c +@@ -248,6 +248,8 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel) + return 0; + + cleanup: ++ if (io && io->name) ++ ext2fs_free_mem(&io->name); + if (io) + ext2fs_free_mem(&io); + if (data) +diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c +index eb56f53d..f4a6d526 100644 +--- a/lib/ext2fs/undo_io.c ++++ b/lib/ext2fs/undo_io.c +@@ -790,6 +790,8 @@ cleanup: + io_channel_close(data->real); + if (data) + ext2fs_free_mem(&data); ++ if (io && io->name) ++ ext2fs_free_mem(&io->name); + if (io) + ext2fs_free_mem(&io); + return retval; +-- +cgit + diff --git a/0029-e2fsck-avoid-theoretical-null-dereference-in-end_pro.patch b/0029-e2fsck-avoid-theoretical-null-dereference-in-end_pro.patch new file mode 100644 index 0000000..2fe4bc6 --- /dev/null +++ b/0029-e2fsck-avoid-theoretical-null-dereference-in-end_pro.patch @@ -0,0 +1,42 @@ +From fdec633fd661e79b7b81e848b5699775328d70ae Mon Sep 17 00:00:00 2001 +From: zhanchengbin +Date: Fri, 31 Dec 2021 15:43:10 +0800 +Subject: e2fsck: avoid theoretical null dereference in end_problem_latch() + +This should only happen if there is a programming bug, but better safe +than sorry. + +Link: https://lore.kernel.org/r/9a9c6658-a8b3-794a-85df-c3bdf0470111@huawei.com +Signed-off-by: zhanchengbin +Signed-off-by: Theodore Ts'o +--- + e2fsck/problem.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/e2fsck/problem.c b/e2fsck/problem.c +index 46a74273..95f0ace8 100644 +--- a/e2fsck/problem.c ++++ b/e2fsck/problem.c +@@ -2321,6 +2321,8 @@ int end_problem_latch(e2fsck_t ctx, int mask) + int answer = -1; + + ldesc = find_latch(mask); ++ if (!ldesc) ++ return answer; + if (ldesc->end_message && (ldesc->flags & PRL_LATCHED)) { + clear_problem_context(&pctx); + answer = fix_problem(ctx, ldesc->end_message, &pctx); +@@ -2467,8 +2469,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx) + * Do special latch processing. This is where we ask the + * latch question, if it exists + */ +- if (ptr->flags & PR_LATCH_MASK) { +- ldesc = find_latch(ptr->flags & PR_LATCH_MASK); ++ if (ptr->flags & PR_LATCH_MASK && ++ (ldesc = find_latch(ptr->flags & PR_LATCH_MASK)) != NULL) { + if (ldesc->question && !(ldesc->flags & PRL_LATCHED)) { + ans = fix_problem(ctx, ldesc->question, pctx); + if (ans == 1) +-- +cgit + diff --git a/0030-e2fsck-fix-potential-out-of-bounds-read-in-inc_ea_in.patch b/0030-e2fsck-fix-potential-out-of-bounds-read-in-inc_ea_in.patch new file mode 100644 index 0000000..7bc63f0 --- /dev/null +++ b/0030-e2fsck-fix-potential-out-of-bounds-read-in-inc_ea_in.patch @@ -0,0 +1,56 @@ +From 1052048fb8f4ddcc0160eb670ef746ef7ee505a4 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Mon, 6 Jun 2022 11:39:23 -0400 +Subject: e2fsck: fix potential out-of-bounds read in inc_ea_inode_refs() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +If there isn't enough space for a full extended attribute entry, +inc_ea_inode_refs() might end up reading beyond the allocated memory +buffer. + +Reported-by: Nils Bars +Reported-by: Moritz Schlögel +Reported-by: Nico Schiller +Signed-off-by: Theodore Ts'o +--- + e2fsck/pass1.c | 13 ++++++++----- + 1 file changed, 8 insertions(+), 5 deletions(-) + +diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c +index dde862a8..2a17bb8a 100644 +--- a/e2fsck/pass1.c ++++ b/e2fsck/pass1.c +@@ -389,13 +389,13 @@ static problem_t check_large_ea_inode(e2fsck_t ctx, + static void inc_ea_inode_refs(e2fsck_t ctx, struct problem_context *pctx, + struct ext2_ext_attr_entry *first, void *end) + { +- struct ext2_ext_attr_entry *entry; ++ struct ext2_ext_attr_entry *entry = first; ++ struct ext2_ext_attr_entry *np = EXT2_EXT_ATTR_NEXT(entry); + +- for (entry = first; +- (void *)entry < end && !EXT2_EXT_IS_LAST_ENTRY(entry); +- entry = EXT2_EXT_ATTR_NEXT(entry)) { ++ while ((void *) entry < end && (void *) np < end && ++ !EXT2_EXT_IS_LAST_ENTRY(entry)) { + if (!entry->e_value_inum) +- continue; ++ goto next; + if (!ctx->ea_inode_refs) { + pctx->errcode = ea_refcount_create(0, + &ctx->ea_inode_refs); +@@ -408,6 +408,9 @@ static void inc_ea_inode_refs(e2fsck_t ctx, struct problem_context *pctx, + } + ea_refcount_increment(ctx->ea_inode_refs, entry->e_value_inum, + 0); ++ next: ++ entry = np; ++ np = EXT2_EXT_ATTR_NEXT(entry); + } + } + +-- +cgit + diff --git a/0031-e2fsck-avoid-out-of-bounds-write-for-very-deep-exten.patch b/0031-e2fsck-avoid-out-of-bounds-write-for-very-deep-exten.patch new file mode 100644 index 0000000..d6f33ee --- /dev/null +++ b/0031-e2fsck-avoid-out-of-bounds-write-for-very-deep-exten.patch @@ -0,0 +1,71 @@ +From 8d66e7e9316002ca9f9d558069bd56ccba9cece8 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Mon, 6 Jun 2022 22:44:35 -0400 +Subject: e2fsck: avoid out-of-bounds write for very deep extent trees +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The kernel doesn't support extent trees deeper than 5 +(EXT4_MAX_EXTENT_DEPTH). For this reason we only maintain the extent +tree statistics for 5 levels. Avoid out-of-bounds writes and reads if +the extent tree is deeper than this. + +We keep these statistics to determine whether we should rebuild the +extent tree. If the extent tree is too deep, we don't need the +statistics because we should always rebuild the it. + +Reported-by: Nils Bars +Reported-by: Moritz Schlögel +Reported-by: Nico Schiller +Signed-off-by: Theodore Ts'o +--- + e2fsck/extents.c | 10 +++++++++- + e2fsck/pass1.c | 3 ++- + 2 files changed, 11 insertions(+), 2 deletions(-) + +diff --git a/e2fsck/extents.c b/e2fsck/extents.c +index 01879f56..86fe00e7 100644 +--- a/e2fsck/extents.c ++++ b/e2fsck/extents.c +@@ -526,7 +526,8 @@ errcode_t e2fsck_check_rebuild_extents(e2fsck_t ctx, ext2_ino_t ino, + */ + if (info.curr_entry == 1 && + !(extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) && +- !eti.force_rebuild) { ++ !eti.force_rebuild && ++ info.curr_level < MAX_EXTENT_DEPTH_COUNT) { + struct extent_tree_level *etl; + + etl = eti.ext_info + info.curr_level; +@@ -580,6 +581,13 @@ errcode_t e2fsck_should_rebuild_extents(e2fsck_t ctx, + extents_per_block = (ctx->fs->blocksize - + sizeof(struct ext3_extent_header)) / + sizeof(struct ext3_extent); ++ ++ /* If the extent tree is too deep, then rebuild it. */ ++ if (info->max_depth > MAX_EXTENT_DEPTH_COUNT) { ++ pctx->blk = info->max_depth; ++ op = PR_1E_CAN_COLLAPSE_EXTENT_TREE; ++ goto rebuild; ++ } + /* + * If we can consolidate a level or shorten the tree, schedule the + * extent tree to be rebuilt. +diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c +index 11d7ce93..43972e7c 100644 +--- a/e2fsck/pass1.c ++++ b/e2fsck/pass1.c +@@ -2842,7 +2842,8 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx, + if (pctx->errcode) + return; + if (!(ctx->options & E2F_OPT_FIXES_ONLY) && +- !pb->eti.force_rebuild) { ++ !pb->eti.force_rebuild && ++ info.curr_level < MAX_EXTENT_DEPTH_COUNT) { + struct extent_tree_level *etl; + + etl = pb->eti.ext_info + info.curr_level; +-- +cgit + diff --git a/0032-e2fsck-fix-potential-fencepost-error-in-e2fsck_shoul.patch b/0032-e2fsck-fix-potential-fencepost-error-in-e2fsck_shoul.patch new file mode 100644 index 0000000..635a91c --- /dev/null +++ b/0032-e2fsck-fix-potential-fencepost-error-in-e2fsck_shoul.patch @@ -0,0 +1,55 @@ +From 7464397a0c5df0416a7ef3436747045b36fb7882 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Tue, 9 Aug 2022 10:52:57 -0400 +Subject: e2fsck: fix potential fencepost error in + e2fsck_should_rebuild_extents() + +The ext2_extent_info.max_depth is zero-based (e.g., it is zero when +the entire extent tree fits in the inode). Hence, if it is equal to +MAX_EXTENT_DEPTH_COUNT we should always rebuild the extent tree to +shorten it. + +Also, for 1k block file systems, it's possible for the worst-case +extent tree in its most compact form to have a maximum depth of 6, not +5. So set MAX_EXTENT_DEPTH_COUNT to 8 just to be sure we have plenty +of headroom. (The kernel supports an extent depth up to 2**16, but +e2fsck only keeps statistics up to MAX_EXTENT_DEPTH_COUNT, and if it's +deeper than that, we know that it will be profitable to rebuild the +extent tree in any case.) + +Addresses-Coverity-Bug: 1507761 +Signed-off-by: Theodore Ts'o +--- + e2fsck/e2fsck.h | 2 +- + e2fsck/extents.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h +index 00b20919..75baf2cd 100644 +--- a/e2fsck/e2fsck.h ++++ b/e2fsck/e2fsck.h +@@ -233,7 +233,7 @@ typedef struct ea_refcount *ext2_refcount_t; + */ + typedef struct e2fsck_struct *e2fsck_t; + +-#define MAX_EXTENT_DEPTH_COUNT 5 ++#define MAX_EXTENT_DEPTH_COUNT 8 + + /* + * This strucutre is used to manage the list of extents in a file. Placing +diff --git a/e2fsck/extents.c b/e2fsck/extents.c +index 86fe00e7..70798f34 100644 +--- a/e2fsck/extents.c ++++ b/e2fsck/extents.c +@@ -583,7 +583,7 @@ errcode_t e2fsck_should_rebuild_extents(e2fsck_t ctx, + sizeof(struct ext3_extent); + + /* If the extent tree is too deep, then rebuild it. */ +- if (info->max_depth > MAX_EXTENT_DEPTH_COUNT) { ++ if (info->max_depth > MAX_EXTENT_DEPTH_COUNT-1) { + pctx->blk = info->max_depth; + op = PR_1E_CAN_COLLAPSE_EXTENT_TREE; + goto rebuild; +-- +cgit + diff --git a/0033-libext2fs-fix-potential-integer-overflow-in-bitmap-a.patch b/0033-libext2fs-fix-potential-integer-overflow-in-bitmap-a.patch new file mode 100644 index 0000000..70f0030 --- /dev/null +++ b/0033-libext2fs-fix-potential-integer-overflow-in-bitmap-a.patch @@ -0,0 +1,53 @@ +From 27504bcf89193d47d7632cde922a65e0c051be01 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Tue, 9 Aug 2022 11:16:47 -0400 +Subject: libext2fs: fix potential integer overflow in bitmap accessors + +bmap->cluster_bits has a maximum value of 19, but Coverity doesn't +know that. To make it happy, and just in case there is a bug where +somehow the cluster size does get set to an invalid value and the rest +of the library doesn't check it, use 1ULL instead of 1 to avoid the +integer overflow. + +Addresses-Coverity-Bug: 1500759 +Addresses-Coverity-Bug: 1500764 +Addresses-Coverity-Bug: 1500771 +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/gen_bitmap64.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c +index d9809084..c860c10e 100644 +--- a/lib/ext2fs/gen_bitmap64.c ++++ b/lib/ext2fs/gen_bitmap64.c +@@ -684,7 +684,7 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, + + /* convert to clusters if necessary */ + block >>= bmap->cluster_bits; +- end += (1 << bmap->cluster_bits) - 1; ++ end += (1ULL << bmap->cluster_bits) - 1; + end >>= bmap->cluster_bits; + num = end - block; + +@@ -725,7 +725,7 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, + + /* convert to clusters if necessary */ + block >>= bmap->cluster_bits; +- end += (1 << bmap->cluster_bits) - 1; ++ end += (1ULL << bmap->cluster_bits) - 1; + end >>= bmap->cluster_bits; + num = end - block; + +@@ -766,7 +766,7 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, + + /* convert to clusters if necessary */ + block >>= bmap->cluster_bits; +- end += (1 << bmap->cluster_bits) - 1; ++ end += (1ULL << bmap->cluster_bits) - 1; + end >>= bmap->cluster_bits; + num = end - block; + +-- +cgit + diff --git a/0034-tune2fs-fix-an-error-message.patch b/0034-tune2fs-fix-an-error-message.patch new file mode 100644 index 0000000..58a5a2c --- /dev/null +++ b/0034-tune2fs-fix-an-error-message.patch @@ -0,0 +1,36 @@ +From 6695555e50a374f897965300568253f242a0b13b Mon Sep 17 00:00:00 2001 +From: Lubomir Rintel +Date: Fri, 23 Sep 2022 15:25:48 +0200 +Subject: tune2fs: fix an error message + + $ tune2fs -O ^has_journal -ff /dev/sdh2 + Recovering journal. tune2fs: Unknown code ____ 251 while recovering journal. + + Before: Please run e2fsck -fy -O. + After: Please run e2fsck -fy /dev/sdh2. + +Note this doesn't fix the "Unknown code" message, just the "Please run +e2fsck" one. + +Signed-off-by: Lubomir Rintel +Signed-off-by: Theodore Ts'o +--- + misc/tune2fs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index f566ed81..f3ce443c 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -3105,7 +3105,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + if (retval) { + com_err("tune2fs", retval, + "while recovering journal.\n"); +- printf(_("Please run e2fsck -fy %s.\n"), argv[1]); ++ printf(_("Please run e2fsck -fy %s.\n"), device_name); + if (!fs) + exit(1); + rc = 1; +-- +cgit + diff --git a/0035-e2fsck-don-t-allow-journal-inode-to-have-encrypt-fla.patch b/0035-e2fsck-don-t-allow-journal-inode-to-have-encrypt-fla.patch new file mode 100644 index 0000000..91d73f5 --- /dev/null +++ b/0035-e2fsck-don-t-allow-journal-inode-to-have-encrypt-fla.patch @@ -0,0 +1,113 @@ +From b0cd09e5b65373fc9f89048958c093bb1e6a1ecb Mon Sep 17 00:00:00 2001 +From: Eric Biggers +Date: Wed, 2 Nov 2022 15:05:51 -0700 +Subject: e2fsck: don't allow journal inode to have encrypt flag + +Since the kernel is being fixed to consider journal inodes with the +'encrypt' flag set to be invalid, also update e2fsck accordingly. + +Signed-off-by: Eric Biggers +Reviewed-by: Andreas Dilger +Signed-off-by: Theodore Ts'o +--- + e2fsck/journal.c | 3 ++- + tests/f_badjour_encrypted/expect.1 | 30 ++++++++++++++++++++++++++++++ + tests/f_badjour_encrypted/expect.2 | 7 +++++++ + tests/f_badjour_encrypted/name | 1 + + tests/f_badjour_encrypted/script | 11 +++++++++++ + 5 files changed, 51 insertions(+), 1 deletion(-) + create mode 100644 tests/f_badjour_encrypted/expect.1 + create mode 100644 tests/f_badjour_encrypted/expect.2 + create mode 100644 tests/f_badjour_encrypted/name + create mode 100644 tests/f_badjour_encrypted/script + +diff --git a/e2fsck/journal.c b/e2fsck/journal.c +index 1646b479..1bfabb02 100644 +--- a/e2fsck/journal.c ++++ b/e2fsck/journal.c +@@ -1039,7 +1039,8 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal) + tried_backup_jnl++; + } + if (!j_inode->i_ext2.i_links_count || +- !LINUX_S_ISREG(j_inode->i_ext2.i_mode)) { ++ !LINUX_S_ISREG(j_inode->i_ext2.i_mode) || ++ (j_inode->i_ext2.i_flags & EXT4_ENCRYPT_FL)) { + retval = EXT2_ET_NO_JOURNAL; + goto try_backup_journal; + } +diff --git a/tests/f_badjour_encrypted/expect.1 b/tests/f_badjour_encrypted/expect.1 +new file mode 100644 +index 00000000..0b13b9eb +--- /dev/null ++++ b/tests/f_badjour_encrypted/expect.1 +@@ -0,0 +1,30 @@ ++Superblock has an invalid journal (inode 8). ++Clear? yes ++ ++*** journal has been deleted *** ++ ++Pass 1: Checking inodes, blocks, and sizes ++Journal inode is not in use, but contains data. Clear? yes ++ ++Pass 2: Checking directory structure ++Pass 3: Checking directory connectivity ++Pass 4: Checking reference counts ++Pass 5: Checking group summary information ++Block bitmap differences: -(24--25) -(27--41) -(107--1113) ++Fix? yes ++ ++Free blocks count wrong for group #0 (934, counted=1958). ++Fix? yes ++ ++Free blocks count wrong (934, counted=1958). ++Fix? yes ++ ++Recreate journal? yes ++ ++Creating journal (1024 blocks): Done. ++ ++*** journal has been regenerated *** ++ ++test_filesys: ***** FILE SYSTEM WAS MODIFIED ***** ++test_filesys: 11/256 files (0.0% non-contiguous), 1114/2048 blocks ++Exit status is 1 +diff --git a/tests/f_badjour_encrypted/expect.2 b/tests/f_badjour_encrypted/expect.2 +new file mode 100644 +index 00000000..76934be2 +--- /dev/null ++++ b/tests/f_badjour_encrypted/expect.2 +@@ -0,0 +1,7 @@ ++Pass 1: Checking inodes, blocks, and sizes ++Pass 2: Checking directory structure ++Pass 3: Checking directory connectivity ++Pass 4: Checking reference counts ++Pass 5: Checking group summary information ++test_filesys: 11/256 files (9.1% non-contiguous), 1114/2048 blocks ++Exit status is 0 +diff --git a/tests/f_badjour_encrypted/name b/tests/f_badjour_encrypted/name +new file mode 100644 +index 00000000..e8f4c04f +--- /dev/null ++++ b/tests/f_badjour_encrypted/name +@@ -0,0 +1 @@ ++journal inode has encrypt flag +diff --git a/tests/f_badjour_encrypted/script b/tests/f_badjour_encrypted/script +new file mode 100644 +index 00000000..e6778f1d +--- /dev/null ++++ b/tests/f_badjour_encrypted/script +@@ -0,0 +1,11 @@ ++if ! test -x $DEBUGFS_EXE; then ++ echo "$test_name: $test_description: skipped (no debugfs)" ++ return 0 ++fi ++ ++touch $TMPFILE ++$MKE2FS -t ext4 -b 1024 $TMPFILE 2M ++$DEBUGFS -w -R 'set_inode_field <8> flags 0x80800' $TMPFILE ++ ++SKIP_GUNZIP="true" ++. $cmd_dir/run_e2fsck +-- +cgit + diff --git a/0036-lib-ext2fs-fix-unbalanced-mutex-unlock-for-BOUNCE_MT.patch b/0036-lib-ext2fs-fix-unbalanced-mutex-unlock-for-BOUNCE_MT.patch new file mode 100644 index 0000000..2489a77 --- /dev/null +++ b/0036-lib-ext2fs-fix-unbalanced-mutex-unlock-for-BOUNCE_MT.patch @@ -0,0 +1,31 @@ +From c640cf1f3a9a7ac6ecbf82c27539c8e158f8ea24 Mon Sep 17 00:00:00 2001 +From: "Ritesh Harjani (IBM)" +Date: Mon, 7 Nov 2022 17:50:49 +0530 +Subject: lib/ext2fs: fix unbalanced mutex unlock for BOUNCE_MTX in unix_io + +f_crashdisk test failed with UNIX_IO_FORCE_BOUNCE=yes due to unbalanced +mutex unlock in below path. + +This patch fixes it. + +Signed-off-by: Ritesh Harjani (IBM) +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/unix_io.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c +index e53db333..5b894826 100644 +--- a/lib/ext2fs/unix_io.c ++++ b/lib/ext2fs/unix_io.c +@@ -305,7 +305,6 @@ bounce_read: + while (size > 0) { + actual = read(data->dev, data->bounce, align_size); + if (actual != align_size) { +- mutex_unlock(data, BOUNCE_MTX); + actual = really_read; + buf -= really_read; + size += really_read; +-- +cgit + diff --git a/0037-libext2fs-fix-ext2fs_compare_generic_bmap-logic.patch b/0037-libext2fs-fix-ext2fs_compare_generic_bmap-logic.patch new file mode 100644 index 0000000..30d8aca --- /dev/null +++ b/0037-libext2fs-fix-ext2fs_compare_generic_bmap-logic.patch @@ -0,0 +1,41 @@ +From b795c06d8a44f42cdffdf5aa9561ff8de20d78cc Mon Sep 17 00:00:00 2001 +From: "Ritesh Harjani (IBM)" +Date: Mon, 7 Nov 2022 17:50:50 +0530 +Subject: libext2fs: fix ext2fs_compare_generic_bmap logic + +Currently this function was not correctly comparing against the right +length of the bitmap. Also when we compare bitarray v/s rbtree bitmap +the value returned by ext2fs_test_generic_bmap() could be different in +these two implementations. Hence only check against boolean value. + +Signed-off-by: Ritesh Harjani (IBM) +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/gen_bitmap64.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c +index c860c10e..f7710afd 100644 +--- a/lib/ext2fs/gen_bitmap64.c ++++ b/lib/ext2fs/gen_bitmap64.c +@@ -629,10 +629,14 @@ errcode_t ext2fs_compare_generic_bmap(errcode_t neq, + (bm1->end != bm2->end)) + return neq; + +- for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) +- if (ext2fs_test_generic_bmap(gen_bm1, i) != +- ext2fs_test_generic_bmap(gen_bm2, i)) ++ for (i = bm1->start; i < bm1->end; i++) { ++ int ret1, ret2; ++ ret1 = !!ext2fs_test_generic_bmap(gen_bm1, i); ++ ret2 = !!ext2fs_test_generic_bmap(gen_bm2, i); ++ if (ret1 != ret2) { + return neq; ++ } ++ } + + return 0; + } +-- +cgit + diff --git a/0038-Quiet-unused-variable-warnings.patch b/0038-Quiet-unused-variable-warnings.patch new file mode 100644 index 0000000..0662fb9 --- /dev/null +++ b/0038-Quiet-unused-variable-warnings.patch @@ -0,0 +1,72 @@ +From 9d8b56b3b5d59691f16a8b8ae5fb763bc6be3d15 Mon Sep 17 00:00:00 2001 +From: Andreas Dilger +Date: Thu, 4 Aug 2022 11:18:32 -0600 +Subject: Quiet unused variable warnings + +Quiet various compiler warnings about unreferenced or unset variables. + +Signed-off-by: Andreas Dilger +Signed-off-by: Theodore Ts'o +--- + e2fsck/journal.c | 15 +++++++-------- + lib/ext2fs/swapfs.c | 2 +- + 2 files changed, 8 insertions(+), 9 deletions(-) + +diff --git a/e2fsck/journal.c b/e2fsck/journal.c +index 12487e3d..571de83e 100644 +--- a/e2fsck/journal.c ++++ b/e2fsck/journal.c +@@ -620,7 +620,6 @@ static inline int tl_to_darg(struct dentry_info_args *darg, + struct ext4_fc_tl *tl, __u8 *val) + { + struct ext4_fc_dentry_info fcd; +- int tag = le16_to_cpu(tl->fc_tag); + + memcpy(&fcd, val, sizeof(fcd)); + +@@ -636,10 +635,10 @@ static inline int tl_to_darg(struct dentry_info_args *darg, + darg->dname_len); + darg->dname[darg->dname_len] = 0; + jbd_debug(1, "%s: %s, ino %lu, parent %lu\n", +- tag == EXT4_FC_TAG_CREAT ? "create" : +- (tag == EXT4_FC_TAG_LINK ? "link" : +- (tag == EXT4_FC_TAG_UNLINK ? "unlink" : "error")), +- darg->dname, darg->ino, darg->parent_ino); ++ le16_to_cpu(tl->fc_tag) == EXT4_FC_TAG_CREAT ? "create" : ++ (le16_to_cpu(tl->fc_tag) == EXT4_FC_TAG_LINK ? "link" : ++ (le16_to_cpu(tl->fc_tag) == EXT4_FC_TAG_UNLINK ? "unlink" : ++ "error")), darg->dname, darg->ino, darg->parent_ino); + return 0; + } + +@@ -652,11 +651,11 @@ static int ext4_fc_handle_unlink(e2fsck_t ctx, struct ext4_fc_tl *tl, __u8 *val) + if (ret) + return ret; + ext4_fc_flush_extents(ctx, darg.ino); +- ret = errcode_to_errno( +- ext2fs_unlink(ctx->fs, darg.parent_ino, +- darg.dname, darg.ino, 0)); ++ ret = errcode_to_errno(ext2fs_unlink(ctx->fs, darg.parent_ino, ++ darg.dname, darg.ino, 0)); + /* It's okay if the above call fails */ + free(darg.dname); ++ + return ret; + } + +diff --git a/lib/ext2fs/swapfs.c b/lib/ext2fs/swapfs.c +index 1006b2d2..cd160b31 100644 +--- a/lib/ext2fs/swapfs.c ++++ b/lib/ext2fs/swapfs.c +@@ -244,7 +244,7 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, + int bufsize) + { + unsigned i, extra_isize, attr_magic; +- int has_extents, has_inline_data, islnk, fast_symlink; ++ int has_extents = 0, has_inline_data = 0, islnk = 0, fast_symlink = 0; + unsigned int inode_size; + __u32 *eaf, *eat; + +-- +cgit + diff --git a/0039-ext2fs-Use-64bit-lseek-when-_FILE_OFFSET_BITS-is-64.patch b/0039-ext2fs-Use-64bit-lseek-when-_FILE_OFFSET_BITS-is-64.patch new file mode 100644 index 0000000..1478639 --- /dev/null +++ b/0039-ext2fs-Use-64bit-lseek-when-_FILE_OFFSET_BITS-is-64.patch @@ -0,0 +1,40 @@ +From 674d844c52cba11a5a80cb864161b97f1529fe5c Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Wed, 14 Dec 2022 20:56:44 -0800 +Subject: ext2fs: Use 64bit lseek when _FILE_OFFSET_BITS is 64 + +Use lseek() with 64bit off_t when _FILE_OFFSET_BITS is 64 +this fixes build with musl where there is no _llseek but lseek +is using off_t which is 64bit on musl + +Signed-off-by: Khem Raj +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/llseek.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c +index 922a0d56..45f21d09 100644 +--- a/lib/ext2fs/llseek.c ++++ b/lib/ext2fs/llseek.c +@@ -51,7 +51,7 @@ extern long long llseek (int fd, long long offset, int origin); + + #else /* ! HAVE_LLSEEK */ + +-#if SIZEOF_LONG == SIZEOF_LONG_LONG ++#if SIZEOF_LONG == SIZEOF_LONG_LONG || _FILE_OFFSET_BITS+0 == 64 + + #define my_llseek lseek + +@@ -69,7 +69,7 @@ static int _llseek (unsigned int, unsigned long, + + static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high, + unsigned long, offset_low,ext2_loff_t *,result, +- unsigned int, origin) ++ unsigned int, origin); + #endif + + static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin) +-- +cgit + diff --git a/e2fsprogs.spec b/e2fsprogs.spec index b354d5e..14e3d8d 100644 --- a/e2fsprogs.spec +++ b/e2fsprogs.spec @@ -1,6 +1,6 @@ Name: e2fsprogs Version: 1.46.4 -Release: 20 +Release: 21 Summary: Second extended file system management tools License: GPLv2+ and LGPLv2 and MIT URL: http://e2fsprogs.sourceforge.net/ @@ -33,6 +33,19 @@ Patch23: 0023-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch Patch24: 0024-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch Patch25: 0025-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch Patch26: 0026-misc-fsck.c-Processes-may-kill-other-processes.patch +Patch27: 0027-dumpe2fs-resize2fs-avoid-memory-leak-on-error-path.patch +Patch28: 0028-libext2fs-fix-memory-leak-in-error-path-while-openin.patch +Patch29: 0029-e2fsck-avoid-theoretical-null-dereference-in-end_pro.patch +Patch30: 0030-e2fsck-fix-potential-out-of-bounds-read-in-inc_ea_in.patch +Patch31: 0031-e2fsck-avoid-out-of-bounds-write-for-very-deep-exten.patch +Patch32: 0032-e2fsck-fix-potential-fencepost-error-in-e2fsck_shoul.patch +Patch33: 0033-libext2fs-fix-potential-integer-overflow-in-bitmap-a.patch +Patch34: 0034-tune2fs-fix-an-error-message.patch +Patch35: 0035-e2fsck-don-t-allow-journal-inode-to-have-encrypt-fla.patch +Patch36: 0036-lib-ext2fs-fix-unbalanced-mutex-unlock-for-BOUNCE_MT.patch +Patch37: 0037-libext2fs-fix-ext2fs_compare_generic_bmap-logic.patch +Patch38: 0038-Quiet-unused-variable-warnings.patch +Patch39: 0039-ext2fs-Use-64bit-lseek-when-_FILE_OFFSET_BITS-is-64.patch BuildRequires: gcc pkgconfig texinfo @@ -174,6 +187,9 @@ exit 0 %{_mandir}/man8/* %changelog +* Sun Jun 25 2023 suweifeng - 1.46.4-21 +- backport patches from upstream + * Fri Jun 9 2023 tangyuchen - 1.46.4-20 - delete invalid link for ext4 -- Gitee