提交 157f1071 编写于 作者: T Tyler Hicks

eCryptfs: Fix metadata in xattr feature regression

Fixes regression in 8faece5f

When using the ecryptfs_xattr_metadata mount option, eCryptfs stores the
metadata (normally stored at the front of the file) in the user.ecryptfs
xattr.  This causes ecryptfs_crypt_stat.num_header_bytes_at_front to be
0, since there is no header data at the front of the file.  This results
in too much memory being requested and ENOMEM being returned from
ecryptfs_write_metadata().

This patch fixes the problem by using the num_header_bytes_at_front
variable for specifying the max size of the metadata, despite whether it
is stored in the header or xattr.
Reviewed-by: NEric Sandeen <sandeen@redhat.com>
Signed-off-by: NTyler Hicks <tyhicks@linux.vnet.ibm.com>
上级 220bf991
...@@ -381,8 +381,8 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -381,8 +381,8 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
struct ecryptfs_crypt_stat *crypt_stat) struct ecryptfs_crypt_stat *crypt_stat)
{ {
(*offset) = (crypt_stat->num_header_bytes_at_front (*offset) = ecryptfs_lower_header_size(crypt_stat)
+ (crypt_stat->extent_size * extent_num)); + (crypt_stat->extent_size * extent_num);
} }
/** /**
...@@ -834,7 +834,8 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -834,7 +834,8 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat)
set_extent_mask_and_shift(crypt_stat); set_extent_mask_and_shift(crypt_stat);
crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES;
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
crypt_stat->num_header_bytes_at_front = 0; crypt_stat->num_header_bytes_at_front =
ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
else { else {
if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE) if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)
crypt_stat->num_header_bytes_at_front = crypt_stat->num_header_bytes_at_front =
......
...@@ -464,6 +464,14 @@ struct ecryptfs_daemon { ...@@ -464,6 +464,14 @@ struct ecryptfs_daemon {
extern struct mutex ecryptfs_daemon_hash_mux; extern struct mutex ecryptfs_daemon_hash_mux;
static inline size_t
ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
{
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
return 0;
return crypt_stat->num_header_bytes_at_front;
}
static inline struct ecryptfs_file_info * static inline struct ecryptfs_file_info *
ecryptfs_file_to_private(struct file *file) ecryptfs_file_to_private(struct file *file)
{ {
......
...@@ -768,7 +768,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, ...@@ -768,7 +768,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
{ {
loff_t lower_size; loff_t lower_size;
lower_size = crypt_stat->num_header_bytes_at_front; lower_size = ecryptfs_lower_header_size(crypt_stat);
if (upper_size != 0) { if (upper_size != 0) {
loff_t num_extents; loff_t num_extents;
......
...@@ -97,19 +97,6 @@ static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc) ...@@ -97,19 +97,6 @@ static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
* (big-endian) * (big-endian)
* Octet 26: Begin RFC 2440 authentication token packet set * Octet 26: Begin RFC 2440 authentication token packet set
*/ */
static void set_header_info(char *page_virt,
struct ecryptfs_crypt_stat *crypt_stat)
{
size_t written;
size_t save_num_header_bytes_at_front =
crypt_stat->num_header_bytes_at_front;
crypt_stat->num_header_bytes_at_front =
ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written);
crypt_stat->num_header_bytes_at_front =
save_num_header_bytes_at_front;
}
/** /**
* ecryptfs_copy_up_encrypted_with_header * ecryptfs_copy_up_encrypted_with_header
...@@ -146,9 +133,13 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, ...@@ -146,9 +133,13 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
memset(page_virt, 0, PAGE_CACHE_SIZE); memset(page_virt, 0, PAGE_CACHE_SIZE);
/* TODO: Support more than one header extent */ /* TODO: Support more than one header extent */
if (view_extent_num == 0) { if (view_extent_num == 0) {
size_t written;
rc = ecryptfs_read_xattr_region( rc = ecryptfs_read_xattr_region(
page_virt, page->mapping->host); page_virt, page->mapping->host);
set_header_info(page_virt, crypt_stat); ecryptfs_write_header_metadata(page_virt + 20,
crypt_stat,
&written);
} }
kunmap_atomic(page_virt, KM_USER0); kunmap_atomic(page_virt, KM_USER0);
flush_dcache_page(page); flush_dcache_page(page);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册