public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Lizhi Xu <lizhi.xu@windriver.com>,
	 adilger.kernel@dilger.ca, coreteam@netfilter.org,
	 davem@davemloft.net,  ebiggers@kernel.org, fw@strlen.de,
	 jaegeuk@kernel.org,  kadlec@netfilter.org, kuba@kernel.org,
	 linux-ext4@vger.kernel.org, linux-fscrypt@vger.kernel.org,
	 linux-kernel@vger.kernel.org, lkp@intel.com,
	 llvm@lists.linux.dev,  netdev@vger.kernel.org,
	netfilter-devel@vger.kernel.org,  oe-kbuild-all@lists.linux.dev,
	pablo@netfilter.org,
	syzbot+340581ba9dceb7e06fb3@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH] ext4: Fix error message when rejecting the default hash
Date: Tue, 27 Aug 2024 16:16:36 -0400	[thread overview]
Message-ID: <87jzg1en6j.fsf_-_@mailhost.krisman.be> (raw)
In-Reply-To: <172433877724.370733.16770771071139702263.b4-ty@mit.edu> (Theodore Ts'o's message of "Thu, 22 Aug 2024 11:00:11 -0400")

"Theodore Ts'o" <tytso@mit.edu> writes:

> On Wed, 05 Jun 2024 09:23:35 +0800, Lizhi Xu wrote:
>> When mounting the ext4 filesystem, if the default hash version is set to
>> DX_HASH_SIPHASH but the casefold feature is not set, exit the mounting.
>> 
>> 
>
> Applied, thanks!
>
> [1/1] fs/ext4: Filesystem without casefold feature cannot be mounted with spihash
>       commit: 985b67cd86392310d9e9326de941c22fc9340eec

Ted,

Since you took the above, can you please consider the following fixup?
I had pointed we shouldn't have siphash as the sb default hash at all:

based on your dev branch.

>8
Subject: [PATCH] ext4: Fix error message when rejecting the default hash

Commit 985b67cd8639 ("ext4: filesystems without casefold feature cannot
be mounted with siphash") properly rejects volumes where
s_def_hash_version is set to DX_HASH_SIPHASH, but the check and the
error message should not look into casefold setup - a filesystem should
never have DX_HASH_SIPHASH as the default hash.  Fix it and, since we
are there, move the check to ext4_hash_info_init.

Fixes:985b67cd8639 ("ext4: filesystems without casefold feature cannot
be mounted with siphash")
Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
 fs/ext4/ext4.h  |  1 +
 fs/ext4/super.c | 27 +++++++++++++++++----------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 5845e4aa091a..4120f24880cb 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2462,6 +2462,7 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
 #define DX_HASH_HALF_MD4_UNSIGNED	4
 #define DX_HASH_TEA_UNSIGNED		5
 #define DX_HASH_SIPHASH			6
+#define DX_HASH_LAST 			DX_HASH_SIPHASH
 
 static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
 			      const void *address, unsigned int length)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 25cd0d662e31..c6a34ad07ecc 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3582,13 +3582,6 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly)
 			 "mounted without CONFIG_UNICODE");
 		return 0;
 	}
-	if (EXT4_SB(sb)->s_es->s_def_hash_version == DX_HASH_SIPHASH &&
-	    !ext4_has_feature_casefold(sb)) {
-		ext4_msg(sb, KERN_ERR,
-			 "Filesystem without casefold feature cannot be "
-			 "mounted with siphash");
-		return 0;
-	}
 
 	if (readonly)
 		return 1;
@@ -5094,16 +5087,27 @@ static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,
 	return ret;
 }
 
-static void ext4_hash_info_init(struct super_block *sb)
+static int ext4_hash_info_init(struct super_block *sb)
 {
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct ext4_super_block *es = sbi->s_es;
 	unsigned int i;
 
+	sbi->s_def_hash_version = es->s_def_hash_version;
+
+	if (sbi->s_def_hash_version > DX_HASH_LAST) {
+		ext4_msg(sb, KERN_ERR,
+			 "Invalid default hash set in the superblock");
+		return -EINVAL;
+	} else if (sbi->s_def_hash_version == DX_HASH_SIPHASH) {
+		ext4_msg(sb, KERN_ERR,
+			 "SIPHASH is not a valid default hash value");
+		return -EINVAL;
+	}
+
 	for (i = 0; i < 4; i++)
 		sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
 
-	sbi->s_def_hash_version = es->s_def_hash_version;
 	if (ext4_has_feature_dir_index(sb)) {
 		i = le32_to_cpu(es->s_flags);
 		if (i & EXT2_FLAGS_UNSIGNED_HASH)
@@ -5121,6 +5125,7 @@ static void ext4_hash_info_init(struct super_block *sb)
 #endif
 		}
 	}
+	return 0;
 }
 
 static int ext4_block_group_meta_init(struct super_block *sb, int silent)
@@ -5256,7 +5261,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	if (err)
 		goto failed_mount;
 
-	ext4_hash_info_init(sb);
+	err = ext4_hash_info_init(sb);
+	if (err)
+		goto failed_mount;
 
 	err = ext4_handle_clustersize(sb);
 	if (err)
-- 
2.46.0

  reply	other threads:[~2024-08-27 20:16 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 20:41 [syzbot] [fscrypt?] WARNING in fscrypt_fname_siphash syzbot
2024-05-30  6:32 ` [syzbot] " syzbot
2024-05-30  7:41 ` [PATCH] ext4: add casefolded file check Lizhi Xu
2024-05-31  1:05   ` Eric Biggers
2024-05-31  1:47     ` Lizhi Xu
2024-05-31  2:20       ` Eric Biggers
2024-05-31  3:07     ` [PATCH V2] ext4: add casefolded feature check before setup encrypted info Lizhi Xu
2024-05-31  3:11       ` Eric Biggers
2024-05-31  8:58       ` kernel test robot
2024-05-31  9:06         ` [PATCH V4] ext4: check hash version and filesystem casefolded consistent Lizhi Xu
2024-05-31 18:55           ` Eric Biggers
2024-06-01 11:37             ` [PATCH V5] " Lizhi Xu
2024-06-03 14:50               ` Gabriel Krisman Bertazi
2024-06-04  1:17                 ` Lizhi Xu
2024-06-04 19:06                   ` Gabriel Krisman Bertazi
2024-06-05  1:16                     ` Lizhi Xu
2024-06-05  1:23                     ` [PATCH V6] fs/ext4: Filesystem without casefold feature cannot be mounted with spihash Lizhi Xu
2024-08-22 15:00                       ` Theodore Ts'o
2024-08-27 20:16                         ` Gabriel Krisman Bertazi [this message]
2024-09-05 14:53                           ` [PATCH] ext4: Fix error message when rejecting the default hash Theodore Ts'o
2024-06-06  6:27                     ` [PATCH V5] ext4: check hash version and filesystem casefolded consistent Eric Biggers
2024-05-31  3:30     ` [PATCH V2] ext4: add casefolded feature check before setup encrypted info Lizhi Xu
2024-05-31  3:34       ` Eric Biggers
2024-05-31  8:56         ` [PATCH V3] ext4: check hash version and filesystem casefolded consistent Lizhi Xu
2024-06-04  9:27           ` Dan Carpenter
2024-06-04  9:36             ` Lizhi Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jzg1en6j.fsf_-_@mailhost.krisman.be \
    --to=krisman@suse.de \
    --cc=adilger.kernel@dilger.ca \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=fw@strlen.de \
    --cc=jaegeuk@kernel.org \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.xu@windriver.com \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=pablo@netfilter.org \
    --cc=syzbot+340581ba9dceb7e06fb3@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox