Skip to content

Commit aa1dca3

Browse files
ebiggerstytso
authored andcommitted
ext4: inherit encryption xattr before other xattrs
When using both encryption and SELinux (or another feature that requires an xattr per file) on a filesystem with 256-byte inodes, each file's xattrs usually spill into an external xattr block. Currently, the xattrs are inherited in the order ACL, security, then encryption. Therefore, if spillage occurs, the encryption xattr will always end up in the external block. This is not ideal because the encryption xattrs contain a nonce, so they will always be unique and will prevent the external xattr blocks from being deduplicated. To improve the situation, change the inheritance order to encryption, ACL, then security. This gives the encryption xattr a better chance to be stored in-inode, allowing the other xattr(s) to be deduplicated. Note that it may be better for userspace to format the filesystem with 512-byte inodes in this case. However, it's not the default. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 72d622b commit aa1dca3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎fs/ext4/ialloc.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,17 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
10981098
if (err)
10991099
goto fail_drop;
11001100

1101+
/*
1102+
* Since the encryption xattr will always be unique, create it first so
1103+
* that it's less likely to end up in an external xattr block and
1104+
* prevent its deduplication.
1105+
*/
1106+
if (encrypt) {
1107+
err = fscrypt_inherit_context(dir, inode, handle, true);
1108+
if (err)
1109+
goto fail_free_drop;
1110+
}
1111+
11011112
err = ext4_init_acl(handle, inode, dir);
11021113
if (err)
11031114
goto fail_free_drop;
@@ -1119,12 +1130,6 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
11191130
ei->i_datasync_tid = handle->h_transaction->t_tid;
11201131
}
11211132

1122-
if (encrypt) {
1123-
err = fscrypt_inherit_context(dir, inode, handle, true);
1124-
if (err)
1125-
goto fail_free_drop;
1126-
}
1127-
11281133
err = ext4_mark_inode_dirty(handle, inode);
11291134
if (err) {
11301135
ext4_std_error(sb, err);

0 commit comments

Comments
 (0)