Skip to content

Commit 854f091

Browse files
committed
ext4: make xattr char unsignedness in hash explicit
Commit f3bbac3 ("ext4: deal with legacy signed xattr name hash values") added a hashing function for the legacy case of having the xattr hash calculated using a signed 'char' type. It left the unsigned case alone, since it's all implicitly handled by the '-funsigned-char' compiler option. However, there's been some noise about back-porting it all into stable kernels that lack the '-funsigned-char', so let's just make that at least possible by making the whole 'this uses unsigned char' very explicit in the code itself. Whether such a back-port is really warranted or not, I'll leave to others, but at least together with this change it is technically sensible. Also, add a 'pr_warn_once()' for reporting the "hey, signedness for this hash calculation has changed" issue. Hopefully it never triggers except for that xfstests generic/454 test-case, but even if it does it's just good information to have. If for no other reason than "we can remove the legacy signed hash code entirely if nobody ever sees the message any more". Cc: Sasha Levin <sashal@kernel.org> Cc: Eric Biggers <ebiggers@kernel.org> Cc: Andreas Dilger <adilger@dilger.ca> Cc: Theodore Ts'o <tytso@mit.edu>, Cc: Jason Donenfeld <Jason@zx2c4.com> Cc: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7bf70db commit 854f091

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fs/ext4/xattr.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,12 @@ ext4_xattr_inode_verify_hashes(struct inode *ea_inode,
482482
*/
483483
e_hash = ext4_xattr_hash_entry_signed(entry->e_name, entry->e_name_len,
484484
&tmp_data, 1);
485-
if (e_hash == entry->e_hash)
486-
return 0;
487-
488485
/* Still no match - bad */
489-
return -EFSCORRUPTED;
486+
if (e_hash != entry->e_hash)
487+
return -EFSCORRUPTED;
488+
489+
/* Let people know about old hash */
490+
pr_warn_once("ext4: filesystem with signed xattr name hash");
490491
}
491492
return 0;
492493
}
@@ -3096,7 +3097,7 @@ static __le32 ext4_xattr_hash_entry(char *name, size_t name_len, __le32 *value,
30963097
while (name_len--) {
30973098
hash = (hash << NAME_HASH_SHIFT) ^
30983099
(hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3099-
*name++;
3100+
(unsigned char)*name++;
31003101
}
31013102
while (value_count--) {
31023103
hash = (hash << VALUE_HASH_SHIFT) ^

0 commit comments

Comments
 (0)