Skip to content

Commit 45eaab7

Browse files
Michael HalcrowLinus Torvalds
authored andcommitted
eCryptfs: remove header_extent_size
There is no point to keeping a separate header_extent_size and an extent_size. The total size of the header can always be represented as some multiple of the regular data extent size. [randy.dunlap@oracle.com: ecryptfs: fix printk format warning] Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com> Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e9f6a99 commit 45eaab7

4 files changed

Lines changed: 52 additions & 36 deletions

File tree

‎fs/ecryptfs/crypto.c‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ ecryptfs_extent_to_lwr_pg_idx_and_offset(unsigned long *lower_page_idx,
366366
int extents_per_page;
367367

368368
bytes_occupied_by_headers_at_front =
369-
( crypt_stat->header_extent_size
370-
* crypt_stat->num_header_extents_at_front );
369+
(crypt_stat->extent_size
370+
* crypt_stat->num_header_extents_at_front);
371371
extents_occupied_by_headers_at_front =
372372
( bytes_occupied_by_headers_at_front
373373
/ crypt_stat->extent_size );
@@ -376,8 +376,8 @@ ecryptfs_extent_to_lwr_pg_idx_and_offset(unsigned long *lower_page_idx,
376376
(*lower_page_idx) = lower_extent_num / extents_per_page;
377377
extent_offset = lower_extent_num % extents_per_page;
378378
(*byte_offset) = extent_offset * crypt_stat->extent_size;
379-
ecryptfs_printk(KERN_DEBUG, " * crypt_stat->header_extent_size = "
380-
"[%d]\n", crypt_stat->header_extent_size);
379+
ecryptfs_printk(KERN_DEBUG, " * crypt_stat->extent_size = "
380+
"[%d]\n", crypt_stat->extent_size);
381381
ecryptfs_printk(KERN_DEBUG, " * crypt_stat->"
382382
"num_header_extents_at_front = [%d]\n",
383383
crypt_stat->num_header_extents_at_front);
@@ -899,15 +899,17 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat)
899899
crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE;
900900
set_extent_mask_and_shift(crypt_stat);
901901
crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES;
902-
if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE) {
903-
crypt_stat->header_extent_size =
904-
ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE;
905-
} else
906-
crypt_stat->header_extent_size = PAGE_CACHE_SIZE;
907902
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
908903
crypt_stat->num_header_extents_at_front = 0;
909-
else
910-
crypt_stat->num_header_extents_at_front = 1;
904+
else {
905+
if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)
906+
crypt_stat->num_header_extents_at_front =
907+
(ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE
908+
/ crypt_stat->extent_size);
909+
else
910+
crypt_stat->num_header_extents_at_front =
911+
(PAGE_CACHE_SIZE / crypt_stat->extent_size);
912+
}
911913
}
912914

913915
/**
@@ -1319,7 +1321,7 @@ ecryptfs_write_header_metadata(char *virt,
13191321
u32 header_extent_size;
13201322
u16 num_header_extents_at_front;
13211323

1322-
header_extent_size = (u32)crypt_stat->header_extent_size;
1324+
header_extent_size = (u32)crypt_stat->extent_size;
13231325
num_header_extents_at_front =
13241326
(u16)crypt_stat->num_header_extents_at_front;
13251327
header_extent_size = cpu_to_be32(header_extent_size);
@@ -1415,7 +1417,7 @@ ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat,
14151417
set_fs(oldfs);
14161418
goto out;
14171419
}
1418-
header_pages = ((crypt_stat->header_extent_size
1420+
header_pages = ((crypt_stat->extent_size
14191421
* crypt_stat->num_header_extents_at_front)
14201422
/ PAGE_CACHE_SIZE);
14211423
memset(page_virt, 0, PAGE_CACHE_SIZE);
@@ -1532,17 +1534,16 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
15321534
virt += 4;
15331535
memcpy(&num_header_extents_at_front, virt, 2);
15341536
num_header_extents_at_front = be16_to_cpu(num_header_extents_at_front);
1535-
crypt_stat->header_extent_size = (int)header_extent_size;
15361537
crypt_stat->num_header_extents_at_front =
15371538
(int)num_header_extents_at_front;
1538-
(*bytes_read) = 6;
1539+
(*bytes_read) = (sizeof(u32) + sizeof(u16));
15391540
if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE)
1540-
&& ((crypt_stat->header_extent_size
1541+
&& ((crypt_stat->extent_size
15411542
* crypt_stat->num_header_extents_at_front)
15421543
< ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) {
15431544
rc = -EINVAL;
1544-
ecryptfs_printk(KERN_WARNING, "Invalid header extent size: "
1545-
"[%d]\n", crypt_stat->header_extent_size);
1545+
printk(KERN_WARNING "Invalid number of header extents: [%zd]\n",
1546+
crypt_stat->num_header_extents_at_front);
15461547
}
15471548
return rc;
15481549
}
@@ -1557,8 +1558,7 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat,
15571558
*/
15581559
static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat)
15591560
{
1560-
crypt_stat->header_extent_size = 4096;
1561-
crypt_stat->num_header_extents_at_front = 1;
1561+
crypt_stat->num_header_extents_at_front = 2;
15621562
}
15631563

15641564
/**

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/* Version verification for shared data structures w/ userspace */
3939
#define ECRYPTFS_VERSION_MAJOR 0x00
4040
#define ECRYPTFS_VERSION_MINOR 0x04
41-
#define ECRYPTFS_SUPPORTED_FILE_VERSION 0x02
41+
#define ECRYPTFS_SUPPORTED_FILE_VERSION 0x03
4242
/* These flags indicate which features are supported by the kernel
4343
* module; userspace tools such as the mount helper read
4444
* ECRYPTFS_VERSIONING_MASK from a sysfs handle in order to determine
@@ -67,8 +67,7 @@
6767
#define ECRYPTFS_MAX_KEY_BYTES 64
6868
#define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512
6969
#define ECRYPTFS_DEFAULT_IV_BYTES 16
70-
#define ECRYPTFS_FILE_VERSION 0x02
71-
#define ECRYPTFS_DEFAULT_HEADER_EXTENT_SIZE 8192
70+
#define ECRYPTFS_FILE_VERSION 0x03
7271
#define ECRYPTFS_DEFAULT_EXTENT_SIZE 4096
7372
#define ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE 8192
7473
#define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32
@@ -201,7 +200,7 @@ ecryptfs_get_key_payload_data(struct key *key)
201200
#define ECRYPTFS_SALT_BYTES 2
202201
#define MAGIC_ECRYPTFS_MARKER 0x3c81b7f5
203202
#define MAGIC_ECRYPTFS_MARKER_SIZE_BYTES 8 /* 4*2 */
204-
#define ECRYPTFS_FILE_SIZE_BYTES 8
203+
#define ECRYPTFS_FILE_SIZE_BYTES (sizeof(u64))
205204
#define ECRYPTFS_DEFAULT_CIPHER "aes"
206205
#define ECRYPTFS_DEFAULT_KEY_BYTES 16
207206
#define ECRYPTFS_DEFAULT_HASH "md5"
@@ -238,7 +237,6 @@ struct ecryptfs_crypt_stat {
238237
u32 flags;
239238
unsigned int file_version;
240239
size_t iv_bytes;
241-
size_t header_extent_size;
242240
size_t num_header_extents_at_front;
243241
size_t extent_size; /* Data extent size; default is 4096 */
244242
size_t key_size;
@@ -273,6 +271,17 @@ struct ecryptfs_dentry_info {
273271
};
274272

275273
/**
274+
* ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
275+
* @flags: Status flags
276+
* @mount_crypt_stat_list: These auth_toks hang off the mount-wide
277+
* cryptographic context. Every time a new
278+
* inode comes into existence, eCryptfs copies
279+
* the auth_toks on that list to the set of
280+
* auth_toks on the inode's crypt_stat
281+
* @global_auth_tok_key: The key from the user's keyring for the sig
282+
* @global_auth_tok: The key contents
283+
* @sig: The key identifier
284+
*
276285
* ecryptfs_global_auth_tok structs refer to authentication token keys
277286
* in the user keyring that apply to newly created files. A list of
278287
* these objects hangs off of the mount_crypt_stat struct for any
@@ -283,15 +292,21 @@ struct ecryptfs_dentry_info {
283292
struct ecryptfs_global_auth_tok {
284293
#define ECRYPTFS_AUTH_TOK_INVALID 0x00000001
285294
u32 flags;
286-
struct list_head mount_crypt_stat_list; /* Default auth_tok list for
287-
* the mount_crypt_stat */
288-
struct key *global_auth_tok_key; /* The key from the user's keyring for
289-
* the sig */
290-
struct ecryptfs_auth_tok *global_auth_tok; /* The key contents */
291-
unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1]; /* The key identifier */
295+
struct list_head mount_crypt_stat_list;
296+
struct key *global_auth_tok_key;
297+
struct ecryptfs_auth_tok *global_auth_tok;
298+
unsigned char sig[ECRYPTFS_SIG_SIZE_HEX + 1];
292299
};
293300

294301
/**
302+
* ecryptfs_key_tfm - Persistent key tfm
303+
* @key_tfm: crypto API handle to the key
304+
* @key_size: Key size in bytes
305+
* @key_tfm_mutex: Mutex to ensure only one operation in eCryptfs is
306+
* using the persistent TFM at any point in time
307+
* @key_tfm_list: Handle to hang this off the module-wide TFM list
308+
* @cipher_name: String name for the cipher for this TFM
309+
*
295310
* Typically, eCryptfs will use the same ciphers repeatedly throughout
296311
* the course of its operations. In order to avoid unnecessarily
297312
* destroying and initializing the same cipher repeatedly, eCryptfs
@@ -301,7 +316,7 @@ struct ecryptfs_key_tfm {
301316
struct crypto_blkcipher *key_tfm;
302317
size_t key_size;
303318
struct mutex key_tfm_mutex;
304-
struct list_head key_tfm_list; /* The module's tfm list */
319+
struct list_head key_tfm_list;
305320
unsigned char cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1];
306321
};
307322

‎fs/ecryptfs/inode.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
392392
dentry->d_sb)->mount_crypt_stat;
393393
if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) {
394394
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
395-
file_size = (crypt_stat->header_extent_size
395+
file_size = ((crypt_stat->extent_size
396+
* crypt_stat->num_header_extents_at_front)
396397
+ i_size_read(lower_dentry->d_inode));
397398
else
398399
file_size = i_size_read(lower_dentry->d_inode);
@@ -722,8 +723,8 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
722723
{
723724
loff_t lower_size;
724725

725-
lower_size = ( crypt_stat->header_extent_size
726-
* crypt_stat->num_header_extents_at_front );
726+
lower_size = (crypt_stat->extent_size
727+
* crypt_stat->num_header_extents_at_front);
727728
if (upper_size != 0) {
728729
loff_t num_extents;
729730

‎fs/ecryptfs/mmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int ecryptfs_readpage(struct file *file, struct page *page)
301301
} else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
302302
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
303303
int num_pages_in_header_region =
304-
(crypt_stat->header_extent_size
304+
(crypt_stat->extent_size
305305
/ PAGE_CACHE_SIZE);
306306

307307
if (page->index < num_pages_in_header_region) {

0 commit comments

Comments
 (0)