diff --git a/backport-fix-last-bg-is-free-clusters-calculation-on-64-bit-file-systems.patch b/backport-fix-last-bg-is-free-clusters-calculation-on-64-bit-file-systems.patch new file mode 100644 index 0000000000000000000000000000000000000000..cc7c333ca1c447bf0d3f443f02bf6fb100154943 --- /dev/null +++ b/backport-fix-last-bg-is-free-clusters-calculation-on-64-bit-file-systems.patch @@ -0,0 +1,27 @@ +From 1da249a125cb2ae138a6dd1d262754e2b4d45175 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Sun, 28 Apr 2024 23:26:19 -0400 +Subject: [PATCH] resize2fs: fix last bg's free clusters calculation on 64-bit + file systems + +Fixes-Coverity-bug: 1596645 +Fixes: d43fb24ca0db ("resize2fs: fix r_bigalloc_big_expand test failure") +Signed-off-by: Theodore Ts'o +--- + resize/resize2fs.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/resize/resize2fs.c b/resize/resize2fs.c +index 4daa068b8..f4a409805 100644 +--- a/resize/resize2fs.c ++++ b/resize/resize2fs.c +@@ -2870,7 +2870,8 @@ static errcode_t resize2fs_calculate_summary_stats(ext2_filsys fs) + if ((group == fs->group_desc_count - 1) && (max & 7)) { + n = 0; + for (b = (fs->super->s_first_data_block + +- (fs->super->s_blocks_per_group * group)); ++ ((blk64_t) fs->super->s_blocks_per_group * ++ group)); + b < ext2fs_blocks_count(fs->super); + b += EXT2FS_CLUSTER_RATIO(fs)) { + if (ext2fs_test_block_bitmap2(fs->block_map, b)) diff --git a/backport-fix-r_bigalloc_big_expand-test-failure.patch b/backport-fix-r_bigalloc_big_expand-test-failure.patch new file mode 100644 index 0000000000000000000000000000000000000000..8d559b1b1d10698484164a7b637d5b6334fb11ff --- /dev/null +++ b/backport-fix-r_bigalloc_big_expand-test-failure.patch @@ -0,0 +1,82 @@ +From d43fb24ca0db24cdb3d53d0cc0bf8c211f416b78 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Sat, 27 Apr 2024 21:04:33 -0400 +Subject: [PATCH] resize2fs: fix r_bigalloc_big_expand test failure + +Manually count the number free clusters in the last block group since +it might not be a multiple of 8, and using ext2fs_bitcount() might not +work if bitmap isn't properly padding out. + +In addition, when setting up the block bitmap for the resized file +system, resize2fs was setting up the "real end" of the bitmap in units +of blocks instead of clusters. + +We didn't notice this problem earlier because of a test failure which +caused the test to be skipped. + +Signed-off-by: Theodore Ts'o +--- + resize/resize2fs.c | 29 ++++++++++++++++++++--------- + 1 file changed, 20 insertions(+), 9 deletions(-) + +diff --git a/resize/resize2fs.c b/resize/resize2fs.c +index 46540501d..4daa068b8 100644 +--- a/resize/resize2fs.c ++++ b/resize/resize2fs.c +@@ -803,8 +803,8 @@ errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, + fs->inode_map); + if (retval) goto errout; + +- real_end = EXT2_GROUPS_TO_BLOCKS(fs->super, fs->group_desc_count) - 1 + +- fs->super->s_first_data_block; ++ real_end = EXT2_GROUPS_TO_CLUSTERS(fs->super, fs->group_desc_count) - ++ 1 + EXT2FS_B2C(fs, fs->super->s_first_data_block); + retval = ext2fs_resize_block_bitmap2(new_size - 1, + real_end, fs->block_map); + if (retval) goto errout; +@@ -2843,9 +2843,9 @@ static errcode_t fix_resize_inode(ext2_filsys fs) + static errcode_t resize2fs_calculate_summary_stats(ext2_filsys fs) + { + errcode_t retval; +- blk64_t blk = fs->super->s_first_data_block; ++ blk64_t b, blk = fs->super->s_first_data_block; + ext2_ino_t ino; +- unsigned int n, group, count; ++ unsigned int n, max, group, count; + blk64_t total_clusters_free = 0; + int total_inodes_free = 0; + int group_free = 0; +@@ -2858,17 +2858,28 @@ static errcode_t resize2fs_calculate_summary_stats(ext2_filsys fs) + bitmap_buf = malloc(fs->blocksize); + if (!bitmap_buf) + return ENOMEM; +- for (group = 0; group < fs->group_desc_count; +- group++) { ++ for (group = 0; group < fs->group_desc_count; group++) { + retval = ext2fs_get_block_bitmap_range2(fs->block_map, + B2C(blk), fs->super->s_clusters_per_group, bitmap_buf); + if (retval) { + free(bitmap_buf); + return retval; + } +- n = ext2fs_bitcount(bitmap_buf, +- fs->super->s_clusters_per_group / 8); +- group_free = fs->super->s_clusters_per_group - n; ++ max = ext2fs_group_blocks_count(fs, group) >> ++ fs->cluster_ratio_bits; ++ if ((group == fs->group_desc_count - 1) && (max & 7)) { ++ n = 0; ++ for (b = (fs->super->s_first_data_block + ++ (fs->super->s_blocks_per_group * group)); ++ b < ext2fs_blocks_count(fs->super); ++ b += EXT2FS_CLUSTER_RATIO(fs)) { ++ if (ext2fs_test_block_bitmap2(fs->block_map, b)) ++ n++; ++ } ++ } else { ++ n = ext2fs_bitcount(bitmap_buf, (max + 7) / 8); ++ } ++ group_free = max - n; + total_clusters_free += group_free; + ext2fs_bg_free_blocks_count_set(fs, group, group_free); + ext2fs_group_desc_csum_set(fs, group); diff --git a/backport-handle-short-reads-writes-while-creating-the-qcow-file.patch b/backport-handle-short-reads-writes-while-creating-the-qcow-file.patch new file mode 100644 index 0000000000000000000000000000000000000000..e56cea84a78607e2aa918209d0d21f5d032b6206 --- /dev/null +++ b/backport-handle-short-reads-writes-while-creating-the-qcow-file.patch @@ -0,0 +1,66 @@ +From 8cfc832cf6771c950c9220b6fe8c9df82f577c52 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Thu, 25 Apr 2024 17:52:05 -0400 +Subject: [PATCH] libextr2fs: handle short reads/writes while creating the qcow + file + +This issue was flagged by Coverity, although its analysis was +incorrect. This isn't actually a memory overrun / security issue, but +rather a functional correctness issue since POSIX allows reads and +writes to be partially completed, and in those cases qcow2_copy_data() +could result in a corrutped qcow2 file. + +Addresses-Coverity-Bug: 1531830 +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/qcow2.c | 30 +++++++++++++++++++++--------- + 1 file changed, 21 insertions(+), 9 deletions(-) + +diff --git a/lib/ext2fs/qcow2.c b/lib/ext2fs/qcow2.c +index 208241707..8f96eeed7 100644 +--- a/lib/ext2fs/qcow2.c ++++ b/lib/ext2fs/qcow2.c +@@ -134,7 +134,9 @@ static int qcow2_read_l2_table(struct ext2_qcow2_image *img, + static int qcow2_copy_data(int fdin, int fdout, __u64 off_in, + __u64 off_out, void *buf, size_t count) + { +- size_t size; ++ ssize_t c1, c2, c; ++ void *ptr; ++ int retries = 10; + + assert(buf); + +@@ -144,14 +146,24 @@ static int qcow2_copy_data(int fdin, int fdout, __u64 off_in, + if (ext2fs_llseek(fdin, off_in, SEEK_SET) < 0) + return errno; + +- size = read(fdin, buf, count); +- if (size != count) +- return errno; +- +- size = write(fdout, buf, count); +- if (size != count) +- return errno; +- ++ while (count > 0) { ++ errno = 0; ++ c1 = read(fdin, buf, count); ++ if (c1 < 0 || ((c1 == 0) && errno)) ++ return errno; ++ if (c1 == 0) ++ break; /* EOF */ ++ ++ for (ptr = buf, c = c1; c > 0; ptr += c2, c -= c2) { ++ errno = 0; ++ c2 = write(fdout, ptr, c1); ++ if (c2 < 0 || ((c2 == 0) && errno)) ++ return errno; ++ if (c2 == 0 && --retries <= 0) ++ break; /* This should never happen... */ ++ } ++ count -= c1; ++ } + return 0; + } + diff --git a/backport-minor-man-page-fixes.patch b/backport-minor-man-page-fixes.patch new file mode 100644 index 0000000000000000000000000000000000000000..13066a08046129d7174cc73079b8948152a6d6f8 --- /dev/null +++ b/backport-minor-man-page-fixes.patch @@ -0,0 +1,277 @@ +From 18d47788c45c5361b93bcd0eb4c84c394a06d06a Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Fri, 26 Apr 2024 00:36:31 -0400 +Subject: [PATCH] e2fsck.8: minor man page fixes + +Addresses-Debian-Bug: #1038286 +Signed-off-by: Theodore Ts'o +--- + e2fsck/e2fsck.8.in | 112 ++++++++++++++++++++++++--------------------- + 1 file changed, 61 insertions(+), 51 deletions(-) + +diff --git a/e2fsck/e2fsck.8.in b/e2fsck/e2fsck.8.in +index dc6a5856a..ea0f51488 100644 +--- a/e2fsck/e2fsck.8.in ++++ b/e2fsck/e2fsck.8.in +@@ -44,8 +44,9 @@ e2fsck \- check a Linux ext2/ext3/ext4 file system + is used to check the ext2/ext3/ext4 family of file systems. + For ext3 and ext4 file systems that use a journal, if the system has been + shut down uncleanly without any errors, normally, after replaying the +-committed transactions in the journal, the file system should be +-marked as clean. Hence, for file systems that use journaling, ++committed transactions in the journal, the file system should be ++marked as clean. ++Hence, for file systems that use journaling, + .B e2fsck + will normally replay the journal and exit, unless its superblock + indicates that further checking is required. +@@ -63,12 +64,14 @@ option is specified, and + .BR \-c , + .BR \-l , + or +-.B -L ++.B \-L + options are + .I not +-specified. However, even if it is safe to do so, the results printed by ++specified. ++However, even if it is safe to do so, the results printed by + .B e2fsck +-are not valid if the file system is mounted. If ++are not valid if the file system is mounted. ++If + .B e2fsck + asks whether or not you should check a file system which is mounted, + the only correct answer is ``no''. Only experts who really know what +@@ -80,10 +83,10 @@ is run in interactive mode (meaning that none of + .BR \-y , + .BR \-n , + or +-.BR \-p ++.B \-p + are specified), the program will ask the user to fix each problem found in the +-file system. A response of 'y' will fix the error; 'n' will leave the error +-unfixed; and 'a' will fix the problem and all subsequent problems; pressing ++file system. A response of \&'y' will fix the error; \&'n' will leave the error ++unfixed; and \&'a' will fix the problem and all subsequent problems; pressing + Enter will proceed with the default response, which is printed before the + question mark. Pressing Control-C terminates e2fsck immediately. + .SH OPTIONS +@@ -113,7 +116,7 @@ program using the + option to print out where the superblocks exist, supposing + .B mke2fs + is supplied with arguments that are consistent with the file system's layout +-(e.g. blocksize, blocks per group, ++(e.g.\& blocksize, blocks per group, + .BR sparse_super , + etc.). + .IP +@@ -170,7 +173,7 @@ Print debugging output (useless unless you are debugging + .B \-D + Optimize directories in file system. This option causes e2fsck to + try to optimize all directories, either by re-indexing them if the +-file system supports directory indexing, or by sorting and compressing ++file system supports directory indexing, or by sorting and compressing + directories for smaller directories, or for file systems using + traditional linear directories. + .IP +@@ -204,86 +207,92 @@ Set the version of the extended attribute blocks which + will require while checking the file system. The version number may + be 1 or 2. The default extended attribute version format is 2. + .TP +-.BI journal_only ++.B journal_only + Only replay the journal if required, but do not perform any further checks + or repairs. + .TP +-.BI fragcheck ++.B fragcheck + During pass 1, print a detailed report of any discontiguous blocks for + files in the file system. + .TP +-.BI discard ++.B discard + Attempt to discard free blocks and unused inode blocks after the full + file system check (discarding blocks is useful on solid state devices and sparse +-/ thin-provisioned storage). Note that discard is done in pass 5 AFTER the ++/ thin-provisioned storage). ++Note that discard is done in pass 5 AFTER the + file system has been fully checked and only if it does not contain recognizable +-errors. However there might be cases where ++errors. ++However there might be cases where + .B e2fsck + does not fully recognize a problem and hence in this case this + option may prevent you from further manual data recovery. + .TP +-.BI nodiscard +-Do not attempt to discard free blocks and unused inode blocks. This option is +-exactly the opposite of discard option. This is set as default. ++.B nodiscard ++Do not attempt to discard free blocks and unused inode blocks. ++This option is exactly the opposite of discard option. ++This is set as default. + .TP +-.BI no_optimize_extents ++.B no_optimize_extents + Do not offer to optimize the extent tree by eliminating unnecessary + width or depth. This can also be enabled in the options section of + .BR /etc/e2fsck.conf . + .TP +-.BI optimize_extents ++.B optimize_extents + Offer to optimize the extent tree by eliminating unnecessary + width or depth. This is the default unless otherwise specified in + .BR /etc/e2fsck.conf . + .TP +-.BI inode_count_fullmap ++.B inode_count_fullmap + Trade off using memory for speed when checking a file system with a + large number of hard-linked files. The amount of memory required is + proportional to the number of inodes in the file system. For large file +-systems, this can be gigabytes of memory. (For example, a 40TB file system ++systems, this can be gigabytes of memory. (For example, a 40\ TB file system + with 2.8 billion inodes will consume an additional 5.7 GB memory if this + optimization is enabled.) This optimization can also be enabled in the + options section of + .BR /etc/e2fsck.conf . + .TP +-.BI no_inode_count_fullmap ++.B no_inode_count_fullmap + Disable the + .B inode_count_fullmap + optimization. This is the default unless otherwise specified in + .BR /etc/e2fsck.conf . + .TP +-.BI readahead_kb ++.B readahead_kb + Use this many KiB of memory to pre-fetch metadata in the hopes of reducing + e2fsck runtime. By default, this is set to the size of two block groups' inode +-tables (typically 4MiB on a regular ext4 file system); if this amount is more ++tables (typically 4\ MiB on a regular ext4 file system); if this amount is more + than 1/50th of total physical memory, readahead is disabled. Set this to zero + to disable readahead entirely. + .TP +-.BI bmap2extent ++.B bmap2extent + Convert block-mapped files to extent-mapped files. + .TP +-.BI fixes_only ++.B fixes_only + Only fix damaged metadata; do not optimize htree directories or compress +-extent trees. This option is incompatible with the -D and -E bmap2extent ++extent trees. This option is incompatible with the \-D and \-E bmap2extent + options. + .TP +-.BI check_encoding ++.B check_encoding + Force verification of encoded filenames in case-insensitive directories. + This is the default mode if the file system has the strict flag enabled. + .TP +-.BI unshare_blocks ++.B unshare_blocks + If the file system has shared blocks, with the shared blocks read-only feature + enabled, then this will unshare all shared blocks and unset the read-only +-feature bit. If there is not enough free space then the operation will fail. ++feature bit. ++If there is not enough free space then the operation will fail. + If the file system does not have the read-only feature bit, but has shared +-blocks anyway, then this option will have no effect. Note when using this ++blocks anyway, then this option will have no effect. ++Note when using this + option, if there is no free space to clone blocks, there is no prompt to + delete files and instead the operation will fail. + .IP +-Note that unshare_blocks implies the "-f" option to ensure that all passes +-are run. Additionally, if "-n" is also specified, e2fsck will simulate trying +-to allocate enough space to deduplicate. If this fails, the exit code will +-be non-zero. ++Note that unshare_blocks implies the "\-f" option to ensure that all passes ++are run. ++Additionally, if "\-n" is also specified, e2fsck will simulate trying ++to allocate enough space to deduplicate. ++If this fails, the exit code will be non-zero. + .RE + .TP + .B \-f +@@ -299,7 +308,7 @@ time trials. + @JDEV@Set the pathname where the external-journal for this file system can be + @JDEV@found. + .TP +-.BI \-k ++.B \-k + When combined with the + .B \-c + option, any existing bad blocks in the bad blocks list are preserved, +@@ -318,7 +327,7 @@ of the file system. Hence, + .BR badblocks (8) + must be given the blocksize of the file system in order to obtain correct + results. As a result, it is much simpler and safer to use the +-.B -c ++.B \-c + option to + .BR e2fsck , + since it will assure that the correct parameters are passed to the +@@ -391,7 +400,9 @@ options. + .TP + .BI \-z " undo_file" + Before overwriting a file system block, write the old contents of the block to +-an undo file. This undo file can be used with e2undo(8) to restore the old ++an undo file. This undo file can be used with ++.BR e2undo (8) ++to restore the old + contents of the file system should something go wrong. If the empty string is + passed as the undo_file argument, the undo file will be written to a file named + e2fsck-\fIdevice\fR.e2undo in the directory specified via the +@@ -403,24 +414,23 @@ The exit code returned by + .B e2fsck + is the sum of the following conditions: + .br +-\ 0\ \-\ No errors +-.br +-\ 1\ \-\ File system errors corrected ++ 0 \-\ No errors + .br +-\ 2\ \-\ File system errors corrected, system should ++ 1 \-\ File system errors corrected + .br +-\ \ \ \ be rebooted ++ 2 \-\ File system errors corrected, system should + .br +-\ 4\ \-\ File system errors left uncorrected ++ \ \ be rebooted + .br +-\ 8\ \-\ Operational error ++ 4 \-\ File system errors left uncorrected + .br +-\ 16\ \-\ Usage or syntax error ++ 8 \-\ Operational error + .br +-\ 32\ \-\ E2fsck canceled by user request ++ 16 \-\ Usage or syntax error + .br +-\ 128\ \-\ Shared library error ++ 32 \-\ E2fsck canceled by user request + .br ++ 128 \-\ Shared library error + .SH SIGNALS + The following signals have the following effect when sent to + .BR e2fsck . +@@ -454,7 +464,7 @@ the messages printed by + are in English; if your system has been + configured so that + .BR e2fsck 's +-messages have been translated into another language, please set the the ++messages have been translated into another language, please set the + .B LC_ALL + environment variable to + .B C +@@ -492,7 +502,7 @@ Always include the full version string which + displays when it is run, so I know which version you are running. + .SH ENVIRONMENT + .TP +-.BI E2FSCK_CONFIG ++.B E2FSCK_CONFIG + Determines the location of the configuration file (see + .BR e2fsck.conf (5)). + .SH AUTHOR diff --git a/e2fsprogs.spec b/e2fsprogs.spec index b69bc524f927369d42284bd97eebdbfa18f7677e..59d65e47d2fba6acac493f3b7cb70e613d1404e0 100644 --- a/e2fsprogs.spec +++ b/e2fsprogs.spec @@ -1,6 +1,6 @@ Name: e2fsprogs Version: 1.47.0 -Release: 7 +Release: 8 Summary: Second extended file system management tools License: GPLv2+ and LGPLv2 and MIT URL: http://e2fsprogs.sourceforge.net/ @@ -24,6 +24,11 @@ Patch14: 0014-e2fsck-update-quota-accounting-after-directory-optim.patch Patch15: 0015-e2fsck-update-quota-when-deallocating-a-bad-inode.patch Patch16: 0016-fsck-fix-memory-leak-on-an-error-exit.patch +Patch17: backport-handle-short-reads-writes-while-creating-the-qcow-file.patch +Patch18: backport-minor-man-page-fixes.patch +Patch19: backport-fix-r_bigalloc_big_expand-test-failure.patch +Patch20: backport-fix-last-bg-is-free-clusters-calculation-on-64-bit-file-systems.patch + BuildRequires: gcc pkgconfig texinfo BuildRequires: fuse-devel libblkid-devel libuuid-devel BuildRequires: audit @@ -163,6 +168,13 @@ exit 0 %{_mandir}/man8/* %changelog +* Thu Aug 1 2024 zhangxingrong - 1.47.0-8 +- sync patchs from community + libextr2fs: handle short reads/writes while creating the qcow file + e2fsck.8: minor man page fixes + resize2fs: fix r_bigalloc_big_expand test failure + resize2fs: fix last bg's free clusters calculation on 64-bit file systems + * Tue Jul 2 2024 cenhuilin - 1.47.0-7 - fsck: fix memory leak on an error exit