Linux-ext4 Archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.14 8/9] ext4: avoid remove directory when directory is corrupted
       [not found] <20220814153637.2380406-1-sashal@kernel.org>
@ 2022-08-14 15:36 ` Sasha Levin
  2022-08-14 15:36 ` [PATCH AUTOSEL 4.14 9/9] ext4: avoid resizing to a partial cluster size Sasha Levin
  1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2022-08-14 15:36 UTC (permalink / raw
  To: linux-kernel, stable
  Cc: Ye Bin, Jan Kara, Theodore Ts'o, Sasha Levin, adilger.kernel,
	linux-ext4

From: Ye Bin <yebin10@huawei.com>

[ Upstream commit b24e77ef1c6d4dbf42749ad4903c97539cc9755a ]

Now if check directoy entry is corrupted, ext4_empty_dir may return true
then directory will be removed when file system mounted with "errors=continue".
In order not to make things worse just return false when directory is corrupted.

Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220622090223.682234-1-yebin10@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ext4/namei.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index c5f289737d0f..2460ac22e632 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2804,11 +2804,8 @@ bool ext4_empty_dir(struct inode *inode)
 		de = (struct ext4_dir_entry_2 *) (bh->b_data +
 					(offset & (sb->s_blocksize - 1)));
 		if (ext4_check_dir_entry(inode, NULL, de, bh,
-					 bh->b_data, bh->b_size, offset)) {
-			offset = (offset | (sb->s_blocksize - 1)) + 1;
-			continue;
-		}
-		if (le32_to_cpu(de->inode)) {
+					 bh->b_data, bh->b_size, offset) ||
+		    le32_to_cpu(de->inode)) {
 			brelse(bh);
 			return false;
 		}
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH AUTOSEL 4.14 9/9] ext4: avoid resizing to a partial cluster size
       [not found] <20220814153637.2380406-1-sashal@kernel.org>
  2022-08-14 15:36 ` [PATCH AUTOSEL 4.14 8/9] ext4: avoid remove directory when directory is corrupted Sasha Levin
@ 2022-08-14 15:36 ` Sasha Levin
  1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2022-08-14 15:36 UTC (permalink / raw
  To: linux-kernel, stable
  Cc: Kiselev, Oleg, Theodore Ts'o, Sasha Levin, adilger.kernel,
	linux-ext4

From: "Kiselev, Oleg" <okiselev@amazon.com>

[ Upstream commit 69cb8e9d8cd97cdf5e293b26d70a9dee3e35e6bd ]

This patch avoids an attempt to resize the filesystem to an
unaligned cluster boundary.  An online resize to a size that is not
integral to cluster size results in the last iteration attempting to
grow the fs by a negative amount, which trips a BUG_ON and leaves the fs
with a corrupted in-memory superblock.

Signed-off-by: Oleg Kiselev <okiselev@amazon.com>
Link: https://lore.kernel.org/r/0E92A0AB-4F16-4F1A-94B7-702CC6504FDE@amazon.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ext4/resize.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 721a00767d0e..aab86205c056 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1950,6 +1950,16 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 	}
 	brelse(bh);
 
+	/*
+	 * For bigalloc, trim the requested size to the nearest cluster
+	 * boundary to avoid creating an unusable filesystem. We do this
+	 * silently, instead of returning an error, to avoid breaking
+	 * callers that blindly resize the filesystem to the full size of
+	 * the underlying block device.
+	 */
+	if (ext4_has_feature_bigalloc(sb))
+		n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1);
+
 retry:
 	o_blocks_count = ext4_blocks_count(es);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-14 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20220814153637.2380406-1-sashal@kernel.org>
2022-08-14 15:36 ` [PATCH AUTOSEL 4.14 8/9] ext4: avoid remove directory when directory is corrupted Sasha Levin
2022-08-14 15:36 ` [PATCH AUTOSEL 4.14 9/9] ext4: avoid resizing to a partial cluster size Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).