From 3568d9297dccd7dcff9d46648a2239064c013574 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 30 Jul 2021 19:44:26 +0100 Subject: [PATCH] e2fsck: fix '..' directory repair on big-endian systems The bug is initially observed on hppa and sparc by Rolf Eike Beer where `f_baddotdir` test failed cimplaining about invalid ".." directly after repair. It's a regression bisected down to 63f44aaf ("e2fsck: fix ".." more gracefully if possible "). The bug happens in check_dot() where repair splits one on-disk dirent into two: | dirent "." | | ... more ... | dirent "." | dirent ".." | ... more ... | The problem is that newly creted ".." dirent is in on-disk little-endian format as ext2fs_read_dir_block4() only accounted for oversized "." dirent. The change explicitly flips bytes around for dirent "..". Tested on powerpc-unknown-linux-gnu. Reported-by: Rolf Eike Beer Bug: https://bugs.gentoo.org/790191 Bug: https://github.com/tytso/e2fsprogs/issues/75 Fixes: 63f44aaf ("e2fsck: fix ".." more gracefully if possible ") Signed-off-by: Sergei Trofimovich --- e2fsck/pass2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index f00cb40e..48a37872 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -447,6 +447,12 @@ static int check_dot(e2fsck_t ctx, nextdir = (struct ext2_dir_entry *) ((char *) dirent + 12); dirent->rec_len = 12; +#ifdef WORDS_BIGENDIAN + /* We discover new on disk dir entry. + * Account for it's endianness. */ + ext2fs_dirent_swab_in2(ctx->fs, + nextdir, new_len, 0); +#endif /* if the next entry looks like "..", leave it * and let check_dotdot() verify the dirent, * otherwise zap the following entry. */ -- 2.32.0