提交 e2bd99ec 编写于 作者: M Michael Halcrow 提交者: Linus Torvalds

[PATCH] eCryptfs: open-code flag checking and manipulation

Open-code flag checking and manipulation.
Signed-off-by: NMichael Halcrow <mhalcrow@us.ibm.com>
Signed-off-by: NTrevor Highland <tshighla@us.ibm.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 9d8b8ce5
...@@ -207,7 +207,7 @@ ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -207,7 +207,7 @@ ecryptfs_init_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat)
mutex_init(&crypt_stat->cs_mutex); mutex_init(&crypt_stat->cs_mutex);
mutex_init(&crypt_stat->cs_tfm_mutex); mutex_init(&crypt_stat->cs_tfm_mutex);
mutex_init(&crypt_stat->cs_hash_tfm_mutex); mutex_init(&crypt_stat->cs_hash_tfm_mutex);
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_STRUCT_INITIALIZED); crypt_stat->flags |= ECRYPTFS_STRUCT_INITIALIZED;
} }
/** /**
...@@ -305,8 +305,7 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -305,8 +305,7 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
int rc = 0; int rc = 0;
BUG_ON(!crypt_stat || !crypt_stat->tfm BUG_ON(!crypt_stat || !crypt_stat->tfm
|| !ECRYPTFS_CHECK_FLAG(crypt_stat->flags, || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED));
ECRYPTFS_STRUCT_INITIALIZED));
if (unlikely(ecryptfs_verbosity > 0)) { if (unlikely(ecryptfs_verbosity > 0)) {
ecryptfs_printk(KERN_DEBUG, "Key size [%d]; key:\n", ecryptfs_printk(KERN_DEBUG, "Key size [%d]; key:\n",
crypt_stat->key_size); crypt_stat->key_size);
...@@ -485,7 +484,7 @@ int ecryptfs_encrypt_page(struct ecryptfs_page_crypt_context *ctx) ...@@ -485,7 +484,7 @@ int ecryptfs_encrypt_page(struct ecryptfs_page_crypt_context *ctx)
lower_inode = ecryptfs_inode_to_lower(ctx->page->mapping->host); lower_inode = ecryptfs_inode_to_lower(ctx->page->mapping->host);
inode_info = ecryptfs_inode_to_private(ctx->page->mapping->host); inode_info = ecryptfs_inode_to_private(ctx->page->mapping->host);
crypt_stat = &inode_info->crypt_stat; crypt_stat = &inode_info->crypt_stat;
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED)) { if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
rc = ecryptfs_copy_page_to_lower(ctx->page, lower_inode, rc = ecryptfs_copy_page_to_lower(ctx->page, lower_inode,
ctx->param.lower_file); ctx->param.lower_file);
if (rc) if (rc)
...@@ -617,7 +616,7 @@ int ecryptfs_decrypt_page(struct file *file, struct page *page) ...@@ -617,7 +616,7 @@ int ecryptfs_decrypt_page(struct file *file, struct page *page)
crypt_stat = &(ecryptfs_inode_to_private( crypt_stat = &(ecryptfs_inode_to_private(
page->mapping->host)->crypt_stat); page->mapping->host)->crypt_stat);
lower_inode = ecryptfs_inode_to_lower(page->mapping->host); lower_inode = ecryptfs_inode_to_lower(page->mapping->host);
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED)) { if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
rc = ecryptfs_do_readpage(file, page, page->index); rc = ecryptfs_do_readpage(file, page, page->index);
if (rc) if (rc)
ecryptfs_printk(KERN_ERR, "Error attempting to copy " ecryptfs_printk(KERN_ERR, "Error attempting to copy "
...@@ -882,7 +881,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -882,7 +881,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat)
BUG_ON(crypt_stat->iv_bytes > MD5_DIGEST_SIZE); BUG_ON(crypt_stat->iv_bytes > MD5_DIGEST_SIZE);
BUG_ON(crypt_stat->iv_bytes <= 0); BUG_ON(crypt_stat->iv_bytes <= 0);
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID)) { if (!(crypt_stat->flags & ECRYPTFS_KEY_VALID)) {
rc = -EINVAL; rc = -EINVAL;
ecryptfs_printk(KERN_WARNING, "Session key not valid; " ecryptfs_printk(KERN_WARNING, "Session key not valid; "
"cannot generate root IV\n"); "cannot generate root IV\n");
...@@ -899,8 +898,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -899,8 +898,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat)
out: out:
if (rc) { if (rc) {
memset(crypt_stat->root_iv, 0, crypt_stat->iv_bytes); memset(crypt_stat->root_iv, 0, crypt_stat->iv_bytes);
ECRYPTFS_SET_FLAG(crypt_stat->flags, crypt_stat->flags |= ECRYPTFS_SECURITY_WARNING;
ECRYPTFS_SECURITY_WARNING);
} }
return rc; return rc;
} }
...@@ -908,7 +906,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -908,7 +906,7 @@ int ecryptfs_compute_root_iv(struct ecryptfs_crypt_stat *crypt_stat)
static void ecryptfs_generate_new_key(struct ecryptfs_crypt_stat *crypt_stat) static void ecryptfs_generate_new_key(struct ecryptfs_crypt_stat *crypt_stat)
{ {
get_random_bytes(crypt_stat->key, crypt_stat->key_size); get_random_bytes(crypt_stat->key, crypt_stat->key_size);
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID); crypt_stat->flags |= ECRYPTFS_KEY_VALID;
ecryptfs_compute_root_iv(crypt_stat); ecryptfs_compute_root_iv(crypt_stat);
if (unlikely(ecryptfs_verbosity > 0)) { if (unlikely(ecryptfs_verbosity > 0)) {
ecryptfs_printk(KERN_DEBUG, "Generated new session key:\n"); ecryptfs_printk(KERN_DEBUG, "Generated new session key:\n");
...@@ -948,7 +946,7 @@ static void ecryptfs_set_default_crypt_stat_vals( ...@@ -948,7 +946,7 @@ static void ecryptfs_set_default_crypt_stat_vals(
ecryptfs_set_default_sizes(crypt_stat); ecryptfs_set_default_sizes(crypt_stat);
strcpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER); strcpy(crypt_stat->cipher, ECRYPTFS_DEFAULT_CIPHER);
crypt_stat->key_size = ECRYPTFS_DEFAULT_KEY_BYTES; crypt_stat->key_size = ECRYPTFS_DEFAULT_KEY_BYTES;
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID); crypt_stat->flags &= ~(ECRYPTFS_KEY_VALID);
crypt_stat->file_version = ECRYPTFS_FILE_VERSION; crypt_stat->file_version = ECRYPTFS_FILE_VERSION;
crypt_stat->mount_crypt_stat = mount_crypt_stat; crypt_stat->mount_crypt_stat = mount_crypt_stat;
} }
...@@ -988,8 +986,8 @@ int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry) ...@@ -988,8 +986,8 @@ int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry)
if (mount_crypt_stat->global_auth_tok) { if (mount_crypt_stat->global_auth_tok) {
ecryptfs_printk(KERN_DEBUG, "Initializing context for new " ecryptfs_printk(KERN_DEBUG, "Initializing context for new "
"file using mount_crypt_stat\n"); "file using mount_crypt_stat\n");
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); crypt_stat->flags |= ECRYPTFS_ENCRYPTED;
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID); crypt_stat->flags |= ECRYPTFS_KEY_VALID;
ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat, ecryptfs_copy_mount_wide_flags_to_inode_flags(crypt_stat,
mount_crypt_stat); mount_crypt_stat);
memcpy(crypt_stat->keysigs[crypt_stat->num_keysigs++], memcpy(crypt_stat->keysigs[crypt_stat->num_keysigs++],
...@@ -1074,11 +1072,9 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -1074,11 +1072,9 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat,
for (i = 0; i < ((sizeof(ecryptfs_flag_map) for (i = 0; i < ((sizeof(ecryptfs_flag_map)
/ sizeof(struct ecryptfs_flag_map_elem))); i++) / sizeof(struct ecryptfs_flag_map_elem))); i++)
if (flags & ecryptfs_flag_map[i].file_flag) { if (flags & ecryptfs_flag_map[i].file_flag) {
ECRYPTFS_SET_FLAG(crypt_stat->flags, crypt_stat->flags |= ecryptfs_flag_map[i].local_flag;
ecryptfs_flag_map[i].local_flag);
} else } else
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, crypt_stat->flags &= ~(ecryptfs_flag_map[i].local_flag);
ecryptfs_flag_map[i].local_flag);
/* Version is in top 8 bits of the 32-bit flag vector */ /* Version is in top 8 bits of the 32-bit flag vector */
crypt_stat->file_version = ((flags >> 24) & 0xFF); crypt_stat->file_version = ((flags >> 24) & 0xFF);
(*bytes_read) = 4; (*bytes_read) = 4;
...@@ -1115,8 +1111,7 @@ write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat, ...@@ -1115,8 +1111,7 @@ write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat,
for (i = 0; i < ((sizeof(ecryptfs_flag_map) for (i = 0; i < ((sizeof(ecryptfs_flag_map)
/ sizeof(struct ecryptfs_flag_map_elem))); i++) / sizeof(struct ecryptfs_flag_map_elem))); i++)
if (ECRYPTFS_CHECK_FLAG(crypt_stat->flags, if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag)
ecryptfs_flag_map[i].local_flag))
flags |= ecryptfs_flag_map[i].file_flag; flags |= ecryptfs_flag_map[i].file_flag;
/* Version is in top 8 bits of the 32-bit flag vector */ /* Version is in top 8 bits of the 32-bit flag vector */
flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000); flags |= ((((u8)crypt_stat->file_version) << 24) & 0xFF000000);
...@@ -1414,10 +1409,8 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry, ...@@ -1414,10 +1409,8 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry,
crypt_stat = &ecryptfs_inode_to_private( crypt_stat = &ecryptfs_inode_to_private(
ecryptfs_dentry->d_inode)->crypt_stat; ecryptfs_dentry->d_inode)->crypt_stat;
if (likely(ECRYPTFS_CHECK_FLAG(crypt_stat->flags, if (likely(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
ECRYPTFS_ENCRYPTED))) { if (!(crypt_stat->flags & ECRYPTFS_KEY_VALID)) {
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags,
ECRYPTFS_KEY_VALID)) {
ecryptfs_printk(KERN_DEBUG, "Key is " ecryptfs_printk(KERN_DEBUG, "Key is "
"invalid; bailing out\n"); "invalid; bailing out\n");
rc = -EINVAL; rc = -EINVAL;
......
...@@ -36,7 +36,7 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok) ...@@ -36,7 +36,7 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n", ecryptfs_printk(KERN_DEBUG, "Auth tok at mem loc [%p]:\n",
auth_tok); auth_tok);
if (ECRYPTFS_CHECK_FLAG(auth_tok->flags, ECRYPTFS_PRIVATE_KEY)) { if (auth_tok->flags & ECRYPTFS_PRIVATE_KEY) {
ecryptfs_printk(KERN_DEBUG, " * private key type\n"); ecryptfs_printk(KERN_DEBUG, " * private key type\n");
ecryptfs_printk(KERN_DEBUG, " * (NO PRIVATE KEY SUPPORT " ecryptfs_printk(KERN_DEBUG, " * (NO PRIVATE KEY SUPPORT "
"IN ECRYPTFS VERSION 0.1)\n"); "IN ECRYPTFS VERSION 0.1)\n");
...@@ -46,8 +46,8 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok) ...@@ -46,8 +46,8 @@ void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok)
ECRYPTFS_SALT_SIZE); ECRYPTFS_SALT_SIZE);
salt[ECRYPTFS_SALT_SIZE * 2] = '\0'; salt[ECRYPTFS_SALT_SIZE * 2] = '\0';
ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt); ecryptfs_printk(KERN_DEBUG, " * salt = [%s]\n", salt);
if (ECRYPTFS_CHECK_FLAG(auth_tok->token.password.flags, if (auth_tok->token.password.flags &
ECRYPTFS_PERSISTENT_PASSWORD)) { ECRYPTFS_PERSISTENT_PASSWORD) {
ecryptfs_printk(KERN_DEBUG, " * persistent\n"); ecryptfs_printk(KERN_DEBUG, " * persistent\n");
} }
memcpy(sig, auth_tok->token.password.signature, memcpy(sig, auth_tok->token.password.signature,
......
...@@ -94,9 +94,6 @@ ...@@ -94,9 +94,6 @@
#define RFC2440_CIPHER_TWOFISH 0x0a #define RFC2440_CIPHER_TWOFISH 0x0a
#define RFC2440_CIPHER_CAST_6 0x0b #define RFC2440_CIPHER_CAST_6 0x0b
#define ECRYPTFS_SET_FLAG(flag_bit_vector, flag) (flag_bit_vector |= (flag))
#define ECRYPTFS_CLEAR_FLAG(flag_bit_vector, flag) (flag_bit_vector &= ~(flag))
#define ECRYPTFS_CHECK_FLAG(flag_bit_vector, flag) (flag_bit_vector & (flag))
#define RFC2440_CIPHER_RSA 0x01 #define RFC2440_CIPHER_RSA 0x01
/** /**
......
...@@ -273,11 +273,11 @@ static int ecryptfs_open(struct inode *inode, struct file *file) ...@@ -273,11 +273,11 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
mutex_lock(&crypt_stat->cs_mutex); mutex_lock(&crypt_stat->cs_mutex);
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) { if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n");
/* Policy code enabled in future release */ /* Policy code enabled in future release */
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED); crypt_stat->flags |= ECRYPTFS_POLICY_APPLIED;
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); crypt_stat->flags |= ECRYPTFS_ENCRYPTED;
} }
mutex_unlock(&crypt_stat->cs_mutex); mutex_unlock(&crypt_stat->cs_mutex);
lower_flags = file->f_flags; lower_flags = file->f_flags;
...@@ -297,15 +297,13 @@ static int ecryptfs_open(struct inode *inode, struct file *file) ...@@ -297,15 +297,13 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
lower_inode = lower_dentry->d_inode; lower_inode = lower_dentry->d_inode;
if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
rc = 0; rc = 0;
goto out; goto out;
} }
mutex_lock(&crypt_stat->cs_mutex); mutex_lock(&crypt_stat->cs_mutex);
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
ECRYPTFS_POLICY_APPLIED) || !(crypt_stat->flags & ECRYPTFS_KEY_VALID)) {
|| !ECRYPTFS_CHECK_FLAG(crypt_stat->flags,
ECRYPTFS_KEY_VALID)) {
rc = ecryptfs_read_metadata(ecryptfs_dentry, lower_file); rc = ecryptfs_read_metadata(ecryptfs_dentry, lower_file);
if (rc) { if (rc) {
ecryptfs_printk(KERN_DEBUG, ecryptfs_printk(KERN_DEBUG,
...@@ -320,9 +318,8 @@ static int ecryptfs_open(struct inode *inode, struct file *file) ...@@ -320,9 +318,8 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
mutex_unlock(&crypt_stat->cs_mutex); mutex_unlock(&crypt_stat->cs_mutex);
goto out_puts; goto out_puts;
} }
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags,
ECRYPTFS_ENCRYPTED);
rc = 0; rc = 0;
crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
mutex_unlock(&crypt_stat->cs_mutex); mutex_unlock(&crypt_stat->cs_mutex);
goto out; goto out;
} }
......
...@@ -161,9 +161,8 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file, ...@@ -161,9 +161,8 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file,
ecryptfs_set_file_lower(&fake_file, lower_file); ecryptfs_set_file_lower(&fake_file, lower_file);
rc = ecryptfs_fill_zeros(&fake_file, 1); rc = ecryptfs_fill_zeros(&fake_file, 1);
if (rc) { if (rc) {
ECRYPTFS_SET_FLAG( ecryptfs_inode_to_private(inode)->crypt_stat.flags |=
ecryptfs_inode_to_private(inode)->crypt_stat.flags, ECRYPTFS_SECURITY_WARNING;
ECRYPTFS_SECURITY_WARNING);
ecryptfs_printk(KERN_WARNING, "Error attempting to fill zeros " ecryptfs_printk(KERN_WARNING, "Error attempting to fill zeros "
"in file; rc = [%d]\n", rc); "in file; rc = [%d]\n", rc);
goto out; goto out;
...@@ -172,8 +171,7 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file, ...@@ -172,8 +171,7 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file,
ecryptfs_write_inode_size_to_metadata(lower_file, lower_inode, inode, ecryptfs_write_inode_size_to_metadata(lower_file, lower_inode, inode,
ecryptfs_dentry, ecryptfs_dentry,
ECRYPTFS_LOWER_I_MUTEX_NOT_HELD); ECRYPTFS_LOWER_I_MUTEX_NOT_HELD);
ECRYPTFS_SET_FLAG(ecryptfs_inode_to_private(inode)->crypt_stat.flags, ecryptfs_inode_to_private(inode)->crypt_stat.flags |= ECRYPTFS_NEW_FILE;
ECRYPTFS_NEW_FILE);
out: out:
return rc; return rc;
} }
...@@ -216,10 +214,10 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) ...@@ -216,10 +214,10 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
lower_inode = lower_dentry->d_inode; lower_inode = lower_dentry->d_inode;
if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
goto out_fput; goto out_fput;
} }
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE); crypt_stat->flags |= ECRYPTFS_NEW_FILE;
ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
rc = ecryptfs_new_file_context(ecryptfs_dentry); rc = ecryptfs_new_file_context(ecryptfs_dentry);
if (rc) { if (rc) {
...@@ -373,7 +371,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -373,7 +371,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
goto out_dput; goto out_dput;
} }
crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
ecryptfs_set_default_sizes(crypt_stat); ecryptfs_set_default_sizes(crypt_stat);
rc = ecryptfs_read_and_validate_header_region(page_virt, lower_dentry, rc = ecryptfs_read_and_validate_header_region(page_virt, lower_dentry,
nd->mnt); nd->mnt);
......
...@@ -607,13 +607,13 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -607,13 +607,13 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat,
(*new_auth_tok)->session_key.flags |= (*new_auth_tok)->session_key.flags |=
ECRYPTFS_CONTAINS_ENCRYPTED_KEY; ECRYPTFS_CONTAINS_ENCRYPTED_KEY;
(*new_auth_tok)->token_type = ECRYPTFS_PRIVATE_KEY; (*new_auth_tok)->token_type = ECRYPTFS_PRIVATE_KEY;
ECRYPTFS_SET_FLAG((*new_auth_tok)->flags, ECRYPTFS_PRIVATE_KEY); (*new_auth_tok)->flags |= ECRYPTFS_PRIVATE_KEY;
/* TODO: Why are we setting this flag here? Don't we want the /* TODO: Why are we setting this flag here? Don't we want the
* userspace to decrypt the session key? */ * userspace to decrypt the session key? */
ECRYPTFS_CLEAR_FLAG((*new_auth_tok)->session_key.flags, (*new_auth_tok)->session_key.flags &=
ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT); ~(ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT);
ECRYPTFS_CLEAR_FLAG((*new_auth_tok)->session_key.flags, (*new_auth_tok)->session_key.flags &=
ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT); ~(ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT);
list_add(&auth_tok_list_item->list, auth_tok_list); list_add(&auth_tok_list_item->list, auth_tok_list);
goto out; goto out;
out_free: out_free:
...@@ -793,10 +793,10 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -793,10 +793,10 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat,
(*new_auth_tok)->token_type = ECRYPTFS_PASSWORD; (*new_auth_tok)->token_type = ECRYPTFS_PASSWORD;
/* TODO: Parametarize; we might actually want userspace to /* TODO: Parametarize; we might actually want userspace to
* decrypt the session key. */ * decrypt the session key. */
ECRYPTFS_CLEAR_FLAG((*new_auth_tok)->session_key.flags, (*new_auth_tok)->session_key.flags &=
ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT); ~(ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT);
ECRYPTFS_CLEAR_FLAG((*new_auth_tok)->session_key.flags, (*new_auth_tok)->session_key.flags &=
ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT); ~(ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT);
list_add(&auth_tok_list_item->list, auth_tok_list); list_add(&auth_tok_list_item->list, auth_tok_list);
goto out; goto out;
out_free: out_free:
...@@ -941,8 +941,7 @@ static int decrypt_session_key(struct ecryptfs_auth_tok *auth_tok, ...@@ -941,8 +941,7 @@ static int decrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
int rc = 0; int rc = 0;
password_s_ptr = &auth_tok->token.password; password_s_ptr = &auth_tok->token.password;
if (ECRYPTFS_CHECK_FLAG(password_s_ptr->flags, if (password_s_ptr->flags & ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET)
ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET))
ecryptfs_printk(KERN_DEBUG, "Session key encryption key " ecryptfs_printk(KERN_DEBUG, "Session key encryption key "
"set; skipping key generation\n"); "set; skipping key generation\n");
ecryptfs_printk(KERN_DEBUG, "Session key encryption key (size [%d])" ecryptfs_printk(KERN_DEBUG, "Session key encryption key (size [%d])"
...@@ -1024,7 +1023,7 @@ static int decrypt_session_key(struct ecryptfs_auth_tok *auth_tok, ...@@ -1024,7 +1023,7 @@ static int decrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
auth_tok->session_key.flags |= ECRYPTFS_CONTAINS_DECRYPTED_KEY; auth_tok->session_key.flags |= ECRYPTFS_CONTAINS_DECRYPTED_KEY;
memcpy(crypt_stat->key, auth_tok->session_key.decrypted_key, memcpy(crypt_stat->key, auth_tok->session_key.decrypted_key,
auth_tok->session_key.decrypted_key_size); auth_tok->session_key.decrypted_key_size);
ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_KEY_VALID); crypt_stat->flags |= ECRYPTFS_KEY_VALID;
ecryptfs_printk(KERN_DEBUG, "Decrypted session key:\n"); ecryptfs_printk(KERN_DEBUG, "Decrypted session key:\n");
if (ecryptfs_verbosity > 0) if (ecryptfs_verbosity > 0)
ecryptfs_dump_hex(crypt_stat->key, ecryptfs_dump_hex(crypt_stat->key,
...@@ -1127,8 +1126,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -1127,8 +1126,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
sig_tmp_space, tag_11_contents_size); sig_tmp_space, tag_11_contents_size);
new_auth_tok->token.password.signature[ new_auth_tok->token.password.signature[
ECRYPTFS_PASSWORD_SIG_SIZE] = '\0'; ECRYPTFS_PASSWORD_SIG_SIZE] = '\0';
ECRYPTFS_SET_FLAG(crypt_stat->flags, crypt_stat->flags |= ECRYPTFS_ENCRYPTED;
ECRYPTFS_ENCRYPTED);
break; break;
case ECRYPTFS_TAG_1_PACKET_TYPE: case ECRYPTFS_TAG_1_PACKET_TYPE:
rc = parse_tag_1_packet(crypt_stat, rc = parse_tag_1_packet(crypt_stat,
...@@ -1142,8 +1140,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -1142,8 +1140,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
goto out_wipe_list; goto out_wipe_list;
} }
i += packet_size; i += packet_size;
ECRYPTFS_SET_FLAG(crypt_stat->flags, crypt_stat->flags |= ECRYPTFS_ENCRYPTED;
ECRYPTFS_ENCRYPTED);
break; break;
case ECRYPTFS_TAG_11_PACKET_TYPE: case ECRYPTFS_TAG_11_PACKET_TYPE:
ecryptfs_printk(KERN_WARNING, "Invalid packet set " ecryptfs_printk(KERN_WARNING, "Invalid packet set "
...@@ -1209,8 +1206,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -1209,8 +1206,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
} }
leave_list: leave_list:
rc = -ENOTSUPP; rc = -ENOTSUPP;
if ((ECRYPTFS_CHECK_FLAG(candidate_auth_tok->flags, if (candidate_auth_tok->token_type == ECRYPTFS_PRIVATE_KEY) {
ECRYPTFS_PRIVATE_KEY))) {
memcpy(&(candidate_auth_tok->token.private_key), memcpy(&(candidate_auth_tok->token.private_key),
&(chosen_auth_tok->token.private_key), &(chosen_auth_tok->token.private_key),
sizeof(struct ecryptfs_private_key)); sizeof(struct ecryptfs_private_key));
......
...@@ -295,8 +295,8 @@ static int ecryptfs_readpage(struct file *file, struct page *page) ...@@ -295,8 +295,8 @@ static int ecryptfs_readpage(struct file *file, struct page *page)
crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode) crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
->crypt_stat; ->crypt_stat;
if (!crypt_stat if (!crypt_stat
|| !ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED) || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
|| ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) { || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
ecryptfs_printk(KERN_DEBUG, ecryptfs_printk(KERN_DEBUG,
"Passing through unencrypted page\n"); "Passing through unencrypted page\n");
rc = ecryptfs_do_readpage(file, page, page->index); rc = ecryptfs_do_readpage(file, page, page->index);
...@@ -657,10 +657,10 @@ static int ecryptfs_commit_write(struct file *file, struct page *page, ...@@ -657,10 +657,10 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
mutex_lock(&lower_inode->i_mutex); mutex_lock(&lower_inode->i_mutex);
crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode) crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
->crypt_stat; ->crypt_stat;
if (ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) { if (crypt_stat->flags & ECRYPTFS_NEW_FILE) {
ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in " ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in "
"crypt_stat at memory location [%p]\n", crypt_stat); "crypt_stat at memory location [%p]\n", crypt_stat);
ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE); crypt_stat->flags &= ~(ECRYPTFS_NEW_FILE);
} else } else
ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册