Skip to contentSkip to conversation

ext4: improve error handling from ext4_dirhash()

PATCH New Theodore Ts'o 1 participant 1 message May 6, 2023 ext4 file system

lore
Share & tools
lore

Theodore Ts'o

author maintainer
#0 lore raw

PATCH 1/1 ext4: improve error handling from ext4_dirhash()

The ext4_dirhash() will *almost* never fail, especially when the hash tree feature was first introduced. However, with the addition of support of encrypted, casefolded file names, that function can most certainly fail today.

So make sure the callers of ext4_dirhash() properly check for failures, and reflect the errors back up to their callers.

---
 fs/ext4/hash.c  |  7 ++++++-
 fs/ext4/namei.c | 53 ++++++++++++++++++++++++++++++++++---------------
 2 files changed, 43 insertions(+), 17 deletions(-)
fs/ext4/hash.c +6 -1
index 147b5241dd94..e43b32ef9380 100644
@@ -277,7 +277,12 @@ static int __ext4fs_dirhash(const struct inode *dir, const char *name, int len,
 	}
 	default:
 		hinfo->hash = 0;
-		return -1;
+		hinfo->minor_hash = 0;
+		ext4_warning(dir->i_sb,
+			     "invalid/unsupported hash tree version %u",
+			     hinfo->hash_version);
+		WARN_ON_ONCE(1);
+		return -EINVAL;
 	}
 	hash = hash & ~1;
 	if (hash == (EXT4_HTREE_EOF_32BIT << 1))
fs/ext4/namei.c +37 -16

102 lines not on this page · raw message

Signature · 1 line
2.31.0