History

ext4: deal with legacy signed xattr name hash values

We potentially have old hashes of the xattr names generated on systems with signed 'char' types. Now that everybody uses '-funsigned-char', those hashes will no longer match. This only happens if you use xattrs names that have the high bit set, which probably doesn't happen in practice, but the xfstest generic/454 shows it. Instead of adding a new "signed xattr hash filesystem" bit and having to deal with all the possible combinations, just calculate the hash both ways if the first one fails, and always generate new hashes with the proper unsigned char version.

Linus Torvalds committed 3 years ago

Commit f3bbac31 parent f8836751 file · +39 −2Browse files

Unified · Split

fs/ext4/xattr.c+39−2
@@ -81,6 +81,8 @@ ext4_xattr_block_cache_find(struct inode *, struct ext4_xattr_header *, · 80 unmodified lines
81 struct mb_cache_entry **);81 struct mb_cache_entry **);
82static __le32 ext4_xattr_hash_entry(char *name, size_t name_len, __le32 *value,82static __le32 ext4_xattr_hash_entry(char *name, size_t name_len, __le32 *value,
83 size_t value_count);83 size_t value_count);
84static __le32 ext4_xattr_hash_entry_signed(char *name, size_t name_len, __le32 *value,
85 size_t value_count);
84static void ext4_xattr_rehash(struct ext4_xattr_header *);86static void ext4_xattr_rehash(struct ext4_xattr_header *);
85 87
86static const struct xattr_handler * const ext4_xattr_handler_map[] = {88static const struct xattr_handler * const ext4_xattr_handler_map[] = {
@@ -470,8 +472,21 @@ ext4_xattr_inode_verify_hashes(struct inode *ea_inode, · 383 unmodified lines
470 tmp_data = cpu_to_le32(hash);472 tmp_data = cpu_to_le32(hash);
471 e_hash = ext4_xattr_hash_entry(entry->e_name, entry->e_name_len,473 e_hash = ext4_xattr_hash_entry(entry->e_name, entry->e_name_len,
472 &tmp_data, 1);474 &tmp_data, 1);
473 if (e_hash != entry->e_hash)475 /* All good? */
474 return -EFSCORRUPTED;476 if (e_hash == entry->e_hash)
477 return 0;
478
479 /*
480 * Not good. Maybe the entry hash was calculated
481 * using the buggy signed char version?
482 */
483 e_hash = ext4_xattr_hash_entry_signed(entry->e_name, entry->e_name_len,
484 &tmp_data, 1);
485 if (e_hash == entry->e_hash)
486 return 0;
487
488 /* Still no match - bad */
489 return -EFSCORRUPTED;
475 }490 }
476 return 0;491 return 0;
477}492}
@@ -3091,6 +3106,28 @@ static __le32 ext4_xattr_hash_entry(char *name, size_t name_len, __le32 *value, · 2613 unmodified lines
3091 return cpu_to_le32(hash);3106 return cpu_to_le32(hash);
3092}3107}
3093 3108
3109/*
3110 * ext4_xattr_hash_entry_signed()
3111 *
3112 * Compute the hash of an extended attribute incorrectly.
3113 */
3114static __le32 ext4_xattr_hash_entry_signed(char *name, size_t name_len, __le32 *value, size_t value_count)
3115{
3116 __u32 hash = 0;
3117
3118 while (name_len--) {
3119 hash = (hash << NAME_HASH_SHIFT) ^
3120 (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
3121 (signed char)*name++;
3122 }
3123 while (value_count--) {
3124 hash = (hash << VALUE_HASH_SHIFT) ^
3125 (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
3126 le32_to_cpu(*value++);
3127 }
3128 return cpu_to_le32(hash);
3129}
3130
3094#undef NAME_HASH_SHIFT3131#undef NAME_HASH_SHIFT
3095#undef VALUE_HASH_SHIFT3132#undef VALUE_HASH_SHIFT
3096 3133

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t