backport patches from mailline
(cherry picked from commit f54403d3ad38439015d9f524cd0b22177cdd6a8a)
This commit is contained in:
parent
46336b8de1
commit
f34a9635c9
@ -0,0 +1,72 @@
|
||||
From 9058e09ee8d1543a185acdf0af4f72cb4d1b2aa7 Mon Sep 17 00:00:00 2001
|
||||
From: Ye Bin <yebin10@huawei.com>
|
||||
Date: Sat, 20 Apr 2024 16:10:16 +0800
|
||||
Subject: [PATCH] e2fsck: fix acl block leak when process orphan list
|
||||
|
||||
There's a issue:
|
||||
[]$~/e2fsprogs/e2fsck/e2fsck -f scsi-disk2.img
|
||||
e2fsck 1.47.0 (5-Feb-2023)
|
||||
scsi-disk2.img: recovering journal
|
||||
Clearing orphaned inode 12 (uid=0, gid=0, mode=0140777, size=0)
|
||||
Pass 1: Checking inodes, blocks, and sizes
|
||||
Extended attribute block 4247 has reference count 3, should be 2. Fix<y>? no
|
||||
Pass 2: Checking directory structure
|
||||
Pass 3: Checking directory connectivity
|
||||
Pass 4: Checking reference counts
|
||||
Pass 5: Checking group summary information
|
||||
Free blocks count wrong (249189, counted=249188).
|
||||
Fix<y>? no
|
||||
Free inodes count wrong (65526, counted=65523).
|
||||
Fix<y>? no
|
||||
|
||||
scsi-disk2.img: ***** FILE SYSTEM WAS MODIFIED *****
|
||||
|
||||
scsi-disk2.img: ********** WARNING: Filesystem still has errors **********
|
||||
|
||||
scsi-disk2.img: 10/65536 files (0.0% non-contiguous), 12955/262144 blocks
|
||||
|
||||
Above issue can reproduce as follows:
|
||||
step1: socat UNIX-LISTEN:/home/test/mysocket.sock,mode=777,reuseaddr,fork EXEC:/home/test &
|
||||
step2: setfacl some xattr for mysocket.sock
|
||||
step3: cp -a /home/test/mysocket.sock /home/test/sock1
|
||||
cp -a /home/test/mysocket.sock /home/test/sock2
|
||||
step4: sync
|
||||
step5: Power-off
|
||||
step6: run e2fsck
|
||||
|
||||
As after commit 42475e281d22 add ext2fs_inode_has_valid_blocks() judgement in
|
||||
release_inode_blocks() which means socket type file skip realse block include
|
||||
ACL block. The kernel does not restrict the setting of extended attributes for
|
||||
socket files. So this will lead to ACL block leak.
|
||||
To solve above issue there's need to release ACL block for other kind of
|
||||
special file.
|
||||
|
||||
Fixes: 42475e281d22 ("super.c (release_inode_blocks): Don't try to release the blocks if the orphaned inode is a device file, symlink, or some other kind of special file that doesn't have a block list.")
|
||||
Signed-off-by: Ye Bin <yebin10@huawei.com>
|
||||
---
|
||||
e2fsck/super.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/e2fsck/super.c b/e2fsck/super.c
|
||||
index ec28426..79460d9 100644
|
||||
--- a/e2fsck/super.c
|
||||
+++ b/e2fsck/super.c
|
||||
@@ -196,7 +196,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
|
||||
__u32 count;
|
||||
|
||||
if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(inode)))
|
||||
- return 0;
|
||||
+ goto release_acl;
|
||||
|
||||
pb.buf = block_buf + 3 * ctx->fs->blocksize;
|
||||
pb.ctx = ctx;
|
||||
@@ -240,6 +240,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
|
||||
if (inode->i_links_count)
|
||||
return 0;
|
||||
|
||||
+release_acl:
|
||||
blk = ext2fs_file_acl_block(fs, EXT2_INODE(inode));
|
||||
if (blk) {
|
||||
retval = ext2fs_adjust_ea_refcount3(fs, blk, block_buf, -1,
|
||||
--
|
||||
2.33.0
|
||||
@ -0,0 +1,35 @@
|
||||
From 1bd16e790308f92e89a5dfbd40ab9e164fe88aa9 Mon Sep 17 00:00:00 2001
|
||||
From: Theodore Ts'o <tytso@mit.edu>
|
||||
Date: Thu, 11 Aug 2022 22:16:41 -0400
|
||||
Subject: [PATCH] e2fsck: when mutating file name make sure its length never
|
||||
exceeds 255
|
||||
|
||||
E2fsck will attempt to mutate filenames to ensure uniqueness if
|
||||
necessary. If there are two unique filenames that are 254 or 255
|
||||
characters in length and do not contain the '~' character, the
|
||||
mutate_name() function would create a filename which is 256 bytes
|
||||
long, which is not a legal filename in Linux. Adjust the mutate_name
|
||||
function to avoid this possibility.
|
||||
|
||||
Addresses-Coverity-Bug: 1500768
|
||||
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
||||
---
|
||||
e2fsck/rehash.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
|
||||
index 8cc36f24..210cfdf2 100644
|
||||
--- a/e2fsck/rehash.c
|
||||
+++ b/e2fsck/rehash.c
|
||||
@@ -414,6 +414,8 @@ static void mutate_name(char *str, unsigned int *len)
|
||||
l += 2;
|
||||
else
|
||||
l = (l+3) & ~3;
|
||||
+ if (l > 255)
|
||||
+ l = 255;
|
||||
str[l-2] = '~';
|
||||
str[l-1] = '0';
|
||||
*len = l;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
126
0048-reisze2fs-sanity-check-free-block-group-counts-when-.patch
Normal file
126
0048-reisze2fs-sanity-check-free-block-group-counts-when-.patch
Normal file
@ -0,0 +1,126 @@
|
||||
From 265f88904e8d47658852e8d41447e727d799cea8 Mon Sep 17 00:00:00 2001
|
||||
From: Theodore Ts'o <tytso@mit.edu>
|
||||
Date: Tue, 28 Dec 2021 12:33:15 -0500
|
||||
Subject: [PATCH] reisze2fs: sanity check free block group counts when
|
||||
calculating minimum size
|
||||
|
||||
If one or more block group descriptor's free blocks count is insane,
|
||||
it's possible this can lead to a infinite loop in the function
|
||||
calculate_minimum_resize_size(), which is called by resize2fs -P or
|
||||
resize2fs -M.
|
||||
|
||||
Add some sanity checks to avoid this. In the case where the file
|
||||
system is corrupt, this will result in resize2fs -P reporting an
|
||||
incorrect value, but that's OK, since when we try to do an actual
|
||||
resize operation, resize2fs requires that the file system be freshly
|
||||
checked using e2fsck.
|
||||
|
||||
https://github.com/tytso/e2fsprogs/issues/94
|
||||
|
||||
Fixes: ac94445fc01f ("resize2fs: make minimum size estimates more reliable for mounted fs")
|
||||
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
||||
---
|
||||
resize/resize2fs.c | 13 +++++++++--
|
||||
tests/r_corrupt_fs/expect | 4 ++++
|
||||
tests/r_corrupt_fs/name | 1 +
|
||||
tests/r_corrupt_fs/script | 45 +++++++++++++++++++++++++++++++++++++++
|
||||
4 files changed, 61 insertions(+), 2 deletions(-)
|
||||
create mode 100644 tests/r_corrupt_fs/expect
|
||||
create mode 100644 tests/r_corrupt_fs/name
|
||||
create mode 100644 tests/r_corrupt_fs/script
|
||||
|
||||
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
|
||||
index 73174be0..b9783e8c 100644
|
||||
--- a/resize/resize2fs.c
|
||||
+++ b/resize/resize2fs.c
|
||||
@@ -3002,8 +3002,17 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags)
|
||||
/* calculate how many blocks are needed for data */
|
||||
data_needed = ext2fs_blocks_count(fs->super);
|
||||
for (grp = 0; grp < fs->group_desc_count; grp++) {
|
||||
- data_needed -= calc_group_overhead(fs, grp, old_desc_blocks);
|
||||
- data_needed -= ext2fs_bg_free_blocks_count(fs, grp);
|
||||
+ __u32 n = ext2fs_bg_free_blocks_count(fs, grp);
|
||||
+
|
||||
+ if (n > EXT2_BLOCKS_PER_GROUP(fs->super))
|
||||
+ n = EXT2_BLOCKS_PER_GROUP(fs->super);
|
||||
+ n += calc_group_overhead(fs, grp, old_desc_blocks);
|
||||
+ if (data_needed < n) {
|
||||
+ if (flags & RESIZE_DEBUG_MIN_CALC)
|
||||
+ printf("file system appears inconsistent?!?\n");
|
||||
+ return ext2fs_blocks_count(fs->super);
|
||||
+ }
|
||||
+ data_needed -= n;
|
||||
}
|
||||
#ifdef RESIZE2FS_DEBUG
|
||||
if (flags & RESIZE_DEBUG_MIN_CALC)
|
||||
diff --git a/tests/r_corrupt_fs/expect b/tests/r_corrupt_fs/expect
|
||||
new file mode 100644
|
||||
index 00000000..fe0f2bc4
|
||||
--- /dev/null
|
||||
+++ b/tests/r_corrupt_fs/expect
|
||||
@@ -0,0 +1,4 @@
|
||||
+mke2fs -q -F -t ext4 -o Linux -b 1024 test.img 32M
|
||||
+debugfs -w -R "set_bg 1 free_blocks_count 65536" /tmp/foo.img
|
||||
+resize2fs -P /tmp/foo.img
|
||||
+Estimated minimum size of the filesystem: 6604
|
||||
diff --git a/tests/r_corrupt_fs/name b/tests/r_corrupt_fs/name
|
||||
new file mode 100644
|
||||
index 00000000..ed627419
|
||||
--- /dev/null
|
||||
+++ b/tests/r_corrupt_fs/name
|
||||
@@ -0,0 +1 @@
|
||||
+resize2fs -P of a corrupted file system
|
||||
diff --git a/tests/r_corrupt_fs/script b/tests/r_corrupt_fs/script
|
||||
new file mode 100644
|
||||
index 00000000..08af91ed
|
||||
--- /dev/null
|
||||
+++ b/tests/r_corrupt_fs/script
|
||||
@@ -0,0 +1,45 @@
|
||||
+if ! test -x $RESIZE2FS_EXE -o ! -x $DEBUGFS_EXE; then
|
||||
+ echo "$test_name: $test_description: skipped (no debugfs/resize2fs)"
|
||||
+ return 0
|
||||
+fi
|
||||
+
|
||||
+OUT=$test_name.log
|
||||
+if [ -f $test_dir/expect.gz ]; then
|
||||
+ EXP=$test_name.tmp
|
||||
+ gunzip < $test_dir/expect.gz > $EXP1
|
||||
+else
|
||||
+ EXP=$test_dir/expect
|
||||
+fi
|
||||
+
|
||||
+echo mke2fs -q -F -t ext4 -o Linux -b 1024 test.img 32M > $OUT.new
|
||||
+$MKE2FS -q -F -t ext4 -o Linux -b 1024 $TMPFILE 32M >> $OUT.new 2>&1
|
||||
+
|
||||
+echo debugfs -w -R \"set_bg 1 free_blocks_count 65536\" /tmp/foo.img >> $OUT.new
|
||||
+$DEBUGFS -w -R "set_bg 1 free_blocks_count 65536" $TMPFILE > /dev/null 2>&1
|
||||
+
|
||||
+if type timeout > /dev/null 2>&1 ; then
|
||||
+ TIMEOUT="timeout -v 30s"
|
||||
+else
|
||||
+ TIMEOUT=
|
||||
+fi
|
||||
+
|
||||
+echo resize2fs -P /tmp/foo.img >> $OUT.new
|
||||
+$TIMEOUT $RESIZE2FS -P $TMPFILE >> $OUT.new 2>&1
|
||||
+
|
||||
+sed -f $cmd_dir/filter.sed < $OUT.new > $OUT
|
||||
+
|
||||
+rm -f $TMPFILE $OUT.new
|
||||
+
|
||||
+cmp -s $OUT $EXP
|
||||
+status=$?
|
||||
+
|
||||
+if [ "$status" = 0 ] ; then
|
||||
+ echo "$test_name: $test_description: ok"
|
||||
+ touch $test_name.ok
|
||||
+else
|
||||
+ echo "$test_name: $test_description: failed"
|
||||
+ diff $DIFF_OPTS $EXP $OUT > $test_name.failed
|
||||
+ rm -f $test_name.tmp
|
||||
+fi
|
||||
+
|
||||
+unset IMAGE OUT EXP TIMEOUT
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: e2fsprogs
|
||||
Version: 1.46.4
|
||||
Release: 26
|
||||
Release: 27
|
||||
Summary: Second extended file system management tools
|
||||
License: GPLv2+ and LGPLv2 and MIT
|
||||
URL: http://e2fsprogs.sourceforge.net/
|
||||
@ -52,6 +52,9 @@ Patch42: 0042-debugfs-Use-the-hash_version-from-superblock-if-a-fi.patch
|
||||
Patch43: 0043-tune2fs-fuse2fs-debugfs-save-error-information-durin.patch
|
||||
Patch44: 0044-resize2fs-use-Direct-I-O-when-reading-the-superblock.patch
|
||||
Patch45: 0045-modify-dumpe2fs-to-report-free-block-ranges-for-bigalloc.patch
|
||||
Patch46: 0046-e2fsck-fix-acl-block-leak-when-process-orphan-list.patch
|
||||
Patch47: 0047-e2fsck-when-mutating-file-name-make-sure-its-length-.patch
|
||||
Patch48: 0048-reisze2fs-sanity-check-free-block-group-counts-when-.patch
|
||||
|
||||
BuildRequires: gcc pkgconfig texinfo
|
||||
BuildRequires: fuse-devel libblkid-devel libuuid-devel
|
||||
@ -192,6 +195,9 @@ exit 0
|
||||
%{_mandir}/man8/*
|
||||
|
||||
%changelog
|
||||
* Thu May 30 2024 zhangjian <zhangjian496@huawei.com> - 1.46.4-27
|
||||
- backport upstream patch
|
||||
|
||||
* Tue May 07 2024 zhangxingrong <zhangxingrong@uniontech.com> - 1.46.4-26
|
||||
- backport upstream patch
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user