]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: inherit encryption xattr before other xattrs
authorEric Biggers <ebiggers@google.com>
Tue, 2 May 2017 04:49:54 +0000 (00:49 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 2 May 2017 04:49:54 +0000 (00:49 -0400)
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>
fs/ext4/ialloc.c

index 17bc043308f33bb28cdb4d63ea7393b0dfc310e1..98ac2f1f23b3d74ec29ac31eeb276da4f1de5605 100644 (file)
@@ -1098,6 +1098,17 @@ got:
        if (err)
                goto fail_drop;
 
+       /*
+        * Since the encryption xattr will always be unique, create it first so
+        * that it's less likely to end up in an external xattr block and
+        * prevent its deduplication.
+        */
+       if (encrypt) {
+               err = fscrypt_inherit_context(dir, inode, handle, true);
+               if (err)
+                       goto fail_free_drop;
+       }
+
        err = ext4_init_acl(handle, inode, dir);
        if (err)
                goto fail_free_drop;
@@ -1119,12 +1130,6 @@ got:
                ei->i_datasync_tid = handle->h_transaction->t_tid;
        }
 
-       if (encrypt) {
-               err = fscrypt_inherit_context(dir, inode, handle, true);
-               if (err)
-                       goto fail_free_drop;
-       }
-
        err = ext4_mark_inode_dirty(handle, inode);
        if (err) {
                ext4_std_error(sb, err);