Skip to content

Commit f4e60e6

Browse files
author
Tyler Hicks
committed
eCryptfs: Strip metadata in xattr flag in encrypted view
The ecryptfs_encrypted_view mount option provides a unified way of viewing encrypted eCryptfs files. If the metadata is stored in a xattr, the metadata is moved to the file header when the file is read inside the eCryptfs mount. Because of this, we should strip the ECRYPTFS_METADATA_IN_XATTR flag from the header's flag section. This allows eCryptfs to treat the file as an eCryptfs file with a header at the front. Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
1 parent 1984c23 commit f4e60e6

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎fs/ecryptfs/crypto.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,9 @@ static void write_ecryptfs_marker(char *page_virt, size_t *written)
11071107
(*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES;
11081108
}
11091109

1110-
static void
1111-
write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat,
1112-
size_t *written)
1110+
void ecryptfs_write_crypt_stat_flags(char *page_virt,
1111+
struct ecryptfs_crypt_stat *crypt_stat,
1112+
size_t *written)
11131113
{
11141114
u32 flags = 0;
11151115
int i;
@@ -1290,7 +1290,8 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t max,
12901290
offset = ECRYPTFS_FILE_SIZE_BYTES;
12911291
write_ecryptfs_marker((page_virt + offset), &written);
12921292
offset += written;
1293-
write_ecryptfs_flags((page_virt + offset), crypt_stat, &written);
1293+
ecryptfs_write_crypt_stat_flags((page_virt + offset), crypt_stat,
1294+
&written);
12941295
offset += written;
12951296
ecryptfs_write_header_metadata((page_virt + offset), crypt_stat,
12961297
&written);

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ int ecryptfs_decrypt_page(struct page *page);
659659
int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry);
660660
int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry);
661661
int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry);
662+
void ecryptfs_write_crypt_stat_flags(char *page_virt,
663+
struct ecryptfs_crypt_stat *crypt_stat,
664+
size_t *written);
662665
int ecryptfs_read_and_validate_header_region(char *data,
663666
struct inode *ecryptfs_inode);
664667
int ecryptfs_read_and_validate_xattr_region(char *page_virt,

‎fs/ecryptfs/mmap.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
8282
return rc;
8383
}
8484

85+
static void strip_xattr_flag(char *page_virt,
86+
struct ecryptfs_crypt_stat *crypt_stat)
87+
{
88+
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
89+
size_t written;
90+
91+
crypt_stat->flags &= ~ECRYPTFS_METADATA_IN_XATTR;
92+
ecryptfs_write_crypt_stat_flags(page_virt, crypt_stat,
93+
&written);
94+
crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
95+
}
96+
}
97+
8598
/**
8699
* Header Extent:
87100
* Octets 0-7: Unencrypted file size (big-endian)
@@ -136,6 +149,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
136149

137150
rc = ecryptfs_read_xattr_region(
138151
page_virt, page->mapping->host);
152+
strip_xattr_flag(page_virt + 16, crypt_stat);
139153
ecryptfs_write_header_metadata(page_virt + 20,
140154
crypt_stat,
141155
&written);

0 commit comments

Comments
 (0)