Commit:     17398957aa0a05ef62535060b41d103590dcc533
Parent:     dddfa461fc8951f9b5f951c13565b6cac678635a
Author:     Michael Halcrow <[EMAIL PROTECTED]>
AuthorDate: Mon Feb 12 00:53:45 2007 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Mon Feb 12 09:48:36 2007 -0800

    [PATCH] eCryptfs: xattr flags and mount options
    This patch set introduces the ability to store cryptographic metadata into 
    lower file extended attribute rather than the lower file header region.
    This patch set implements two new mount options:
     - When set, newly created files will have their cryptographic
       metadata stored in the extended attribute region of the file rather
       than the header.
       When storing the data in the file header, there is a minimum of 8KB
       reserved for the header information for each file, making each file at
       least 12KB in size.  This can take up a lot of extra disk space if the 
       creates a lot of small files.  By storing the data in the extended
       attribute, each file will only occupy at least of 4KB of space.
       As the eCryptfs metadata set becomes larger with new features such as
       multi-key associations, most popular filesystems will not be able to 
       all of the information in the xattr region in some cases due to space
       constraints.  However, the majority of users will only ever associate one
       key per file, so most users will be okay with storing their data in the
       xattr region.
       This option should be used with caution.  I want to emphasize that the
       xattr must be maintained under all circumstances, or the file will be
       rendered permanently unrecoverable.  The last thing I want is for a user 
       forget to set an xattr flag in a backup utility, only to later discover
       that their backups are worthless.
     - When set, this option causes eCryptfs to present applications a
       view of encrypted files as if the cryptographic metadata were
       stored in the file header, whether the metadata is actually stored
       in the header or in the extended attributes.
       No matter what eCryptfs winds up doing in the lower filesystem, I want
       to preserve a baseline format compatibility for the encrypted files.  As 
       right now, the metadata may be in the file header or in an xattr.  There 
       no reason why the metadata could not be put in a separate file in future
       Without the compatibility mode, backup utilities would have to know to
       back up the metadata file along with the files.  The semantics of 
       have always been that the lower files are self-contained units of 
       data, and the only additional information required to decrypt any given
       eCryptfs file is the key.  That is what has always been emphasized about
       eCryptfs lower files, and that is what users expect.  Providing the
       encrypted view option will provide a way to userspace applications 
       they can always get to the same old familiar eCryptfs encrypted files,
       regardless of what eCryptfs winds up doing with the metadata behind the
    This patch:
    Add extended attribute support to version bit vector, flags to indicate when
    xattr or encrypted view modes are enabled, and support for the new mount
    Signed-off-by: Michael Halcrow <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 fs/ecryptfs/crypto.c          |   20 ++++++++++++++++++++
 fs/ecryptfs/ecryptfs_kernel.h |   15 ++++++++++-----
 fs/ecryptfs/main.c            |   18 ++++++++++++++++--
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 75bbfae..6d85aab 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -915,6 +915,22 @@ static void ecryptfs_generate_new_key(struct 
ecryptfs_crypt_stat *crypt_stat)
+ * ecryptfs_copy_mount_wide_flags_to_inode_flags
+ *
+ * This function propagates the mount-wide flags to individual inode
+ * flags.
+ */
+static void ecryptfs_copy_mount_wide_flags_to_inode_flags(
+       struct ecryptfs_crypt_stat *crypt_stat,
+       struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
+       if (mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED)
+               crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
+       if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
+               crypt_stat->flags |= ECRYPTFS_VIEW_AS_ENCRYPTED;
  * ecryptfs_set_default_crypt_stat_vals
  * @crypt_stat
@@ -924,6 +940,8 @@ static void ecryptfs_set_default_crypt_stat_vals(
        struct ecryptfs_crypt_stat *crypt_stat,
        struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
+       ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat,
+                                                     mount_crypt_stat);
        strcpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER);
        crypt_stat->key_size = ECRYPTFS_DEFAULT_KEY_BYTES;
@@ -969,6 +987,8 @@ int ecryptfs_new_file_context(struct dentry 
                                "file using mount_crypt_stat\n");
                ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED);
                ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID);
+               ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat,
+                                                             mount_crypt_stat);
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index f21385f..7bbd6e6 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -43,13 +43,14 @@
  * module; userspace tools such as the mount helper read
  * ECRYPTFS_VERSIONING_MASK from a sysfs handle in order to determine
  * how to behave. */
+#define ECRYPTFS_VERSIONING_PASSPHRASE            0x00000001
+#define ECRYPTFS_VERSIONING_PUBKEY                0x00000002
+#define ECRYPTFS_VERSIONING_POLICY                0x00000008
+#define ECRYPTFS_VERSIONING_XATTR                 0x00000010
-                                  | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
-                                  | ECRYPTFS_VERSIONING_PUBKEY)
+                                 | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
+                                 | ECRYPTFS_VERSIONING_PUBKEY)
@@ -227,6 +228,8 @@ struct ecryptfs_crypt_stat {
 #define ECRYPTFS_ENABLE_HMAC        0x00000020
 #define ECRYPTFS_ENCRYPT_IV_PAGES   0x00000040
 #define ECRYPTFS_KEY_VALID          0x00000080
+#define ECRYPTFS_METADATA_IN_XATTR  0x00000100
+#define ECRYPTFS_VIEW_AS_ENCRYPTED  0x00000200
        u32 flags;
        unsigned int file_version;
        size_t iv_bytes;
@@ -273,6 +276,8 @@ struct ecryptfs_dentry_info {
 struct ecryptfs_mount_crypt_stat {
        /* Pointers to memory we do not own, do not free these */
+#define ECRYPTFS_XATTR_METADATA_ENABLED        0x00000002
+#define ECRYPTFS_ENCRYPTED_VIEW_ENABLED        0x00000004
        u32 flags;
        struct ecryptfs_auth_tok *global_auth_tok;
        struct key *global_auth_tok_key;
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 87f05c4..a3efdcc 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -162,7 +162,8 @@ out:
 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, ecryptfs_opt_debug,
        ecryptfs_opt_ecryptfs_debug, ecryptfs_opt_cipher,
        ecryptfs_opt_ecryptfs_cipher, ecryptfs_opt_ecryptfs_key_bytes,
-       ecryptfs_opt_passthrough, ecryptfs_opt_err };
+       ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
+       ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
 static match_table_t tokens = {
        {ecryptfs_opt_sig, "sig=%s"},
@@ -173,6 +174,8 @@ static match_table_t tokens = {
        {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
        {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
        {ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
+       {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
+       {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
        {ecryptfs_opt_err, NULL}
@@ -313,6 +316,16 @@ static int ecryptfs_parse_options(struct super_block *sb, 
char *options)
                        mount_crypt_stat->flags |=
+               case ecryptfs_opt_xattr_metadata:
+                       mount_crypt_stat->flags |=
+                               ECRYPTFS_XATTR_METADATA_ENABLED;
+                       break;
+               case ecryptfs_opt_encrypted_view:
+                       mount_crypt_stat->flags |=
+                               ECRYPTFS_XATTR_METADATA_ENABLED;
+                       mount_crypt_stat->flags |=
+                               ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
+                       break;
                case ecryptfs_opt_err:
@@ -734,7 +747,8 @@ static struct ecryptfs_version_str_map_elem {
        {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
+       {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"}
 static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to