diff options
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/Makefile | 2 | ||||
-rw-r--r-- | fs/ecryptfs/crypto.c | 33 | ||||
-rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 102 | ||||
-rw-r--r-- | fs/ecryptfs/file.c | 2 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 6 | ||||
-rw-r--r-- | fs/ecryptfs/keystore.c | 89 | ||||
-rw-r--r-- | fs/ecryptfs/main.c | 2 | ||||
-rw-r--r-- | fs/ecryptfs/messaging.c | 524 | ||||
-rw-r--r-- | fs/ecryptfs/miscdev.c | 598 | ||||
-rw-r--r-- | fs/ecryptfs/mmap.c | 18 | ||||
-rw-r--r-- | fs/ecryptfs/netlink.c | 33 | ||||
-rw-r--r-- | fs/ecryptfs/read_write.c | 16 |
12 files changed, 1144 insertions, 281 deletions
diff --git a/fs/ecryptfs/Makefile b/fs/ecryptfs/Makefile index 768857015516..1e34a7fd4884 100644 --- a/fs/ecryptfs/Makefile +++ b/fs/ecryptfs/Makefile | |||
@@ -4,4 +4,4 @@ | |||
4 | 4 | ||
5 | obj-$(CONFIG_ECRYPT_FS) += ecryptfs.o | 5 | obj-$(CONFIG_ECRYPT_FS) += ecryptfs.o |
6 | 6 | ||
7 | ecryptfs-objs := dentry.o file.o inode.o main.o super.o mmap.o read_write.o crypto.o keystore.o messaging.o netlink.o debug.o | 7 | ecryptfs-objs := dentry.o file.o inode.o main.o super.o mmap.o read_write.o crypto.o keystore.o messaging.o netlink.o miscdev.o debug.o |
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index a066e109ad9c..cd62d75b2cc0 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -119,21 +119,21 @@ static int ecryptfs_calculate_md5(char *dst, | |||
119 | if (rc) { | 119 | if (rc) { |
120 | printk(KERN_ERR | 120 | printk(KERN_ERR |
121 | "%s: Error initializing crypto hash; rc = [%d]\n", | 121 | "%s: Error initializing crypto hash; rc = [%d]\n", |
122 | __FUNCTION__, rc); | 122 | __func__, rc); |
123 | goto out; | 123 | goto out; |
124 | } | 124 | } |
125 | rc = crypto_hash_update(&desc, &sg, len); | 125 | rc = crypto_hash_update(&desc, &sg, len); |
126 | if (rc) { | 126 | if (rc) { |
127 | printk(KERN_ERR | 127 | printk(KERN_ERR |
128 | "%s: Error updating crypto hash; rc = [%d]\n", | 128 | "%s: Error updating crypto hash; rc = [%d]\n", |
129 | __FUNCTION__, rc); | 129 | __func__, rc); |
130 | goto out; | 130 | goto out; |
131 | } | 131 | } |
132 | rc = crypto_hash_final(&desc, dst); | 132 | rc = crypto_hash_final(&desc, dst); |
133 | if (rc) { | 133 | if (rc) { |
134 | printk(KERN_ERR | 134 | printk(KERN_ERR |
135 | "%s: Error finalizing crypto hash; rc = [%d]\n", | 135 | "%s: Error finalizing crypto hash; rc = [%d]\n", |
136 | __FUNCTION__, rc); | 136 | __func__, rc); |
137 | goto out; | 137 | goto out; |
138 | } | 138 | } |
139 | out: | 139 | out: |
@@ -437,7 +437,7 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
437 | if (rc < 0) { | 437 | if (rc < 0) { |
438 | printk(KERN_ERR "%s: Error attempting to encrypt page with " | 438 | printk(KERN_ERR "%s: Error attempting to encrypt page with " |
439 | "page->index = [%ld], extent_offset = [%ld]; " | 439 | "page->index = [%ld], extent_offset = [%ld]; " |
440 | "rc = [%d]\n", __FUNCTION__, page->index, extent_offset, | 440 | "rc = [%d]\n", __func__, page->index, extent_offset, |
441 | rc); | 441 | rc); |
442 | goto out; | 442 | goto out; |
443 | } | 443 | } |
@@ -487,7 +487,7 @@ int ecryptfs_encrypt_page(struct page *page) | |||
487 | 0, PAGE_CACHE_SIZE); | 487 | 0, PAGE_CACHE_SIZE); |
488 | if (rc) | 488 | if (rc) |
489 | printk(KERN_ERR "%s: Error attempting to copy " | 489 | printk(KERN_ERR "%s: Error attempting to copy " |
490 | "page at index [%ld]\n", __FUNCTION__, | 490 | "page at index [%ld]\n", __func__, |
491 | page->index); | 491 | page->index); |
492 | goto out; | 492 | goto out; |
493 | } | 493 | } |
@@ -508,7 +508,7 @@ int ecryptfs_encrypt_page(struct page *page) | |||
508 | extent_offset); | 508 | extent_offset); |
509 | if (rc) { | 509 | if (rc) { |
510 | printk(KERN_ERR "%s: Error encrypting extent; " | 510 | printk(KERN_ERR "%s: Error encrypting extent; " |
511 | "rc = [%d]\n", __FUNCTION__, rc); | 511 | "rc = [%d]\n", __func__, rc); |
512 | goto out; | 512 | goto out; |
513 | } | 513 | } |
514 | ecryptfs_lower_offset_for_extent( | 514 | ecryptfs_lower_offset_for_extent( |
@@ -569,7 +569,7 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
569 | if (rc < 0) { | 569 | if (rc < 0) { |
570 | printk(KERN_ERR "%s: Error attempting to decrypt to page with " | 570 | printk(KERN_ERR "%s: Error attempting to decrypt to page with " |
571 | "page->index = [%ld], extent_offset = [%ld]; " | 571 | "page->index = [%ld], extent_offset = [%ld]; " |
572 | "rc = [%d]\n", __FUNCTION__, page->index, extent_offset, | 572 | "rc = [%d]\n", __func__, page->index, extent_offset, |
573 | rc); | 573 | rc); |
574 | goto out; | 574 | goto out; |
575 | } | 575 | } |
@@ -622,7 +622,7 @@ int ecryptfs_decrypt_page(struct page *page) | |||
622 | ecryptfs_inode); | 622 | ecryptfs_inode); |
623 | if (rc) | 623 | if (rc) |
624 | printk(KERN_ERR "%s: Error attempting to copy " | 624 | printk(KERN_ERR "%s: Error attempting to copy " |
625 | "page at index [%ld]\n", __FUNCTION__, | 625 | "page at index [%ld]\n", __func__, |
626 | page->index); | 626 | page->index); |
627 | goto out; | 627 | goto out; |
628 | } | 628 | } |
@@ -656,7 +656,7 @@ int ecryptfs_decrypt_page(struct page *page) | |||
656 | extent_offset); | 656 | extent_offset); |
657 | if (rc) { | 657 | if (rc) { |
658 | printk(KERN_ERR "%s: Error encrypting extent; " | 658 | printk(KERN_ERR "%s: Error encrypting extent; " |
659 | "rc = [%d]\n", __FUNCTION__, rc); | 659 | "rc = [%d]\n", __func__, rc); |
660 | goto out; | 660 | goto out; |
661 | } | 661 | } |
662 | } | 662 | } |
@@ -1215,7 +1215,7 @@ int ecryptfs_read_and_validate_header_region(char *data, | |||
1215 | ecryptfs_inode); | 1215 | ecryptfs_inode); |
1216 | if (rc) { | 1216 | if (rc) { |
1217 | printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", | 1217 | printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", |
1218 | __FUNCTION__, rc); | 1218 | __func__, rc); |
1219 | goto out; | 1219 | goto out; |
1220 | } | 1220 | } |
1221 | if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { | 1221 | if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { |
@@ -1246,7 +1246,6 @@ ecryptfs_write_header_metadata(char *virt, | |||
1246 | (*written) = 6; | 1246 | (*written) = 6; |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | struct kmem_cache *ecryptfs_header_cache_0; | ||
1250 | struct kmem_cache *ecryptfs_header_cache_1; | 1249 | struct kmem_cache *ecryptfs_header_cache_1; |
1251 | struct kmem_cache *ecryptfs_header_cache_2; | 1250 | struct kmem_cache *ecryptfs_header_cache_2; |
1252 | 1251 | ||
@@ -1320,7 +1319,7 @@ ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat, | |||
1320 | 0, crypt_stat->num_header_bytes_at_front); | 1319 | 0, crypt_stat->num_header_bytes_at_front); |
1321 | if (rc) | 1320 | if (rc) |
1322 | printk(KERN_ERR "%s: Error attempting to write header " | 1321 | printk(KERN_ERR "%s: Error attempting to write header " |
1323 | "information to lower file; rc = [%d]\n", __FUNCTION__, | 1322 | "information to lower file; rc = [%d]\n", __func__, |
1324 | rc); | 1323 | rc); |
1325 | return rc; | 1324 | return rc; |
1326 | } | 1325 | } |
@@ -1365,14 +1364,14 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | |||
1365 | } | 1364 | } |
1366 | } else { | 1365 | } else { |
1367 | printk(KERN_WARNING "%s: Encrypted flag not set\n", | 1366 | printk(KERN_WARNING "%s: Encrypted flag not set\n", |
1368 | __FUNCTION__); | 1367 | __func__); |
1369 | rc = -EINVAL; | 1368 | rc = -EINVAL; |
1370 | goto out; | 1369 | goto out; |
1371 | } | 1370 | } |
1372 | /* Released in this function */ | 1371 | /* Released in this function */ |
1373 | virt = kzalloc(crypt_stat->num_header_bytes_at_front, GFP_KERNEL); | 1372 | virt = kzalloc(crypt_stat->num_header_bytes_at_front, GFP_KERNEL); |
1374 | if (!virt) { | 1373 | if (!virt) { |
1375 | printk(KERN_ERR "%s: Out of memory\n", __FUNCTION__); | 1374 | printk(KERN_ERR "%s: Out of memory\n", __func__); |
1376 | rc = -ENOMEM; | 1375 | rc = -ENOMEM; |
1377 | goto out; | 1376 | goto out; |
1378 | } | 1377 | } |
@@ -1380,7 +1379,7 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | |||
1380 | ecryptfs_dentry); | 1379 | ecryptfs_dentry); |
1381 | if (unlikely(rc)) { | 1380 | if (unlikely(rc)) { |
1382 | printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n", | 1381 | printk(KERN_ERR "%s: Error whilst writing headers; rc = [%d]\n", |
1383 | __FUNCTION__, rc); | 1382 | __func__, rc); |
1384 | goto out_free; | 1383 | goto out_free; |
1385 | } | 1384 | } |
1386 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) | 1385 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) |
@@ -1391,7 +1390,7 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | |||
1391 | ecryptfs_dentry, virt); | 1390 | ecryptfs_dentry, virt); |
1392 | if (rc) { | 1391 | if (rc) { |
1393 | printk(KERN_ERR "%s: Error writing metadata out to lower file; " | 1392 | printk(KERN_ERR "%s: Error writing metadata out to lower file; " |
1394 | "rc = [%d]\n", __FUNCTION__, rc); | 1393 | "rc = [%d]\n", __func__, rc); |
1395 | goto out_free; | 1394 | goto out_free; |
1396 | } | 1395 | } |
1397 | out_free: | 1396 | out_free: |
@@ -1585,7 +1584,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
1585 | if (!page_virt) { | 1584 | if (!page_virt) { |
1586 | rc = -ENOMEM; | 1585 | rc = -ENOMEM; |
1587 | printk(KERN_ERR "%s: Unable to allocate page_virt\n", | 1586 | printk(KERN_ERR "%s: Unable to allocate page_virt\n", |
1588 | __FUNCTION__); | 1587 | __func__); |
1589 | goto out; | 1588 | goto out; |
1590 | } | 1589 | } |
1591 | rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, | 1590 | rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, |
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 5007f788da01..951ee33a022d 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 1997-2003 Erez Zadok | 5 | * Copyright (C) 1997-2003 Erez Zadok |
6 | * Copyright (C) 2001-2003 Stony Brook University | 6 | * Copyright (C) 2001-2003 Stony Brook University |
7 | * Copyright (C) 2004-2007 International Business Machines Corp. | 7 | * Copyright (C) 2004-2008 International Business Machines Corp. |
8 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> | 8 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> |
9 | * Trevor S. Highland <trevor.highland@gmail.com> | 9 | * Trevor S. Highland <trevor.highland@gmail.com> |
10 | * Tyler Hicks <tyhicks@ou.edu> | 10 | * Tyler Hicks <tyhicks@ou.edu> |
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/namei.h> | 34 | #include <linux/namei.h> |
35 | #include <linux/scatterlist.h> | 35 | #include <linux/scatterlist.h> |
36 | #include <linux/hash.h> | 36 | #include <linux/hash.h> |
37 | #include <linux/nsproxy.h> | ||
37 | 38 | ||
38 | /* Version verification for shared data structures w/ userspace */ | 39 | /* Version verification for shared data structures w/ userspace */ |
39 | #define ECRYPTFS_VERSION_MAJOR 0x00 | 40 | #define ECRYPTFS_VERSION_MAJOR 0x00 |
@@ -49,11 +50,13 @@ | |||
49 | #define ECRYPTFS_VERSIONING_POLICY 0x00000008 | 50 | #define ECRYPTFS_VERSIONING_POLICY 0x00000008 |
50 | #define ECRYPTFS_VERSIONING_XATTR 0x00000010 | 51 | #define ECRYPTFS_VERSIONING_XATTR 0x00000010 |
51 | #define ECRYPTFS_VERSIONING_MULTKEY 0x00000020 | 52 | #define ECRYPTFS_VERSIONING_MULTKEY 0x00000020 |
53 | #define ECRYPTFS_VERSIONING_DEVMISC 0x00000040 | ||
52 | #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \ | 54 | #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \ |
53 | | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \ | 55 | | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \ |
54 | | ECRYPTFS_VERSIONING_PUBKEY \ | 56 | | ECRYPTFS_VERSIONING_PUBKEY \ |
55 | | ECRYPTFS_VERSIONING_XATTR \ | 57 | | ECRYPTFS_VERSIONING_XATTR \ |
56 | | ECRYPTFS_VERSIONING_MULTKEY) | 58 | | ECRYPTFS_VERSIONING_MULTKEY \ |
59 | | ECRYPTFS_VERSIONING_DEVMISC) | ||
57 | #define ECRYPTFS_MAX_PASSWORD_LENGTH 64 | 60 | #define ECRYPTFS_MAX_PASSWORD_LENGTH 64 |
58 | #define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH | 61 | #define ECRYPTFS_MAX_PASSPHRASE_BYTES ECRYPTFS_MAX_PASSWORD_LENGTH |
59 | #define ECRYPTFS_SALT_SIZE 8 | 62 | #define ECRYPTFS_SALT_SIZE 8 |
@@ -73,17 +76,14 @@ | |||
73 | #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32 | 76 | #define ECRYPTFS_DEFAULT_MSG_CTX_ELEMS 32 |
74 | #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ | 77 | #define ECRYPTFS_DEFAULT_SEND_TIMEOUT HZ |
75 | #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3) | 78 | #define ECRYPTFS_MAX_MSG_CTX_TTL (HZ*3) |
76 | #define ECRYPTFS_NLMSG_HELO 100 | ||
77 | #define ECRYPTFS_NLMSG_QUIT 101 | ||
78 | #define ECRYPTFS_NLMSG_REQUEST 102 | ||
79 | #define ECRYPTFS_NLMSG_RESPONSE 103 | ||
80 | #define ECRYPTFS_MAX_PKI_NAME_BYTES 16 | 79 | #define ECRYPTFS_MAX_PKI_NAME_BYTES 16 |
81 | #define ECRYPTFS_DEFAULT_NUM_USERS 4 | 80 | #define ECRYPTFS_DEFAULT_NUM_USERS 4 |
82 | #define ECRYPTFS_MAX_NUM_USERS 32768 | 81 | #define ECRYPTFS_MAX_NUM_USERS 32768 |
83 | #define ECRYPTFS_TRANSPORT_NETLINK 0 | 82 | #define ECRYPTFS_TRANSPORT_NETLINK 0 |
84 | #define ECRYPTFS_TRANSPORT_CONNECTOR 1 | 83 | #define ECRYPTFS_TRANSPORT_CONNECTOR 1 |
85 | #define ECRYPTFS_TRANSPORT_RELAYFS 2 | 84 | #define ECRYPTFS_TRANSPORT_RELAYFS 2 |
86 | #define ECRYPTFS_DEFAULT_TRANSPORT ECRYPTFS_TRANSPORT_NETLINK | 85 | #define ECRYPTFS_TRANSPORT_MISCDEV 3 |
86 | #define ECRYPTFS_DEFAULT_TRANSPORT ECRYPTFS_TRANSPORT_MISCDEV | ||
87 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" | 87 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" |
88 | 88 | ||
89 | #define RFC2440_CIPHER_DES3_EDE 0x02 | 89 | #define RFC2440_CIPHER_DES3_EDE 0x02 |
@@ -366,32 +366,63 @@ struct ecryptfs_auth_tok_list_item { | |||
366 | }; | 366 | }; |
367 | 367 | ||
368 | struct ecryptfs_message { | 368 | struct ecryptfs_message { |
369 | /* Can never be greater than ecryptfs_message_buf_len */ | ||
370 | /* Used to find the parent msg_ctx */ | ||
371 | /* Inherits from msg_ctx->index */ | ||
369 | u32 index; | 372 | u32 index; |
370 | u32 data_len; | 373 | u32 data_len; |
371 | u8 data[]; | 374 | u8 data[]; |
372 | }; | 375 | }; |
373 | 376 | ||
374 | struct ecryptfs_msg_ctx { | 377 | struct ecryptfs_msg_ctx { |
375 | #define ECRYPTFS_MSG_CTX_STATE_FREE 0x0001 | 378 | #define ECRYPTFS_MSG_CTX_STATE_FREE 0x01 |
376 | #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x0002 | 379 | #define ECRYPTFS_MSG_CTX_STATE_PENDING 0x02 |
377 | #define ECRYPTFS_MSG_CTX_STATE_DONE 0x0003 | 380 | #define ECRYPTFS_MSG_CTX_STATE_DONE 0x03 |
378 | u32 state; | 381 | #define ECRYPTFS_MSG_CTX_STATE_NO_REPLY 0x04 |
379 | unsigned int index; | 382 | u8 state; |
380 | unsigned int counter; | 383 | #define ECRYPTFS_MSG_HELO 100 |
384 | #define ECRYPTFS_MSG_QUIT 101 | ||
385 | #define ECRYPTFS_MSG_REQUEST 102 | ||
386 | #define ECRYPTFS_MSG_RESPONSE 103 | ||
387 | u8 type; | ||
388 | u32 index; | ||
389 | /* Counter converts to a sequence number. Each message sent | ||
390 | * out for which we expect a response has an associated | ||
391 | * sequence number. The response must have the same sequence | ||
392 | * number as the counter for the msg_stc for the message to be | ||
393 | * valid. */ | ||
394 | u32 counter; | ||
395 | size_t msg_size; | ||
381 | struct ecryptfs_message *msg; | 396 | struct ecryptfs_message *msg; |
382 | struct task_struct *task; | 397 | struct task_struct *task; |
383 | struct list_head node; | 398 | struct list_head node; |
399 | struct list_head daemon_out_list; | ||
384 | struct mutex mux; | 400 | struct mutex mux; |
385 | }; | 401 | }; |
386 | 402 | ||
387 | extern unsigned int ecryptfs_transport; | 403 | extern unsigned int ecryptfs_transport; |
388 | 404 | ||
389 | struct ecryptfs_daemon_id { | 405 | struct ecryptfs_daemon; |
390 | pid_t pid; | 406 | |
391 | uid_t uid; | 407 | struct ecryptfs_daemon { |
392 | struct hlist_node id_chain; | 408 | #define ECRYPTFS_DAEMON_IN_READ 0x00000001 |
409 | #define ECRYPTFS_DAEMON_IN_POLL 0x00000002 | ||
410 | #define ECRYPTFS_DAEMON_ZOMBIE 0x00000004 | ||
411 | #define ECRYPTFS_DAEMON_MISCDEV_OPEN 0x00000008 | ||
412 | u32 flags; | ||
413 | u32 num_queued_msg_ctx; | ||
414 | struct pid *pid; | ||
415 | uid_t euid; | ||
416 | struct user_namespace *user_ns; | ||
417 | struct task_struct *task; | ||
418 | struct mutex mux; | ||
419 | struct list_head msg_ctx_out_queue; | ||
420 | wait_queue_head_t wait; | ||
421 | struct hlist_node euid_chain; | ||
393 | }; | 422 | }; |
394 | 423 | ||
424 | extern struct mutex ecryptfs_daemon_hash_mux; | ||
425 | |||
395 | static inline struct ecryptfs_file_info * | 426 | static inline struct ecryptfs_file_info * |
396 | ecryptfs_file_to_private(struct file *file) | 427 | ecryptfs_file_to_private(struct file *file) |
397 | { | 428 | { |
@@ -500,7 +531,7 @@ ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt) | |||
500 | } | 531 | } |
501 | 532 | ||
502 | #define ecryptfs_printk(type, fmt, arg...) \ | 533 | #define ecryptfs_printk(type, fmt, arg...) \ |
503 | __ecryptfs_printk(type "%s: " fmt, __FUNCTION__, ## arg); | 534 | __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); |
504 | void __ecryptfs_printk(const char *fmt, ...); | 535 | void __ecryptfs_printk(const char *fmt, ...); |
505 | 536 | ||
506 | extern const struct file_operations ecryptfs_main_fops; | 537 | extern const struct file_operations ecryptfs_main_fops; |
@@ -581,10 +612,13 @@ int | |||
581 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, | 612 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
582 | size_t size, int flags); | 613 | size_t size, int flags); |
583 | int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode); | 614 | int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode); |
584 | int ecryptfs_process_helo(unsigned int transport, uid_t uid, pid_t pid); | 615 | int ecryptfs_process_helo(unsigned int transport, uid_t euid, |
585 | int ecryptfs_process_quit(uid_t uid, pid_t pid); | 616 | struct user_namespace *user_ns, struct pid *pid); |
586 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t uid, | 617 | int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns, |
587 | pid_t pid, u32 seq); | 618 | struct pid *pid); |
619 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid, | ||
620 | struct user_namespace *user_ns, struct pid *pid, | ||
621 | u32 seq); | ||
588 | int ecryptfs_send_message(unsigned int transport, char *data, int data_len, | 622 | int ecryptfs_send_message(unsigned int transport, char *data, int data_len, |
589 | struct ecryptfs_msg_ctx **msg_ctx); | 623 | struct ecryptfs_msg_ctx **msg_ctx); |
590 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, | 624 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, |
@@ -593,14 +627,14 @@ int ecryptfs_init_messaging(unsigned int transport); | |||
593 | void ecryptfs_release_messaging(unsigned int transport); | 627 | void ecryptfs_release_messaging(unsigned int transport); |
594 | 628 | ||
595 | int ecryptfs_send_netlink(char *data, int data_len, | 629 | int ecryptfs_send_netlink(char *data, int data_len, |
596 | struct ecryptfs_msg_ctx *msg_ctx, u16 msg_type, | 630 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, |
597 | u16 msg_flags, pid_t daemon_pid); | 631 | u16 msg_flags, struct pid *daemon_pid); |
598 | int ecryptfs_init_netlink(void); | 632 | int ecryptfs_init_netlink(void); |
599 | void ecryptfs_release_netlink(void); | 633 | void ecryptfs_release_netlink(void); |
600 | 634 | ||
601 | int ecryptfs_send_connector(char *data, int data_len, | 635 | int ecryptfs_send_connector(char *data, int data_len, |
602 | struct ecryptfs_msg_ctx *msg_ctx, u16 msg_type, | 636 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, |
603 | u16 msg_flags, pid_t daemon_pid); | 637 | u16 msg_flags, struct pid *daemon_pid); |
604 | int ecryptfs_init_connector(void); | 638 | int ecryptfs_init_connector(void); |
605 | void ecryptfs_release_connector(void); | 639 | void ecryptfs_release_connector(void); |
606 | void | 640 | void |
@@ -642,5 +676,21 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, | |||
642 | size_t offset_in_page, size_t size, | 676 | size_t offset_in_page, size_t size, |
643 | struct inode *ecryptfs_inode); | 677 | struct inode *ecryptfs_inode); |
644 | struct page *ecryptfs_get_locked_page(struct file *file, loff_t index); | 678 | struct page *ecryptfs_get_locked_page(struct file *file, loff_t index); |
679 | int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon); | ||
680 | int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid, | ||
681 | struct user_namespace *user_ns); | ||
682 | int ecryptfs_parse_packet_length(unsigned char *data, size_t *size, | ||
683 | size_t *length_size); | ||
684 | int ecryptfs_write_packet_length(char *dest, size_t size, | ||
685 | size_t *packet_size_length); | ||
686 | int ecryptfs_init_ecryptfs_miscdev(void); | ||
687 | void ecryptfs_destroy_ecryptfs_miscdev(void); | ||
688 | int ecryptfs_send_miscdev(char *data, size_t data_size, | ||
689 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, | ||
690 | u16 msg_flags, struct ecryptfs_daemon *daemon); | ||
691 | void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx); | ||
692 | int | ||
693 | ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid, | ||
694 | struct user_namespace *user_ns, struct pid *pid); | ||
645 | 695 | ||
646 | #endif /* #ifndef ECRYPTFS_KERNEL_H */ | 696 | #endif /* #ifndef ECRYPTFS_KERNEL_H */ |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 2b8f5ed4adea..2258b8f654a6 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -195,7 +195,9 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
195 | file, ecryptfs_inode_to_private(inode)->lower_file); | 195 | file, ecryptfs_inode_to_private(inode)->lower_file); |
196 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { | 196 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { |
197 | ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); | 197 | ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); |
198 | mutex_lock(&crypt_stat->cs_mutex); | ||
198 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); | 199 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); |
200 | mutex_unlock(&crypt_stat->cs_mutex); | ||
199 | rc = 0; | 201 | rc = 0; |
200 | goto out; | 202 | goto out; |
201 | } | 203 | } |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index e23861152101..0a1397335a8e 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -111,7 +111,7 @@ ecryptfs_do_create(struct inode *directory_inode, | |||
111 | 111 | ||
112 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | 112 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); |
113 | lower_dir_dentry = lock_parent(lower_dentry); | 113 | lower_dir_dentry = lock_parent(lower_dentry); |
114 | if (unlikely(IS_ERR(lower_dir_dentry))) { | 114 | if (IS_ERR(lower_dir_dentry)) { |
115 | ecryptfs_printk(KERN_ERR, "Error locking directory of " | 115 | ecryptfs_printk(KERN_ERR, "Error locking directory of " |
116 | "dentry\n"); | 116 | "dentry\n"); |
117 | rc = PTR_ERR(lower_dir_dentry); | 117 | rc = PTR_ERR(lower_dir_dentry); |
@@ -121,7 +121,7 @@ ecryptfs_do_create(struct inode *directory_inode, | |||
121 | ecryptfs_dentry, mode, nd); | 121 | ecryptfs_dentry, mode, nd); |
122 | if (rc) { | 122 | if (rc) { |
123 | printk(KERN_ERR "%s: Failure to create dentry in lower fs; " | 123 | printk(KERN_ERR "%s: Failure to create dentry in lower fs; " |
124 | "rc = [%d]\n", __FUNCTION__, rc); | 124 | "rc = [%d]\n", __func__, rc); |
125 | goto out_lock; | 125 | goto out_lock; |
126 | } | 126 | } |
127 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, | 127 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, |
@@ -908,7 +908,9 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
908 | if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) | 908 | if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
909 | ia->ia_valid &= ~ATTR_MODE; | 909 | ia->ia_valid &= ~ATTR_MODE; |
910 | 910 | ||
911 | mutex_lock(&lower_dentry->d_inode->i_mutex); | ||
911 | rc = notify_change(lower_dentry, ia); | 912 | rc = notify_change(lower_dentry, ia); |
913 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | ||
912 | out: | 914 | out: |
913 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 915 | fsstack_copy_attr_all(inode, lower_inode, NULL); |
914 | return rc; | 916 | return rc; |
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index 682b1b2482c2..e82b457180be 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c | |||
@@ -65,7 +65,7 @@ static int process_request_key_err(long err_code) | |||
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * parse_packet_length | 68 | * ecryptfs_parse_packet_length |
69 | * @data: Pointer to memory containing length at offset | 69 | * @data: Pointer to memory containing length at offset |
70 | * @size: This function writes the decoded size to this memory | 70 | * @size: This function writes the decoded size to this memory |
71 | * address; zero on error | 71 | * address; zero on error |
@@ -73,8 +73,8 @@ static int process_request_key_err(long err_code) | |||
73 | * | 73 | * |
74 | * Returns zero on success; non-zero on error | 74 | * Returns zero on success; non-zero on error |
75 | */ | 75 | */ |
76 | static int parse_packet_length(unsigned char *data, size_t *size, | 76 | int ecryptfs_parse_packet_length(unsigned char *data, size_t *size, |
77 | size_t *length_size) | 77 | size_t *length_size) |
78 | { | 78 | { |
79 | int rc = 0; | 79 | int rc = 0; |
80 | 80 | ||
@@ -105,7 +105,7 @@ out: | |||
105 | } | 105 | } |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * write_packet_length | 108 | * ecryptfs_write_packet_length |
109 | * @dest: The byte array target into which to write the length. Must | 109 | * @dest: The byte array target into which to write the length. Must |
110 | * have at least 5 bytes allocated. | 110 | * have at least 5 bytes allocated. |
111 | * @size: The length to write. | 111 | * @size: The length to write. |
@@ -114,8 +114,8 @@ out: | |||
114 | * | 114 | * |
115 | * Returns zero on success; non-zero on error. | 115 | * Returns zero on success; non-zero on error. |
116 | */ | 116 | */ |
117 | static int write_packet_length(char *dest, size_t size, | 117 | int ecryptfs_write_packet_length(char *dest, size_t size, |
118 | size_t *packet_size_length) | 118 | size_t *packet_size_length) |
119 | { | 119 | { |
120 | int rc = 0; | 120 | int rc = 0; |
121 | 121 | ||
@@ -162,8 +162,8 @@ write_tag_64_packet(char *signature, struct ecryptfs_session_key *session_key, | |||
162 | goto out; | 162 | goto out; |
163 | } | 163 | } |
164 | message[i++] = ECRYPTFS_TAG_64_PACKET_TYPE; | 164 | message[i++] = ECRYPTFS_TAG_64_PACKET_TYPE; |
165 | rc = write_packet_length(&message[i], ECRYPTFS_SIG_SIZE_HEX, | 165 | rc = ecryptfs_write_packet_length(&message[i], ECRYPTFS_SIG_SIZE_HEX, |
166 | &packet_size_len); | 166 | &packet_size_len); |
167 | if (rc) { | 167 | if (rc) { |
168 | ecryptfs_printk(KERN_ERR, "Error generating tag 64 packet " | 168 | ecryptfs_printk(KERN_ERR, "Error generating tag 64 packet " |
169 | "header; cannot generate packet length\n"); | 169 | "header; cannot generate packet length\n"); |
@@ -172,8 +172,9 @@ write_tag_64_packet(char *signature, struct ecryptfs_session_key *session_key, | |||
172 | i += packet_size_len; | 172 | i += packet_size_len; |
173 | memcpy(&message[i], signature, ECRYPTFS_SIG_SIZE_HEX); | 173 | memcpy(&message[i], signature, ECRYPTFS_SIG_SIZE_HEX); |
174 | i += ECRYPTFS_SIG_SIZE_HEX; | 174 | i += ECRYPTFS_SIG_SIZE_HEX; |
175 | rc = write_packet_length(&message[i], session_key->encrypted_key_size, | 175 | rc = ecryptfs_write_packet_length(&message[i], |
176 | &packet_size_len); | 176 | session_key->encrypted_key_size, |
177 | &packet_size_len); | ||
177 | if (rc) { | 178 | if (rc) { |
178 | ecryptfs_printk(KERN_ERR, "Error generating tag 64 packet " | 179 | ecryptfs_printk(KERN_ERR, "Error generating tag 64 packet " |
179 | "header; cannot generate packet length\n"); | 180 | "header; cannot generate packet length\n"); |
@@ -225,7 +226,7 @@ parse_tag_65_packet(struct ecryptfs_session_key *session_key, u8 *cipher_code, | |||
225 | rc = -EIO; | 226 | rc = -EIO; |
226 | goto out; | 227 | goto out; |
227 | } | 228 | } |
228 | rc = parse_packet_length(&data[i], &m_size, &data_len); | 229 | rc = ecryptfs_parse_packet_length(&data[i], &m_size, &data_len); |
229 | if (rc) { | 230 | if (rc) { |
230 | ecryptfs_printk(KERN_WARNING, "Error parsing packet length; " | 231 | ecryptfs_printk(KERN_WARNING, "Error parsing packet length; " |
231 | "rc = [%d]\n", rc); | 232 | "rc = [%d]\n", rc); |
@@ -304,8 +305,8 @@ write_tag_66_packet(char *signature, u8 cipher_code, | |||
304 | goto out; | 305 | goto out; |
305 | } | 306 | } |
306 | message[i++] = ECRYPTFS_TAG_66_PACKET_TYPE; | 307 | message[i++] = ECRYPTFS_TAG_66_PACKET_TYPE; |
307 | rc = write_packet_length(&message[i], ECRYPTFS_SIG_SIZE_HEX, | 308 | rc = ecryptfs_write_packet_length(&message[i], ECRYPTFS_SIG_SIZE_HEX, |
308 | &packet_size_len); | 309 | &packet_size_len); |
309 | if (rc) { | 310 | if (rc) { |
310 | ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet " | 311 | ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet " |
311 | "header; cannot generate packet length\n"); | 312 | "header; cannot generate packet length\n"); |
@@ -315,8 +316,8 @@ write_tag_66_packet(char *signature, u8 cipher_code, | |||
315 | memcpy(&message[i], signature, ECRYPTFS_SIG_SIZE_HEX); | 316 | memcpy(&message[i], signature, ECRYPTFS_SIG_SIZE_HEX); |
316 | i += ECRYPTFS_SIG_SIZE_HEX; | 317 | i += ECRYPTFS_SIG_SIZE_HEX; |
317 | /* The encrypted key includes 1 byte cipher code and 2 byte checksum */ | 318 | /* The encrypted key includes 1 byte cipher code and 2 byte checksum */ |
318 | rc = write_packet_length(&message[i], crypt_stat->key_size + 3, | 319 | rc = ecryptfs_write_packet_length(&message[i], crypt_stat->key_size + 3, |
319 | &packet_size_len); | 320 | &packet_size_len); |
320 | if (rc) { | 321 | if (rc) { |
321 | ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet " | 322 | ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet " |
322 | "header; cannot generate packet length\n"); | 323 | "header; cannot generate packet length\n"); |
@@ -357,20 +358,25 @@ parse_tag_67_packet(struct ecryptfs_key_record *key_rec, | |||
357 | /* verify that everything through the encrypted FEK size is present */ | 358 | /* verify that everything through the encrypted FEK size is present */ |
358 | if (message_len < 4) { | 359 | if (message_len < 4) { |
359 | rc = -EIO; | 360 | rc = -EIO; |
361 | printk(KERN_ERR "%s: message_len is [%Zd]; minimum acceptable " | ||
362 | "message length is [%d]\n", __func__, message_len, 4); | ||
360 | goto out; | 363 | goto out; |
361 | } | 364 | } |
362 | if (data[i++] != ECRYPTFS_TAG_67_PACKET_TYPE) { | 365 | if (data[i++] != ECRYPTFS_TAG_67_PACKET_TYPE) { |
363 | ecryptfs_printk(KERN_ERR, "Type should be ECRYPTFS_TAG_67\n"); | ||
364 | rc = -EIO; | 366 | rc = -EIO; |
367 | printk(KERN_ERR "%s: Type should be ECRYPTFS_TAG_67\n", | ||
368 | __func__); | ||
365 | goto out; | 369 | goto out; |
366 | } | 370 | } |
367 | if (data[i++]) { | 371 | if (data[i++]) { |
368 | ecryptfs_printk(KERN_ERR, "Status indicator has non zero value" | ||
369 | " [%d]\n", data[i-1]); | ||
370 | rc = -EIO; | 372 | rc = -EIO; |
373 | printk(KERN_ERR "%s: Status indicator has non zero " | ||
374 | "value [%d]\n", __func__, data[i-1]); | ||
375 | |||
371 | goto out; | 376 | goto out; |
372 | } | 377 | } |
373 | rc = parse_packet_length(&data[i], &key_rec->enc_key_size, &data_len); | 378 | rc = ecryptfs_parse_packet_length(&data[i], &key_rec->enc_key_size, |
379 | &data_len); | ||
374 | if (rc) { | 380 | if (rc) { |
375 | ecryptfs_printk(KERN_WARNING, "Error parsing packet length; " | 381 | ecryptfs_printk(KERN_WARNING, "Error parsing packet length; " |
376 | "rc = [%d]\n", rc); | 382 | "rc = [%d]\n", rc); |
@@ -378,17 +384,17 @@ parse_tag_67_packet(struct ecryptfs_key_record *key_rec, | |||
378 | } | 384 | } |
379 | i += data_len; | 385 | i += data_len; |
380 | if (message_len < (i + key_rec->enc_key_size)) { | 386 | if (message_len < (i + key_rec->enc_key_size)) { |
381 | ecryptfs_printk(KERN_ERR, "message_len [%d]; max len is [%d]\n", | ||
382 | message_len, (i + key_rec->enc_key_size)); | ||
383 | rc = -EIO; | 387 | rc = -EIO; |
388 | printk(KERN_ERR "%s: message_len [%Zd]; max len is [%Zd]\n", | ||
389 | __func__, message_len, (i + key_rec->enc_key_size)); | ||
384 | goto out; | 390 | goto out; |
385 | } | 391 | } |
386 | if (key_rec->enc_key_size > ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES) { | 392 | if (key_rec->enc_key_size > ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES) { |
387 | ecryptfs_printk(KERN_ERR, "Encrypted key_size [%d] larger than " | ||
388 | "the maximum key size [%d]\n", | ||
389 | key_rec->enc_key_size, | ||
390 | ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES); | ||
391 | rc = -EIO; | 393 | rc = -EIO; |
394 | printk(KERN_ERR "%s: Encrypted key_size [%Zd] larger than " | ||
395 | "the maximum key size [%d]\n", __func__, | ||
396 | key_rec->enc_key_size, | ||
397 | ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES); | ||
392 | goto out; | 398 | goto out; |
393 | } | 399 | } |
394 | memcpy(key_rec->enc_key, &data[i], key_rec->enc_key_size); | 400 | memcpy(key_rec->enc_key, &data[i], key_rec->enc_key_size); |
@@ -445,7 +451,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, | |||
445 | rc = write_tag_64_packet(auth_tok_sig, &(auth_tok->session_key), | 451 | rc = write_tag_64_packet(auth_tok_sig, &(auth_tok->session_key), |
446 | &netlink_message, &netlink_message_length); | 452 | &netlink_message, &netlink_message_length); |
447 | if (rc) { | 453 | if (rc) { |
448 | ecryptfs_printk(KERN_ERR, "Failed to write tag 64 packet"); | 454 | ecryptfs_printk(KERN_ERR, "Failed to write tag 64 packet\n"); |
449 | goto out; | 455 | goto out; |
450 | } | 456 | } |
451 | rc = ecryptfs_send_message(ecryptfs_transport, netlink_message, | 457 | rc = ecryptfs_send_message(ecryptfs_transport, netlink_message, |
@@ -570,8 +576,8 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat, | |||
570 | goto out; | 576 | goto out; |
571 | } | 577 | } |
572 | (*new_auth_tok) = &auth_tok_list_item->auth_tok; | 578 | (*new_auth_tok) = &auth_tok_list_item->auth_tok; |
573 | rc = parse_packet_length(&data[(*packet_size)], &body_size, | 579 | rc = ecryptfs_parse_packet_length(&data[(*packet_size)], &body_size, |
574 | &length_size); | 580 | &length_size); |
575 | if (rc) { | 581 | if (rc) { |
576 | printk(KERN_WARNING "Error parsing packet length; " | 582 | printk(KERN_WARNING "Error parsing packet length; " |
577 | "rc = [%d]\n", rc); | 583 | "rc = [%d]\n", rc); |
@@ -704,8 +710,8 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat, | |||
704 | goto out; | 710 | goto out; |
705 | } | 711 | } |
706 | (*new_auth_tok) = &auth_tok_list_item->auth_tok; | 712 | (*new_auth_tok) = &auth_tok_list_item->auth_tok; |
707 | rc = parse_packet_length(&data[(*packet_size)], &body_size, | 713 | rc = ecryptfs_parse_packet_length(&data[(*packet_size)], &body_size, |
708 | &length_size); | 714 | &length_size); |
709 | if (rc) { | 715 | if (rc) { |
710 | printk(KERN_WARNING "Error parsing packet length; rc = [%d]\n", | 716 | printk(KERN_WARNING "Error parsing packet length; rc = [%d]\n", |
711 | rc); | 717 | rc); |
@@ -852,8 +858,8 @@ parse_tag_11_packet(unsigned char *data, unsigned char *contents, | |||
852 | rc = -EINVAL; | 858 | rc = -EINVAL; |
853 | goto out; | 859 | goto out; |
854 | } | 860 | } |
855 | rc = parse_packet_length(&data[(*packet_size)], &body_size, | 861 | rc = ecryptfs_parse_packet_length(&data[(*packet_size)], &body_size, |
856 | &length_size); | 862 | &length_size); |
857 | if (rc) { | 863 | if (rc) { |
858 | printk(KERN_WARNING "Invalid tag 11 packet format\n"); | 864 | printk(KERN_WARNING "Invalid tag 11 packet format\n"); |
859 | goto out; | 865 | goto out; |
@@ -1405,8 +1411,8 @@ write_tag_1_packet(char *dest, size_t *remaining_bytes, | |||
1405 | auth_tok->token.private_key.key_size; | 1411 | auth_tok->token.private_key.key_size; |
1406 | rc = pki_encrypt_session_key(auth_tok, crypt_stat, key_rec); | 1412 | rc = pki_encrypt_session_key(auth_tok, crypt_stat, key_rec); |
1407 | if (rc) { | 1413 | if (rc) { |
1408 | ecryptfs_printk(KERN_ERR, "Failed to encrypt session key " | 1414 | printk(KERN_ERR "Failed to encrypt session key via a key " |
1409 | "via a pki"); | 1415 | "module; rc = [%d]\n", rc); |
1410 | goto out; | 1416 | goto out; |
1411 | } | 1417 | } |
1412 | if (ecryptfs_verbosity > 0) { | 1418 | if (ecryptfs_verbosity > 0) { |
@@ -1430,8 +1436,9 @@ encrypted_session_key_set: | |||
1430 | goto out; | 1436 | goto out; |
1431 | } | 1437 | } |
1432 | dest[(*packet_size)++] = ECRYPTFS_TAG_1_PACKET_TYPE; | 1438 | dest[(*packet_size)++] = ECRYPTFS_TAG_1_PACKET_TYPE; |
1433 | rc = write_packet_length(&dest[(*packet_size)], (max_packet_size - 4), | 1439 | rc = ecryptfs_write_packet_length(&dest[(*packet_size)], |
1434 | &packet_size_length); | 1440 | (max_packet_size - 4), |
1441 | &packet_size_length); | ||
1435 | if (rc) { | 1442 | if (rc) { |
1436 | ecryptfs_printk(KERN_ERR, "Error generating tag 1 packet " | 1443 | ecryptfs_printk(KERN_ERR, "Error generating tag 1 packet " |
1437 | "header; cannot generate packet length\n"); | 1444 | "header; cannot generate packet length\n"); |
@@ -1489,8 +1496,9 @@ write_tag_11_packet(char *dest, size_t *remaining_bytes, char *contents, | |||
1489 | goto out; | 1496 | goto out; |
1490 | } | 1497 | } |
1491 | dest[(*packet_length)++] = ECRYPTFS_TAG_11_PACKET_TYPE; | 1498 | dest[(*packet_length)++] = ECRYPTFS_TAG_11_PACKET_TYPE; |
1492 | rc = write_packet_length(&dest[(*packet_length)], | 1499 | rc = ecryptfs_write_packet_length(&dest[(*packet_length)], |
1493 | (max_packet_size - 4), &packet_size_length); | 1500 | (max_packet_size - 4), |
1501 | &packet_size_length); | ||
1494 | if (rc) { | 1502 | if (rc) { |
1495 | printk(KERN_ERR "Error generating tag 11 packet header; cannot " | 1503 | printk(KERN_ERR "Error generating tag 11 packet header; cannot " |
1496 | "generate packet length. rc = [%d]\n", rc); | 1504 | "generate packet length. rc = [%d]\n", rc); |
@@ -1682,8 +1690,9 @@ encrypted_session_key_set: | |||
1682 | dest[(*packet_size)++] = ECRYPTFS_TAG_3_PACKET_TYPE; | 1690 | dest[(*packet_size)++] = ECRYPTFS_TAG_3_PACKET_TYPE; |
1683 | /* Chop off the Tag 3 identifier(1) and Tag 3 packet size(3) | 1691 | /* Chop off the Tag 3 identifier(1) and Tag 3 packet size(3) |
1684 | * to get the number of octets in the actual Tag 3 packet */ | 1692 | * to get the number of octets in the actual Tag 3 packet */ |
1685 | rc = write_packet_length(&dest[(*packet_size)], (max_packet_size - 4), | 1693 | rc = ecryptfs_write_packet_length(&dest[(*packet_size)], |
1686 | &packet_size_length); | 1694 | (max_packet_size - 4), |
1695 | &packet_size_length); | ||
1687 | if (rc) { | 1696 | if (rc) { |
1688 | printk(KERN_ERR "Error generating tag 3 packet header; cannot " | 1697 | printk(KERN_ERR "Error generating tag 3 packet header; cannot " |
1689 | "generate packet length. rc = [%d]\n", rc); | 1698 | "generate packet length. rc = [%d]\n", rc); |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index d25ac9500a92..d603631601eb 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -219,7 +219,7 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | |||
219 | if (rc) { | 219 | if (rc) { |
220 | printk(KERN_ERR "%s: Error attempting to initialize the " | 220 | printk(KERN_ERR "%s: Error attempting to initialize the " |
221 | "persistent file for the dentry with name [%s]; " | 221 | "persistent file for the dentry with name [%s]; " |
222 | "rc = [%d]\n", __FUNCTION__, dentry->d_name.name, rc); | 222 | "rc = [%d]\n", __func__, dentry->d_name.name, rc); |
223 | goto out; | 223 | goto out; |
224 | } | 224 | } |
225 | out: | 225 | out: |
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index 9cc2aec27b0d..1b5c20058acb 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | * eCryptfs: Linux filesystem encryption layer | 2 | * eCryptfs: Linux filesystem encryption layer |
3 | * | 3 | * |
4 | * Copyright (C) 2004-2006 International Business Machines Corp. | 4 | * Copyright (C) 2004-2008 International Business Machines Corp. |
5 | * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> | 5 | * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> |
6 | * Tyler Hicks <tyhicks@ou.edu> | 6 | * Tyler Hicks <tyhicks@ou.edu> |
7 | * | 7 | * |
@@ -20,19 +20,21 @@ | |||
20 | * 02111-1307, USA. | 20 | * 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
23 | #include <linux/user_namespace.h> | ||
24 | #include <linux/nsproxy.h> | ||
23 | #include "ecryptfs_kernel.h" | 25 | #include "ecryptfs_kernel.h" |
24 | 26 | ||
25 | static LIST_HEAD(ecryptfs_msg_ctx_free_list); | 27 | static LIST_HEAD(ecryptfs_msg_ctx_free_list); |
26 | static LIST_HEAD(ecryptfs_msg_ctx_alloc_list); | 28 | static LIST_HEAD(ecryptfs_msg_ctx_alloc_list); |
27 | static struct mutex ecryptfs_msg_ctx_lists_mux; | 29 | static struct mutex ecryptfs_msg_ctx_lists_mux; |
28 | 30 | ||
29 | static struct hlist_head *ecryptfs_daemon_id_hash; | 31 | static struct hlist_head *ecryptfs_daemon_hash; |
30 | static struct mutex ecryptfs_daemon_id_hash_mux; | 32 | struct mutex ecryptfs_daemon_hash_mux; |
31 | static int ecryptfs_hash_buckets; | 33 | static int ecryptfs_hash_buckets; |
32 | #define ecryptfs_uid_hash(uid) \ | 34 | #define ecryptfs_uid_hash(uid) \ |
33 | hash_long((unsigned long)uid, ecryptfs_hash_buckets) | 35 | hash_long((unsigned long)uid, ecryptfs_hash_buckets) |
34 | 36 | ||
35 | static unsigned int ecryptfs_msg_counter; | 37 | static u32 ecryptfs_msg_counter; |
36 | static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr; | 38 | static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr; |
37 | 39 | ||
38 | /** | 40 | /** |
@@ -40,9 +42,10 @@ static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr; | |||
40 | * @msg_ctx: The context that was acquired from the free list | 42 | * @msg_ctx: The context that was acquired from the free list |
41 | * | 43 | * |
42 | * Acquires a context element from the free list and locks the mutex | 44 | * Acquires a context element from the free list and locks the mutex |
43 | * on the context. Returns zero on success; non-zero on error or upon | 45 | * on the context. Sets the msg_ctx task to current. Returns zero on |
44 | * failure to acquire a free context element. Be sure to lock the | 46 | * success; non-zero on error or upon failure to acquire a free |
45 | * list mutex before calling. | 47 | * context element. Must be called with ecryptfs_msg_ctx_lists_mux |
48 | * held. | ||
46 | */ | 49 | */ |
47 | static int ecryptfs_acquire_free_msg_ctx(struct ecryptfs_msg_ctx **msg_ctx) | 50 | static int ecryptfs_acquire_free_msg_ctx(struct ecryptfs_msg_ctx **msg_ctx) |
48 | { | 51 | { |
@@ -50,11 +53,11 @@ static int ecryptfs_acquire_free_msg_ctx(struct ecryptfs_msg_ctx **msg_ctx) | |||
50 | int rc; | 53 | int rc; |
51 | 54 | ||
52 | if (list_empty(&ecryptfs_msg_ctx_free_list)) { | 55 | if (list_empty(&ecryptfs_msg_ctx_free_list)) { |
53 | ecryptfs_printk(KERN_WARNING, "The eCryptfs free " | 56 | printk(KERN_WARNING "%s: The eCryptfs free " |
54 | "context list is empty. It may be helpful to " | 57 | "context list is empty. It may be helpful to " |
55 | "specify the ecryptfs_message_buf_len " | 58 | "specify the ecryptfs_message_buf_len " |
56 | "parameter to be greater than the current " | 59 | "parameter to be greater than the current " |
57 | "value of [%d]\n", ecryptfs_message_buf_len); | 60 | "value of [%d]\n", __func__, ecryptfs_message_buf_len); |
58 | rc = -ENOMEM; | 61 | rc = -ENOMEM; |
59 | goto out; | 62 | goto out; |
60 | } | 63 | } |
@@ -75,8 +78,7 @@ out: | |||
75 | * ecryptfs_msg_ctx_free_to_alloc | 78 | * ecryptfs_msg_ctx_free_to_alloc |
76 | * @msg_ctx: The context to move from the free list to the alloc list | 79 | * @msg_ctx: The context to move from the free list to the alloc list |
77 | * | 80 | * |
78 | * Be sure to lock the list mutex and the context mutex before | 81 | * Must be called with ecryptfs_msg_ctx_lists_mux held. |
79 | * calling. | ||
80 | */ | 82 | */ |
81 | static void ecryptfs_msg_ctx_free_to_alloc(struct ecryptfs_msg_ctx *msg_ctx) | 83 | static void ecryptfs_msg_ctx_free_to_alloc(struct ecryptfs_msg_ctx *msg_ctx) |
82 | { | 84 | { |
@@ -89,36 +91,39 @@ static void ecryptfs_msg_ctx_free_to_alloc(struct ecryptfs_msg_ctx *msg_ctx) | |||
89 | * ecryptfs_msg_ctx_alloc_to_free | 91 | * ecryptfs_msg_ctx_alloc_to_free |
90 | * @msg_ctx: The context to move from the alloc list to the free list | 92 | * @msg_ctx: The context to move from the alloc list to the free list |
91 | * | 93 | * |
92 | * Be sure to lock the list mutex and the context mutex before | 94 | * Must be called with ecryptfs_msg_ctx_lists_mux held. |
93 | * calling. | ||
94 | */ | 95 | */ |
95 | static void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx) | 96 | void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx) |
96 | { | 97 | { |
97 | list_move(&(msg_ctx->node), &ecryptfs_msg_ctx_free_list); | 98 | list_move(&(msg_ctx->node), &ecryptfs_msg_ctx_free_list); |
98 | if (msg_ctx->msg) | 99 | if (msg_ctx->msg) |
99 | kfree(msg_ctx->msg); | 100 | kfree(msg_ctx->msg); |
101 | msg_ctx->msg = NULL; | ||
100 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_FREE; | 102 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_FREE; |
101 | } | 103 | } |
102 | 104 | ||
103 | /** | 105 | /** |
104 | * ecryptfs_find_daemon_id | 106 | * ecryptfs_find_daemon_by_euid |
105 | * @uid: The user id which maps to the desired daemon id | 107 | * @euid: The effective user id which maps to the desired daemon id |
106 | * @id: If return value is zero, points to the desired daemon id | 108 | * @user_ns: The namespace in which @euid applies |
107 | * pointer | 109 | * @daemon: If return value is zero, points to the desired daemon pointer |
108 | * | 110 | * |
109 | * Search the hash list for the given user id. Returns zero if the | 111 | * Must be called with ecryptfs_daemon_hash_mux held. |
110 | * user id exists in the list; non-zero otherwise. The daemon id hash | 112 | * |
111 | * mutex should be held before calling this function. | 113 | * Search the hash list for the given user id. |
114 | * | ||
115 | * Returns zero if the user id exists in the list; non-zero otherwise. | ||
112 | */ | 116 | */ |
113 | static int ecryptfs_find_daemon_id(uid_t uid, struct ecryptfs_daemon_id **id) | 117 | int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon, uid_t euid, |
118 | struct user_namespace *user_ns) | ||
114 | { | 119 | { |
115 | struct hlist_node *elem; | 120 | struct hlist_node *elem; |
116 | int rc; | 121 | int rc; |
117 | 122 | ||
118 | hlist_for_each_entry(*id, elem, | 123 | hlist_for_each_entry(*daemon, elem, |
119 | &ecryptfs_daemon_id_hash[ecryptfs_uid_hash(uid)], | 124 | &ecryptfs_daemon_hash[ecryptfs_uid_hash(euid)], |
120 | id_chain) { | 125 | euid_chain) { |
121 | if ((*id)->uid == uid) { | 126 | if ((*daemon)->euid == euid && (*daemon)->user_ns == user_ns) { |
122 | rc = 0; | 127 | rc = 0; |
123 | goto out; | 128 | goto out; |
124 | } | 129 | } |
@@ -128,181 +133,325 @@ out: | |||
128 | return rc; | 133 | return rc; |
129 | } | 134 | } |
130 | 135 | ||
131 | static int ecryptfs_send_raw_message(unsigned int transport, u16 msg_type, | 136 | static int |
132 | pid_t pid) | 137 | ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, |
138 | u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx); | ||
139 | |||
140 | /** | ||
141 | * ecryptfs_send_raw_message | ||
142 | * @transport: Transport type | ||
143 | * @msg_type: Message type | ||
144 | * @daemon: Daemon struct for recipient of message | ||
145 | * | ||
146 | * A raw message is one that does not include an ecryptfs_message | ||
147 | * struct. It simply has a type. | ||
148 | * | ||
149 | * Must be called with ecryptfs_daemon_hash_mux held. | ||
150 | * | ||
151 | * Returns zero on success; non-zero otherwise | ||
152 | */ | ||
153 | static int ecryptfs_send_raw_message(unsigned int transport, u8 msg_type, | ||
154 | struct ecryptfs_daemon *daemon) | ||
133 | { | 155 | { |
156 | struct ecryptfs_msg_ctx *msg_ctx; | ||
134 | int rc; | 157 | int rc; |
135 | 158 | ||
136 | switch(transport) { | 159 | switch(transport) { |
137 | case ECRYPTFS_TRANSPORT_NETLINK: | 160 | case ECRYPTFS_TRANSPORT_NETLINK: |
138 | rc = ecryptfs_send_netlink(NULL, 0, NULL, msg_type, 0, pid); | 161 | rc = ecryptfs_send_netlink(NULL, 0, NULL, msg_type, 0, |
162 | daemon->pid); | ||
163 | break; | ||
164 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
165 | rc = ecryptfs_send_message_locked(transport, NULL, 0, msg_type, | ||
166 | &msg_ctx); | ||
167 | if (rc) { | ||
168 | printk(KERN_ERR "%s: Error whilst attempting to send " | ||
169 | "message via procfs; rc = [%d]\n", __func__, rc); | ||
170 | goto out; | ||
171 | } | ||
172 | /* Raw messages are logically context-free (e.g., no | ||
173 | * reply is expected), so we set the state of the | ||
174 | * ecryptfs_msg_ctx object to indicate that it should | ||
175 | * be freed as soon as the transport sends out the message. */ | ||
176 | mutex_lock(&msg_ctx->mux); | ||
177 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_NO_REPLY; | ||
178 | mutex_unlock(&msg_ctx->mux); | ||
139 | break; | 179 | break; |
140 | case ECRYPTFS_TRANSPORT_CONNECTOR: | 180 | case ECRYPTFS_TRANSPORT_CONNECTOR: |
141 | case ECRYPTFS_TRANSPORT_RELAYFS: | 181 | case ECRYPTFS_TRANSPORT_RELAYFS: |
142 | default: | 182 | default: |
143 | rc = -ENOSYS; | 183 | rc = -ENOSYS; |
144 | } | 184 | } |
185 | out: | ||
186 | return rc; | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * ecryptfs_spawn_daemon - Create and initialize a new daemon struct | ||
191 | * @daemon: Pointer to set to newly allocated daemon struct | ||
192 | * @euid: Effective user id for the daemon | ||
193 | * @user_ns: The namespace in which @euid applies | ||
194 | * @pid: Process id for the daemon | ||
195 | * | ||
196 | * Must be called ceremoniously while in possession of | ||
197 | * ecryptfs_sacred_daemon_hash_mux | ||
198 | * | ||
199 | * Returns zero on success; non-zero otherwise | ||
200 | */ | ||
201 | int | ||
202 | ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, uid_t euid, | ||
203 | struct user_namespace *user_ns, struct pid *pid) | ||
204 | { | ||
205 | int rc = 0; | ||
206 | |||
207 | (*daemon) = kzalloc(sizeof(**daemon), GFP_KERNEL); | ||
208 | if (!(*daemon)) { | ||
209 | rc = -ENOMEM; | ||
210 | printk(KERN_ERR "%s: Failed to allocate [%Zd] bytes of " | ||
211 | "GFP_KERNEL memory\n", __func__, sizeof(**daemon)); | ||
212 | goto out; | ||
213 | } | ||
214 | (*daemon)->euid = euid; | ||
215 | (*daemon)->user_ns = get_user_ns(user_ns); | ||
216 | (*daemon)->pid = get_pid(pid); | ||
217 | (*daemon)->task = current; | ||
218 | mutex_init(&(*daemon)->mux); | ||
219 | INIT_LIST_HEAD(&(*daemon)->msg_ctx_out_queue); | ||
220 | init_waitqueue_head(&(*daemon)->wait); | ||
221 | (*daemon)->num_queued_msg_ctx = 0; | ||
222 | hlist_add_head(&(*daemon)->euid_chain, | ||
223 | &ecryptfs_daemon_hash[ecryptfs_uid_hash(euid)]); | ||
224 | out: | ||
145 | return rc; | 225 | return rc; |
146 | } | 226 | } |
147 | 227 | ||
148 | /** | 228 | /** |
149 | * ecryptfs_process_helo | 229 | * ecryptfs_process_helo |
150 | * @transport: The underlying transport (netlink, etc.) | 230 | * @transport: The underlying transport (netlink, etc.) |
151 | * @uid: The user ID owner of the message | 231 | * @euid: The user ID owner of the message |
232 | * @user_ns: The namespace in which @euid applies | ||
152 | * @pid: The process ID for the userspace program that sent the | 233 | * @pid: The process ID for the userspace program that sent the |
153 | * message | 234 | * message |
154 | * | 235 | * |
155 | * Adds the uid and pid values to the daemon id hash. If a uid | 236 | * Adds the euid and pid values to the daemon euid hash. If an euid |
156 | * already has a daemon pid registered, the daemon will be | 237 | * already has a daemon pid registered, the daemon will be |
157 | * unregistered before the new daemon id is put into the hash list. | 238 | * unregistered before the new daemon is put into the hash list. |
158 | * Returns zero after adding a new daemon id to the hash list; | 239 | * Returns zero after adding a new daemon to the hash list; |
159 | * non-zero otherwise. | 240 | * non-zero otherwise. |
160 | */ | 241 | */ |
161 | int ecryptfs_process_helo(unsigned int transport, uid_t uid, pid_t pid) | 242 | int ecryptfs_process_helo(unsigned int transport, uid_t euid, |
243 | struct user_namespace *user_ns, struct pid *pid) | ||
162 | { | 244 | { |
163 | struct ecryptfs_daemon_id *new_id; | 245 | struct ecryptfs_daemon *new_daemon; |
164 | struct ecryptfs_daemon_id *old_id; | 246 | struct ecryptfs_daemon *old_daemon; |
165 | int rc; | 247 | int rc; |
166 | 248 | ||
167 | mutex_lock(&ecryptfs_daemon_id_hash_mux); | 249 | mutex_lock(&ecryptfs_daemon_hash_mux); |
168 | new_id = kmalloc(sizeof(*new_id), GFP_KERNEL); | 250 | rc = ecryptfs_find_daemon_by_euid(&old_daemon, euid, user_ns); |
169 | if (!new_id) { | 251 | if (rc != 0) { |
170 | rc = -ENOMEM; | ||
171 | ecryptfs_printk(KERN_ERR, "Failed to allocate memory; unable " | ||
172 | "to register daemon [%d] for user [%d]\n", | ||
173 | pid, uid); | ||
174 | goto unlock; | ||
175 | } | ||
176 | if (!ecryptfs_find_daemon_id(uid, &old_id)) { | ||
177 | printk(KERN_WARNING "Received request from user [%d] " | 252 | printk(KERN_WARNING "Received request from user [%d] " |
178 | "to register daemon [%d]; unregistering daemon " | 253 | "to register daemon [0x%p]; unregistering daemon " |
179 | "[%d]\n", uid, pid, old_id->pid); | 254 | "[0x%p]\n", euid, pid, old_daemon->pid); |
180 | hlist_del(&old_id->id_chain); | 255 | rc = ecryptfs_send_raw_message(transport, ECRYPTFS_MSG_QUIT, |
181 | rc = ecryptfs_send_raw_message(transport, ECRYPTFS_NLMSG_QUIT, | 256 | old_daemon); |
182 | old_id->pid); | ||
183 | if (rc) | 257 | if (rc) |
184 | printk(KERN_WARNING "Failed to send QUIT " | 258 | printk(KERN_WARNING "Failed to send QUIT " |
185 | "message to daemon [%d]; rc = [%d]\n", | 259 | "message to daemon [0x%p]; rc = [%d]\n", |
186 | old_id->pid, rc); | 260 | old_daemon->pid, rc); |
187 | kfree(old_id); | 261 | hlist_del(&old_daemon->euid_chain); |
262 | kfree(old_daemon); | ||
188 | } | 263 | } |
189 | new_id->uid = uid; | 264 | rc = ecryptfs_spawn_daemon(&new_daemon, euid, user_ns, pid); |
190 | new_id->pid = pid; | 265 | if (rc) |
191 | hlist_add_head(&new_id->id_chain, | 266 | printk(KERN_ERR "%s: The gods are displeased with this attempt " |
192 | &ecryptfs_daemon_id_hash[ecryptfs_uid_hash(uid)]); | 267 | "to create a new daemon object for euid [%d]; pid " |
193 | rc = 0; | 268 | "[0x%p]; rc = [%d]\n", __func__, euid, pid, rc); |
194 | unlock: | 269 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
195 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | 270 | return rc; |
271 | } | ||
272 | |||
273 | /** | ||
274 | * ecryptfs_exorcise_daemon - Destroy the daemon struct | ||
275 | * | ||
276 | * Must be called ceremoniously while in possession of | ||
277 | * ecryptfs_daemon_hash_mux and the daemon's own mux. | ||
278 | */ | ||
279 | int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon) | ||
280 | { | ||
281 | struct ecryptfs_msg_ctx *msg_ctx, *msg_ctx_tmp; | ||
282 | int rc = 0; | ||
283 | |||
284 | mutex_lock(&daemon->mux); | ||
285 | if ((daemon->flags & ECRYPTFS_DAEMON_IN_READ) | ||
286 | || (daemon->flags & ECRYPTFS_DAEMON_IN_POLL)) { | ||
287 | rc = -EBUSY; | ||
288 | printk(KERN_WARNING "%s: Attempt to destroy daemon with pid " | ||
289 | "[0x%p], but it is in the midst of a read or a poll\n", | ||
290 | __func__, daemon->pid); | ||
291 | mutex_unlock(&daemon->mux); | ||
292 | goto out; | ||
293 | } | ||
294 | list_for_each_entry_safe(msg_ctx, msg_ctx_tmp, | ||
295 | &daemon->msg_ctx_out_queue, daemon_out_list) { | ||
296 | list_del(&msg_ctx->daemon_out_list); | ||
297 | daemon->num_queued_msg_ctx--; | ||
298 | printk(KERN_WARNING "%s: Warning: dropping message that is in " | ||
299 | "the out queue of a dying daemon\n", __func__); | ||
300 | ecryptfs_msg_ctx_alloc_to_free(msg_ctx); | ||
301 | } | ||
302 | hlist_del(&daemon->euid_chain); | ||
303 | if (daemon->task) | ||
304 | wake_up_process(daemon->task); | ||
305 | if (daemon->pid) | ||
306 | put_pid(daemon->pid); | ||
307 | if (daemon->user_ns) | ||
308 | put_user_ns(daemon->user_ns); | ||
309 | mutex_unlock(&daemon->mux); | ||
310 | memset(daemon, 0, sizeof(*daemon)); | ||
311 | kfree(daemon); | ||
312 | out: | ||
196 | return rc; | 313 | return rc; |
197 | } | 314 | } |
198 | 315 | ||
199 | /** | 316 | /** |
200 | * ecryptfs_process_quit | 317 | * ecryptfs_process_quit |
201 | * @uid: The user ID owner of the message | 318 | * @euid: The user ID owner of the message |
319 | * @user_ns: The namespace in which @euid applies | ||
202 | * @pid: The process ID for the userspace program that sent the | 320 | * @pid: The process ID for the userspace program that sent the |
203 | * message | 321 | * message |
204 | * | 322 | * |
205 | * Deletes the corresponding daemon id for the given uid and pid, if | 323 | * Deletes the corresponding daemon for the given euid and pid, if |
206 | * it is the registered that is requesting the deletion. Returns zero | 324 | * it is the registered that is requesting the deletion. Returns zero |
207 | * after deleting the desired daemon id; non-zero otherwise. | 325 | * after deleting the desired daemon; non-zero otherwise. |
208 | */ | 326 | */ |
209 | int ecryptfs_process_quit(uid_t uid, pid_t pid) | 327 | int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns, |
328 | struct pid *pid) | ||
210 | { | 329 | { |
211 | struct ecryptfs_daemon_id *id; | 330 | struct ecryptfs_daemon *daemon; |
212 | int rc; | 331 | int rc; |
213 | 332 | ||
214 | mutex_lock(&ecryptfs_daemon_id_hash_mux); | 333 | mutex_lock(&ecryptfs_daemon_hash_mux); |
215 | if (ecryptfs_find_daemon_id(uid, &id)) { | 334 | rc = ecryptfs_find_daemon_by_euid(&daemon, euid, user_ns); |
335 | if (rc || !daemon) { | ||
216 | rc = -EINVAL; | 336 | rc = -EINVAL; |
217 | ecryptfs_printk(KERN_ERR, "Received request from user [%d] to " | 337 | printk(KERN_ERR "Received request from user [%d] to " |
218 | "unregister unrecognized daemon [%d]\n", uid, | 338 | "unregister unrecognized daemon [0x%p]\n", euid, pid); |
219 | pid); | 339 | goto out_unlock; |
220 | goto unlock; | ||
221 | } | 340 | } |
222 | if (id->pid != pid) { | 341 | rc = ecryptfs_exorcise_daemon(daemon); |
223 | rc = -EINVAL; | 342 | out_unlock: |
224 | ecryptfs_printk(KERN_WARNING, "Received request from user [%d] " | 343 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
225 | "with pid [%d] to unregister daemon [%d]\n", | ||
226 | uid, pid, id->pid); | ||
227 | goto unlock; | ||
228 | } | ||
229 | hlist_del(&id->id_chain); | ||
230 | kfree(id); | ||
231 | rc = 0; | ||
232 | unlock: | ||
233 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | ||
234 | return rc; | 344 | return rc; |
235 | } | 345 | } |
236 | 346 | ||
237 | /** | 347 | /** |
238 | * ecryptfs_process_reponse | 348 | * ecryptfs_process_reponse |
239 | * @msg: The ecryptfs message received; the caller should sanity check | 349 | * @msg: The ecryptfs message received; the caller should sanity check |
240 | * msg->data_len | 350 | * msg->data_len and free the memory |
241 | * @pid: The process ID of the userspace application that sent the | 351 | * @pid: The process ID of the userspace application that sent the |
242 | * message | 352 | * message |
243 | * @seq: The sequence number of the message | 353 | * @seq: The sequence number of the message; must match the sequence |
354 | * number for the existing message context waiting for this | ||
355 | * response | ||
356 | * | ||
357 | * Processes a response message after sending an operation request to | ||
358 | * userspace. Some other process is awaiting this response. Before | ||
359 | * sending out its first communications, the other process allocated a | ||
360 | * msg_ctx from the ecryptfs_msg_ctx_arr at a particular index. The | ||
361 | * response message contains this index so that we can copy over the | ||
362 | * response message into the msg_ctx that the process holds a | ||
363 | * reference to. The other process is going to wake up, check to see | ||
364 | * that msg_ctx->state == ECRYPTFS_MSG_CTX_STATE_DONE, and then | ||
365 | * proceed to read off and process the response message. Returns zero | ||
366 | * upon delivery to desired context element; non-zero upon delivery | ||
367 | * failure or error. | ||
244 | * | 368 | * |
245 | * Processes a response message after sending a operation request to | 369 | * Returns zero on success; non-zero otherwise |
246 | * userspace. Returns zero upon delivery to desired context element; | ||
247 | * non-zero upon delivery failure or error. | ||
248 | */ | 370 | */ |
249 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t uid, | 371 | int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid, |
250 | pid_t pid, u32 seq) | 372 | struct user_namespace *user_ns, struct pid *pid, |
373 | u32 seq) | ||
251 | { | 374 | { |
252 | struct ecryptfs_daemon_id *id; | 375 | struct ecryptfs_daemon *daemon; |
253 | struct ecryptfs_msg_ctx *msg_ctx; | 376 | struct ecryptfs_msg_ctx *msg_ctx; |
254 | int msg_size; | 377 | size_t msg_size; |
378 | struct nsproxy *nsproxy; | ||
379 | struct user_namespace *current_user_ns; | ||
255 | int rc; | 380 | int rc; |
256 | 381 | ||
257 | if (msg->index >= ecryptfs_message_buf_len) { | 382 | if (msg->index >= ecryptfs_message_buf_len) { |
258 | rc = -EINVAL; | 383 | rc = -EINVAL; |
259 | ecryptfs_printk(KERN_ERR, "Attempt to reference " | 384 | printk(KERN_ERR "%s: Attempt to reference " |
260 | "context buffer at index [%d]; maximum " | 385 | "context buffer at index [%d]; maximum " |
261 | "allowable is [%d]\n", msg->index, | 386 | "allowable is [%d]\n", __func__, msg->index, |
262 | (ecryptfs_message_buf_len - 1)); | 387 | (ecryptfs_message_buf_len - 1)); |
263 | goto out; | 388 | goto out; |
264 | } | 389 | } |
265 | msg_ctx = &ecryptfs_msg_ctx_arr[msg->index]; | 390 | msg_ctx = &ecryptfs_msg_ctx_arr[msg->index]; |
266 | mutex_lock(&msg_ctx->mux); | 391 | mutex_lock(&msg_ctx->mux); |
267 | if (ecryptfs_find_daemon_id(msg_ctx->task->euid, &id)) { | 392 | mutex_lock(&ecryptfs_daemon_hash_mux); |
393 | rcu_read_lock(); | ||
394 | nsproxy = task_nsproxy(msg_ctx->task); | ||
395 | if (nsproxy == NULL) { | ||
268 | rc = -EBADMSG; | 396 | rc = -EBADMSG; |
269 | ecryptfs_printk(KERN_WARNING, "User [%d] received a " | 397 | printk(KERN_ERR "%s: Receiving process is a zombie. Dropping " |
270 | "message response from process [%d] but does " | 398 | "message.\n", __func__); |
271 | "not have a registered daemon\n", | 399 | rcu_read_unlock(); |
272 | msg_ctx->task->euid, pid); | 400 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
273 | goto wake_up; | 401 | goto wake_up; |
274 | } | 402 | } |
275 | if (msg_ctx->task->euid != uid) { | 403 | current_user_ns = nsproxy->user_ns; |
404 | rc = ecryptfs_find_daemon_by_euid(&daemon, msg_ctx->task->euid, | ||
405 | current_user_ns); | ||
406 | rcu_read_unlock(); | ||
407 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
408 | if (rc) { | ||
409 | rc = -EBADMSG; | ||
410 | printk(KERN_WARNING "%s: User [%d] received a " | ||
411 | "message response from process [0x%p] but does " | ||
412 | "not have a registered daemon\n", __func__, | ||
413 | msg_ctx->task->euid, pid); | ||
414 | goto wake_up; | ||
415 | } | ||
416 | if (msg_ctx->task->euid != euid) { | ||
276 | rc = -EBADMSG; | 417 | rc = -EBADMSG; |
277 | ecryptfs_printk(KERN_WARNING, "Received message from user " | 418 | printk(KERN_WARNING "%s: Received message from user " |
278 | "[%d]; expected message from user [%d]\n", | 419 | "[%d]; expected message from user [%d]\n", __func__, |
279 | uid, msg_ctx->task->euid); | 420 | euid, msg_ctx->task->euid); |
280 | goto unlock; | 421 | goto unlock; |
281 | } | 422 | } |
282 | if (id->pid != pid) { | 423 | if (current_user_ns != user_ns) { |
283 | rc = -EBADMSG; | 424 | rc = -EBADMSG; |
284 | ecryptfs_printk(KERN_ERR, "User [%d] received a " | 425 | printk(KERN_WARNING "%s: Received message from user_ns " |
285 | "message response from an unrecognized " | 426 | "[0x%p]; expected message from user_ns [0x%p]\n", |
286 | "process [%d]\n", msg_ctx->task->euid, pid); | 427 | __func__, user_ns, nsproxy->user_ns); |
428 | goto unlock; | ||
429 | } | ||
430 | if (daemon->pid != pid) { | ||
431 | rc = -EBADMSG; | ||
432 | printk(KERN_ERR "%s: User [%d] sent a message response " | ||
433 | "from an unrecognized process [0x%p]\n", | ||
434 | __func__, msg_ctx->task->euid, pid); | ||
287 | goto unlock; | 435 | goto unlock; |
288 | } | 436 | } |
289 | if (msg_ctx->state != ECRYPTFS_MSG_CTX_STATE_PENDING) { | 437 | if (msg_ctx->state != ECRYPTFS_MSG_CTX_STATE_PENDING) { |
290 | rc = -EINVAL; | 438 | rc = -EINVAL; |
291 | ecryptfs_printk(KERN_WARNING, "Desired context element is not " | 439 | printk(KERN_WARNING "%s: Desired context element is not " |
292 | "pending a response\n"); | 440 | "pending a response\n", __func__); |
293 | goto unlock; | 441 | goto unlock; |
294 | } else if (msg_ctx->counter != seq) { | 442 | } else if (msg_ctx->counter != seq) { |
295 | rc = -EINVAL; | 443 | rc = -EINVAL; |
296 | ecryptfs_printk(KERN_WARNING, "Invalid message sequence; " | 444 | printk(KERN_WARNING "%s: Invalid message sequence; " |
297 | "expected [%d]; received [%d]\n", | 445 | "expected [%d]; received [%d]\n", __func__, |
298 | msg_ctx->counter, seq); | 446 | msg_ctx->counter, seq); |
299 | goto unlock; | 447 | goto unlock; |
300 | } | 448 | } |
301 | msg_size = sizeof(*msg) + msg->data_len; | 449 | msg_size = (sizeof(*msg) + msg->data_len); |
302 | msg_ctx->msg = kmalloc(msg_size, GFP_KERNEL); | 450 | msg_ctx->msg = kmalloc(msg_size, GFP_KERNEL); |
303 | if (!msg_ctx->msg) { | 451 | if (!msg_ctx->msg) { |
304 | rc = -ENOMEM; | 452 | rc = -ENOMEM; |
305 | ecryptfs_printk(KERN_ERR, "Failed to allocate memory\n"); | 453 | printk(KERN_ERR "%s: Failed to allocate [%Zd] bytes of " |
454 | "GFP_KERNEL memory\n", __func__, msg_size); | ||
306 | goto unlock; | 455 | goto unlock; |
307 | } | 456 | } |
308 | memcpy(msg_ctx->msg, msg, msg_size); | 457 | memcpy(msg_ctx->msg, msg, msg_size); |
@@ -317,34 +466,38 @@ out: | |||
317 | } | 466 | } |
318 | 467 | ||
319 | /** | 468 | /** |
320 | * ecryptfs_send_message | 469 | * ecryptfs_send_message_locked |
321 | * @transport: The transport over which to send the message (i.e., | 470 | * @transport: The transport over which to send the message (i.e., |
322 | * netlink) | 471 | * netlink) |
323 | * @data: The data to send | 472 | * @data: The data to send |
324 | * @data_len: The length of data | 473 | * @data_len: The length of data |
325 | * @msg_ctx: The message context allocated for the send | 474 | * @msg_ctx: The message context allocated for the send |
475 | * | ||
476 | * Must be called with ecryptfs_daemon_hash_mux held. | ||
477 | * | ||
478 | * Returns zero on success; non-zero otherwise | ||
326 | */ | 479 | */ |
327 | int ecryptfs_send_message(unsigned int transport, char *data, int data_len, | 480 | static int |
328 | struct ecryptfs_msg_ctx **msg_ctx) | 481 | ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, |
482 | u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx) | ||
329 | { | 483 | { |
330 | struct ecryptfs_daemon_id *id; | 484 | struct ecryptfs_daemon *daemon; |
331 | int rc; | 485 | int rc; |
332 | 486 | ||
333 | mutex_lock(&ecryptfs_daemon_id_hash_mux); | 487 | rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid, |
334 | if (ecryptfs_find_daemon_id(current->euid, &id)) { | 488 | current->nsproxy->user_ns); |
335 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | 489 | if (rc || !daemon) { |
336 | rc = -ENOTCONN; | 490 | rc = -ENOTCONN; |
337 | ecryptfs_printk(KERN_ERR, "User [%d] does not have a daemon " | 491 | printk(KERN_ERR "%s: User [%d] does not have a daemon " |
338 | "registered\n", current->euid); | 492 | "registered\n", __func__, current->euid); |
339 | goto out; | 493 | goto out; |
340 | } | 494 | } |
341 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | ||
342 | mutex_lock(&ecryptfs_msg_ctx_lists_mux); | 495 | mutex_lock(&ecryptfs_msg_ctx_lists_mux); |
343 | rc = ecryptfs_acquire_free_msg_ctx(msg_ctx); | 496 | rc = ecryptfs_acquire_free_msg_ctx(msg_ctx); |
344 | if (rc) { | 497 | if (rc) { |
345 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); | 498 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); |
346 | ecryptfs_printk(KERN_WARNING, "Could not claim a free " | 499 | printk(KERN_WARNING "%s: Could not claim a free " |
347 | "context element\n"); | 500 | "context element\n", __func__); |
348 | goto out; | 501 | goto out; |
349 | } | 502 | } |
350 | ecryptfs_msg_ctx_free_to_alloc(*msg_ctx); | 503 | ecryptfs_msg_ctx_free_to_alloc(*msg_ctx); |
@@ -352,23 +505,50 @@ int ecryptfs_send_message(unsigned int transport, char *data, int data_len, | |||
352 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); | 505 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); |
353 | switch (transport) { | 506 | switch (transport) { |
354 | case ECRYPTFS_TRANSPORT_NETLINK: | 507 | case ECRYPTFS_TRANSPORT_NETLINK: |
355 | rc = ecryptfs_send_netlink(data, data_len, *msg_ctx, | 508 | rc = ecryptfs_send_netlink(data, data_len, *msg_ctx, msg_type, |
356 | ECRYPTFS_NLMSG_REQUEST, 0, id->pid); | 509 | 0, daemon->pid); |
510 | break; | ||
511 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
512 | rc = ecryptfs_send_miscdev(data, data_len, *msg_ctx, msg_type, | ||
513 | 0, daemon); | ||
357 | break; | 514 | break; |
358 | case ECRYPTFS_TRANSPORT_CONNECTOR: | 515 | case ECRYPTFS_TRANSPORT_CONNECTOR: |
359 | case ECRYPTFS_TRANSPORT_RELAYFS: | 516 | case ECRYPTFS_TRANSPORT_RELAYFS: |
360 | default: | 517 | default: |
361 | rc = -ENOSYS; | 518 | rc = -ENOSYS; |
362 | } | 519 | } |
363 | if (rc) { | 520 | if (rc) |
364 | printk(KERN_ERR "Error attempting to send message to userspace " | 521 | printk(KERN_ERR "%s: Error attempting to send message to " |
365 | "daemon; rc = [%d]\n", rc); | 522 | "userspace daemon; rc = [%d]\n", __func__, rc); |
366 | } | ||
367 | out: | 523 | out: |
368 | return rc; | 524 | return rc; |
369 | } | 525 | } |
370 | 526 | ||
371 | /** | 527 | /** |
528 | * ecryptfs_send_message | ||
529 | * @transport: The transport over which to send the message (i.e., | ||
530 | * netlink) | ||
531 | * @data: The data to send | ||
532 | * @data_len: The length of data | ||
533 | * @msg_ctx: The message context allocated for the send | ||
534 | * | ||
535 | * Grabs ecryptfs_daemon_hash_mux. | ||
536 | * | ||
537 | * Returns zero on success; non-zero otherwise | ||
538 | */ | ||
539 | int ecryptfs_send_message(unsigned int transport, char *data, int data_len, | ||
540 | struct ecryptfs_msg_ctx **msg_ctx) | ||
541 | { | ||
542 | int rc; | ||
543 | |||
544 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
545 | rc = ecryptfs_send_message_locked(transport, data, data_len, | ||
546 | ECRYPTFS_MSG_REQUEST, msg_ctx); | ||
547 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
548 | return rc; | ||
549 | } | ||
550 | |||
551 | /** | ||
372 | * ecryptfs_wait_for_response | 552 | * ecryptfs_wait_for_response |
373 | * @msg_ctx: The context that was assigned when sending a message | 553 | * @msg_ctx: The context that was assigned when sending a message |
374 | * @msg: The incoming message from userspace; not set if rc != 0 | 554 | * @msg: The incoming message from userspace; not set if rc != 0 |
@@ -377,7 +557,7 @@ out: | |||
377 | * of time exceeds ecryptfs_message_wait_timeout. If zero is | 557 | * of time exceeds ecryptfs_message_wait_timeout. If zero is |
378 | * returned, msg will point to a valid message from userspace; a | 558 | * returned, msg will point to a valid message from userspace; a |
379 | * non-zero value is returned upon failure to receive a message or an | 559 | * non-zero value is returned upon failure to receive a message or an |
380 | * error occurs. | 560 | * error occurs. Callee must free @msg on success. |
381 | */ | 561 | */ |
382 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, | 562 | int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, |
383 | struct ecryptfs_message **msg) | 563 | struct ecryptfs_message **msg) |
@@ -413,32 +593,32 @@ int ecryptfs_init_messaging(unsigned int transport) | |||
413 | 593 | ||
414 | if (ecryptfs_number_of_users > ECRYPTFS_MAX_NUM_USERS) { | 594 | if (ecryptfs_number_of_users > ECRYPTFS_MAX_NUM_USERS) { |
415 | ecryptfs_number_of_users = ECRYPTFS_MAX_NUM_USERS; | 595 | ecryptfs_number_of_users = ECRYPTFS_MAX_NUM_USERS; |
416 | ecryptfs_printk(KERN_WARNING, "Specified number of users is " | 596 | printk(KERN_WARNING "%s: Specified number of users is " |
417 | "too large, defaulting to [%d] users\n", | 597 | "too large, defaulting to [%d] users\n", __func__, |
418 | ecryptfs_number_of_users); | 598 | ecryptfs_number_of_users); |
419 | } | 599 | } |
420 | mutex_init(&ecryptfs_daemon_id_hash_mux); | 600 | mutex_init(&ecryptfs_daemon_hash_mux); |
421 | mutex_lock(&ecryptfs_daemon_id_hash_mux); | 601 | mutex_lock(&ecryptfs_daemon_hash_mux); |
422 | ecryptfs_hash_buckets = 1; | 602 | ecryptfs_hash_buckets = 1; |
423 | while (ecryptfs_number_of_users >> ecryptfs_hash_buckets) | 603 | while (ecryptfs_number_of_users >> ecryptfs_hash_buckets) |
424 | ecryptfs_hash_buckets++; | 604 | ecryptfs_hash_buckets++; |
425 | ecryptfs_daemon_id_hash = kmalloc(sizeof(struct hlist_head) | 605 | ecryptfs_daemon_hash = kmalloc((sizeof(struct hlist_head) |
426 | * ecryptfs_hash_buckets, GFP_KERNEL); | 606 | * ecryptfs_hash_buckets), GFP_KERNEL); |
427 | if (!ecryptfs_daemon_id_hash) { | 607 | if (!ecryptfs_daemon_hash) { |
428 | rc = -ENOMEM; | 608 | rc = -ENOMEM; |
429 | ecryptfs_printk(KERN_ERR, "Failed to allocate memory\n"); | 609 | printk(KERN_ERR "%s: Failed to allocate memory\n", __func__); |
430 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | 610 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
431 | goto out; | 611 | goto out; |
432 | } | 612 | } |
433 | for (i = 0; i < ecryptfs_hash_buckets; i++) | 613 | for (i = 0; i < ecryptfs_hash_buckets; i++) |
434 | INIT_HLIST_HEAD(&ecryptfs_daemon_id_hash[i]); | 614 | INIT_HLIST_HEAD(&ecryptfs_daemon_hash[i]); |
435 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | 615 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
436 | |||
437 | ecryptfs_msg_ctx_arr = kmalloc((sizeof(struct ecryptfs_msg_ctx) | 616 | ecryptfs_msg_ctx_arr = kmalloc((sizeof(struct ecryptfs_msg_ctx) |
438 | * ecryptfs_message_buf_len), GFP_KERNEL); | 617 | * ecryptfs_message_buf_len), |
618 | GFP_KERNEL); | ||
439 | if (!ecryptfs_msg_ctx_arr) { | 619 | if (!ecryptfs_msg_ctx_arr) { |
440 | rc = -ENOMEM; | 620 | rc = -ENOMEM; |
441 | ecryptfs_printk(KERN_ERR, "Failed to allocate memory\n"); | 621 | printk(KERN_ERR "%s: Failed to allocate memory\n", __func__); |
442 | goto out; | 622 | goto out; |
443 | } | 623 | } |
444 | mutex_init(&ecryptfs_msg_ctx_lists_mux); | 624 | mutex_init(&ecryptfs_msg_ctx_lists_mux); |
@@ -446,6 +626,7 @@ int ecryptfs_init_messaging(unsigned int transport) | |||
446 | ecryptfs_msg_counter = 0; | 626 | ecryptfs_msg_counter = 0; |
447 | for (i = 0; i < ecryptfs_message_buf_len; i++) { | 627 | for (i = 0; i < ecryptfs_message_buf_len; i++) { |
448 | INIT_LIST_HEAD(&ecryptfs_msg_ctx_arr[i].node); | 628 | INIT_LIST_HEAD(&ecryptfs_msg_ctx_arr[i].node); |
629 | INIT_LIST_HEAD(&ecryptfs_msg_ctx_arr[i].daemon_out_list); | ||
449 | mutex_init(&ecryptfs_msg_ctx_arr[i].mux); | 630 | mutex_init(&ecryptfs_msg_ctx_arr[i].mux); |
450 | mutex_lock(&ecryptfs_msg_ctx_arr[i].mux); | 631 | mutex_lock(&ecryptfs_msg_ctx_arr[i].mux); |
451 | ecryptfs_msg_ctx_arr[i].index = i; | 632 | ecryptfs_msg_ctx_arr[i].index = i; |
@@ -464,6 +645,11 @@ int ecryptfs_init_messaging(unsigned int transport) | |||
464 | if (rc) | 645 | if (rc) |
465 | ecryptfs_release_messaging(transport); | 646 | ecryptfs_release_messaging(transport); |
466 | break; | 647 | break; |
648 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
649 | rc = ecryptfs_init_ecryptfs_miscdev(); | ||
650 | if (rc) | ||
651 | ecryptfs_release_messaging(transport); | ||
652 | break; | ||
467 | case ECRYPTFS_TRANSPORT_CONNECTOR: | 653 | case ECRYPTFS_TRANSPORT_CONNECTOR: |
468 | case ECRYPTFS_TRANSPORT_RELAYFS: | 654 | case ECRYPTFS_TRANSPORT_RELAYFS: |
469 | default: | 655 | default: |
@@ -488,27 +674,37 @@ void ecryptfs_release_messaging(unsigned int transport) | |||
488 | kfree(ecryptfs_msg_ctx_arr); | 674 | kfree(ecryptfs_msg_ctx_arr); |
489 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); | 675 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); |
490 | } | 676 | } |
491 | if (ecryptfs_daemon_id_hash) { | 677 | if (ecryptfs_daemon_hash) { |
492 | struct hlist_node *elem; | 678 | struct hlist_node *elem; |
493 | struct ecryptfs_daemon_id *id; | 679 | struct ecryptfs_daemon *daemon; |
494 | int i; | 680 | int i; |
495 | 681 | ||
496 | mutex_lock(&ecryptfs_daemon_id_hash_mux); | 682 | mutex_lock(&ecryptfs_daemon_hash_mux); |
497 | for (i = 0; i < ecryptfs_hash_buckets; i++) { | 683 | for (i = 0; i < ecryptfs_hash_buckets; i++) { |
498 | hlist_for_each_entry(id, elem, | 684 | int rc; |
499 | &ecryptfs_daemon_id_hash[i], | 685 | |
500 | id_chain) { | 686 | hlist_for_each_entry(daemon, elem, |
501 | hlist_del(elem); | 687 | &ecryptfs_daemon_hash[i], |
502 | kfree(id); | 688 | euid_chain) { |
689 | rc = ecryptfs_exorcise_daemon(daemon); | ||
690 | if (rc) | ||
691 | printk(KERN_ERR "%s: Error whilst " | ||
692 | "attempting to destroy daemon; " | ||
693 | "rc = [%d]. Dazed and confused, " | ||
694 | "but trying to continue.\n", | ||
695 | __func__, rc); | ||
503 | } | 696 | } |
504 | } | 697 | } |
505 | kfree(ecryptfs_daemon_id_hash); | 698 | kfree(ecryptfs_daemon_hash); |
506 | mutex_unlock(&ecryptfs_daemon_id_hash_mux); | 699 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
507 | } | 700 | } |
508 | switch(transport) { | 701 | switch(transport) { |
509 | case ECRYPTFS_TRANSPORT_NETLINK: | 702 | case ECRYPTFS_TRANSPORT_NETLINK: |
510 | ecryptfs_release_netlink(); | 703 | ecryptfs_release_netlink(); |
511 | break; | 704 | break; |
705 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
706 | ecryptfs_destroy_ecryptfs_miscdev(); | ||
707 | break; | ||
512 | case ECRYPTFS_TRANSPORT_CONNECTOR: | 708 | case ECRYPTFS_TRANSPORT_CONNECTOR: |
513 | case ECRYPTFS_TRANSPORT_RELAYFS: | 709 | case ECRYPTFS_TRANSPORT_RELAYFS: |
514 | default: | 710 | default: |
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c new file mode 100644 index 000000000000..788995efd1d3 --- /dev/null +++ b/fs/ecryptfs/miscdev.c | |||
@@ -0,0 +1,598 @@ | |||
1 | /** | ||
2 | * eCryptfs: Linux filesystem encryption layer | ||
3 | * | ||
4 | * Copyright (C) 2008 International Business Machines Corp. | ||
5 | * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
19 | * 02111-1307, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/fs.h> | ||
23 | #include <linux/hash.h> | ||
24 | #include <linux/random.h> | ||
25 | #include <linux/miscdevice.h> | ||
26 | #include <linux/poll.h> | ||
27 | #include <linux/wait.h> | ||
28 | #include <linux/module.h> | ||
29 | #include "ecryptfs_kernel.h" | ||
30 | |||
31 | static atomic_t ecryptfs_num_miscdev_opens; | ||
32 | |||
33 | /** | ||
34 | * ecryptfs_miscdev_poll | ||
35 | * @file: dev file (ignored) | ||
36 | * @pt: dev poll table (ignored) | ||
37 | * | ||
38 | * Returns the poll mask | ||
39 | */ | ||
40 | static unsigned int | ||
41 | ecryptfs_miscdev_poll(struct file *file, poll_table *pt) | ||
42 | { | ||
43 | struct ecryptfs_daemon *daemon; | ||
44 | unsigned int mask = 0; | ||
45 | int rc; | ||
46 | |||
47 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
48 | /* TODO: Just use file->private_data? */ | ||
49 | rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid, | ||
50 | current->nsproxy->user_ns); | ||
51 | BUG_ON(rc || !daemon); | ||
52 | mutex_lock(&daemon->mux); | ||
53 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
54 | if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { | ||
55 | printk(KERN_WARNING "%s: Attempt to poll on zombified " | ||
56 | "daemon\n", __func__); | ||
57 | goto out_unlock_daemon; | ||
58 | } | ||
59 | if (daemon->flags & ECRYPTFS_DAEMON_IN_READ) | ||
60 | goto out_unlock_daemon; | ||
61 | if (daemon->flags & ECRYPTFS_DAEMON_IN_POLL) | ||
62 | goto out_unlock_daemon; | ||
63 | daemon->flags |= ECRYPTFS_DAEMON_IN_POLL; | ||
64 | mutex_unlock(&daemon->mux); | ||
65 | poll_wait(file, &daemon->wait, pt); | ||
66 | mutex_lock(&daemon->mux); | ||
67 | if (!list_empty(&daemon->msg_ctx_out_queue)) | ||
68 | mask |= POLLIN | POLLRDNORM; | ||
69 | out_unlock_daemon: | ||
70 | daemon->flags &= ~ECRYPTFS_DAEMON_IN_POLL; | ||
71 | mutex_unlock(&daemon->mux); | ||
72 | return mask; | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * ecryptfs_miscdev_open | ||
77 | * @inode: inode of miscdev handle (ignored) | ||
78 | * @file: file for miscdev handle (ignored) | ||
79 | * | ||
80 | * Returns zero on success; non-zero otherwise | ||
81 | */ | ||
82 | static int | ||
83 | ecryptfs_miscdev_open(struct inode *inode, struct file *file) | ||
84 | { | ||
85 | struct ecryptfs_daemon *daemon = NULL; | ||
86 | int rc; | ||
87 | |||
88 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
89 | rc = try_module_get(THIS_MODULE); | ||
90 | if (rc == 0) { | ||
91 | rc = -EIO; | ||
92 | printk(KERN_ERR "%s: Error attempting to increment module use " | ||
93 | "count; rc = [%d]\n", __func__, rc); | ||
94 | goto out_unlock_daemon_list; | ||
95 | } | ||
96 | rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid, | ||
97 | current->nsproxy->user_ns); | ||
98 | if (rc || !daemon) { | ||
99 | rc = ecryptfs_spawn_daemon(&daemon, current->euid, | ||
100 | current->nsproxy->user_ns, | ||
101 | task_pid(current)); | ||
102 | if (rc) { | ||
103 | printk(KERN_ERR "%s: Error attempting to spawn daemon; " | ||
104 | "rc = [%d]\n", __func__, rc); | ||
105 | goto out_module_put_unlock_daemon_list; | ||
106 | } | ||
107 | } | ||
108 | mutex_lock(&daemon->mux); | ||
109 | if (daemon->pid != task_pid(current)) { | ||
110 | rc = -EINVAL; | ||
111 | printk(KERN_ERR "%s: pid [0x%p] has registered with euid [%d], " | ||
112 | "but pid [0x%p] has attempted to open the handle " | ||
113 | "instead\n", __func__, daemon->pid, daemon->euid, | ||
114 | task_pid(current)); | ||
115 | goto out_unlock_daemon; | ||
116 | } | ||
117 | if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) { | ||
118 | rc = -EBUSY; | ||
119 | printk(KERN_ERR "%s: Miscellaneous device handle may only be " | ||
120 | "opened once per daemon; pid [0x%p] already has this " | ||
121 | "handle open\n", __func__, daemon->pid); | ||
122 | goto out_unlock_daemon; | ||
123 | } | ||
124 | daemon->flags |= ECRYPTFS_DAEMON_MISCDEV_OPEN; | ||
125 | atomic_inc(&ecryptfs_num_miscdev_opens); | ||
126 | out_unlock_daemon: | ||
127 | mutex_unlock(&daemon->mux); | ||
128 | out_module_put_unlock_daemon_list: | ||
129 | if (rc) | ||
130 | module_put(THIS_MODULE); | ||
131 | out_unlock_daemon_list: | ||
132 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
133 | return rc; | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * ecryptfs_miscdev_release | ||
138 | * @inode: inode of fs/ecryptfs/euid handle (ignored) | ||
139 | * @file: file for fs/ecryptfs/euid handle (ignored) | ||
140 | * | ||
141 | * This keeps the daemon registered until the daemon sends another | ||
142 | * ioctl to fs/ecryptfs/ctl or until the kernel module unregisters. | ||
143 | * | ||
144 | * Returns zero on success; non-zero otherwise | ||
145 | */ | ||
146 | static int | ||
147 | ecryptfs_miscdev_release(struct inode *inode, struct file *file) | ||
148 | { | ||
149 | struct ecryptfs_daemon *daemon = NULL; | ||
150 | int rc; | ||
151 | |||
152 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
153 | rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid, | ||
154 | current->nsproxy->user_ns); | ||
155 | BUG_ON(rc || !daemon); | ||
156 | mutex_lock(&daemon->mux); | ||
157 | BUG_ON(daemon->pid != task_pid(current)); | ||
158 | BUG_ON(!(daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN)); | ||
159 | daemon->flags &= ~ECRYPTFS_DAEMON_MISCDEV_OPEN; | ||
160 | atomic_dec(&ecryptfs_num_miscdev_opens); | ||
161 | mutex_unlock(&daemon->mux); | ||
162 | rc = ecryptfs_exorcise_daemon(daemon); | ||
163 | if (rc) { | ||
164 | printk(KERN_CRIT "%s: Fatal error whilst attempting to " | ||
165 | "shut down daemon; rc = [%d]. Please report this " | ||
166 | "bug.\n", __func__, rc); | ||
167 | BUG(); | ||
168 | } | ||
169 | module_put(THIS_MODULE); | ||
170 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
171 | return rc; | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * ecryptfs_send_miscdev | ||
176 | * @data: Data to send to daemon; may be NULL | ||
177 | * @data_size: Amount of data to send to daemon | ||
178 | * @msg_ctx: Message context, which is used to handle the reply. If | ||
179 | * this is NULL, then we do not expect a reply. | ||
180 | * @msg_type: Type of message | ||
181 | * @msg_flags: Flags for message | ||
182 | * @daemon: eCryptfs daemon object | ||
183 | * | ||
184 | * Add msg_ctx to queue and then, if it exists, notify the blocked | ||
185 | * miscdevess about the data being available. Must be called with | ||
186 | * ecryptfs_daemon_hash_mux held. | ||
187 | * | ||
188 | * Returns zero on success; non-zero otherwise | ||
189 | */ | ||
190 | int ecryptfs_send_miscdev(char *data, size_t data_size, | ||
191 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, | ||
192 | u16 msg_flags, struct ecryptfs_daemon *daemon) | ||
193 | { | ||
194 | int rc = 0; | ||
195 | |||
196 | mutex_lock(&msg_ctx->mux); | ||
197 | if (data) { | ||
198 | msg_ctx->msg = kmalloc((sizeof(*msg_ctx->msg) + data_size), | ||
199 | GFP_KERNEL); | ||
200 | if (!msg_ctx->msg) { | ||
201 | rc = -ENOMEM; | ||
202 | printk(KERN_ERR "%s: Out of memory whilst attempting " | ||
203 | "to kmalloc(%Zd, GFP_KERNEL)\n", __func__, | ||
204 | (sizeof(*msg_ctx->msg) + data_size)); | ||
205 | goto out_unlock; | ||
206 | } | ||
207 | } else | ||
208 | msg_ctx->msg = NULL; | ||
209 | msg_ctx->msg->index = msg_ctx->index; | ||
210 | msg_ctx->msg->data_len = data_size; | ||
211 | msg_ctx->type = msg_type; | ||
212 | if (data) { | ||
213 | memcpy(msg_ctx->msg->data, data, data_size); | ||
214 | msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size); | ||
215 | } else | ||
216 | msg_ctx->msg_size = 0; | ||
217 | mutex_lock(&daemon->mux); | ||
218 | list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); | ||
219 | daemon->num_queued_msg_ctx++; | ||
220 | wake_up_interruptible(&daemon->wait); | ||
221 | mutex_unlock(&daemon->mux); | ||
222 | out_unlock: | ||
223 | mutex_unlock(&msg_ctx->mux); | ||
224 | return rc; | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * ecryptfs_miscdev_read - format and send message from queue | ||
229 | * @file: fs/ecryptfs/euid miscdevfs handle (ignored) | ||
230 | * @buf: User buffer into which to copy the next message on the daemon queue | ||
231 | * @count: Amount of space available in @buf | ||
232 | * @ppos: Offset in file (ignored) | ||
233 | * | ||
234 | * Pulls the most recent message from the daemon queue, formats it for | ||
235 | * being sent via a miscdevfs handle, and copies it into @buf | ||
236 | * | ||
237 | * Returns the number of bytes copied into the user buffer | ||
238 | */ | ||
239 | static ssize_t | ||
240 | ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count, | ||
241 | loff_t *ppos) | ||
242 | { | ||
243 | struct ecryptfs_daemon *daemon; | ||
244 | struct ecryptfs_msg_ctx *msg_ctx; | ||
245 | size_t packet_length_size; | ||
246 | u32 counter_nbo; | ||
247 | char packet_length[3]; | ||
248 | size_t i; | ||
249 | size_t total_length; | ||
250 | int rc; | ||
251 | |||
252 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
253 | /* TODO: Just use file->private_data? */ | ||
254 | rc = ecryptfs_find_daemon_by_euid(&daemon, current->euid, | ||
255 | current->nsproxy->user_ns); | ||
256 | BUG_ON(rc || !daemon); | ||
257 | mutex_lock(&daemon->mux); | ||
258 | if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { | ||
259 | rc = 0; | ||
260 | printk(KERN_WARNING "%s: Attempt to read from zombified " | ||
261 | "daemon\n", __func__); | ||
262 | goto out_unlock_daemon; | ||
263 | } | ||
264 | if (daemon->flags & ECRYPTFS_DAEMON_IN_READ) { | ||
265 | rc = 0; | ||
266 | goto out_unlock_daemon; | ||
267 | } | ||
268 | /* This daemon will not go away so long as this flag is set */ | ||
269 | daemon->flags |= ECRYPTFS_DAEMON_IN_READ; | ||
270 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
271 | check_list: | ||
272 | if (list_empty(&daemon->msg_ctx_out_queue)) { | ||
273 | mutex_unlock(&daemon->mux); | ||
274 | rc = wait_event_interruptible( | ||
275 | daemon->wait, !list_empty(&daemon->msg_ctx_out_queue)); | ||
276 | mutex_lock(&daemon->mux); | ||
277 | if (rc < 0) { | ||
278 | rc = 0; | ||
279 | goto out_unlock_daemon; | ||
280 | } | ||
281 | } | ||
282 | if (daemon->flags & ECRYPTFS_DAEMON_ZOMBIE) { | ||
283 | rc = 0; | ||
284 | goto out_unlock_daemon; | ||
285 | } | ||
286 | if (list_empty(&daemon->msg_ctx_out_queue)) { | ||
287 | /* Something else jumped in since the | ||
288 | * wait_event_interruptable() and removed the | ||
289 | * message from the queue; try again */ | ||
290 | goto check_list; | ||
291 | } | ||
292 | BUG_ON(current->euid != daemon->euid); | ||
293 | BUG_ON(current->nsproxy->user_ns != daemon->user_ns); | ||
294 | BUG_ON(task_pid(current) != daemon->pid); | ||
295 | msg_ctx = list_first_entry(&daemon->msg_ctx_out_queue, | ||
296 | struct ecryptfs_msg_ctx, daemon_out_list); | ||
297 | BUG_ON(!msg_ctx); | ||
298 | mutex_lock(&msg_ctx->mux); | ||
299 | if (msg_ctx->msg) { | ||
300 | rc = ecryptfs_write_packet_length(packet_length, | ||
301 | msg_ctx->msg_size, | ||
302 | &packet_length_size); | ||
303 | if (rc) { | ||
304 | rc = 0; | ||
305 | printk(KERN_WARNING "%s: Error writing packet length; " | ||
306 | "rc = [%d]\n", __func__, rc); | ||
307 | goto out_unlock_msg_ctx; | ||
308 | } | ||
309 | } else { | ||
310 | packet_length_size = 0; | ||
311 | msg_ctx->msg_size = 0; | ||
312 | } | ||
313 | /* miscdevfs packet format: | ||
314 | * Octet 0: Type | ||
315 | * Octets 1-4: network byte order msg_ctx->counter | ||
316 | * Octets 5-N0: Size of struct ecryptfs_message to follow | ||
317 | * Octets N0-N1: struct ecryptfs_message (including data) | ||
318 | * | ||
319 | * Octets 5-N1 not written if the packet type does not | ||
320 | * include a message */ | ||
321 | total_length = (1 + 4 + packet_length_size + msg_ctx->msg_size); | ||
322 | if (count < total_length) { | ||
323 | rc = 0; | ||
324 | printk(KERN_WARNING "%s: Only given user buffer of " | ||
325 | "size [%Zd], but we need [%Zd] to read the " | ||
326 | "pending message\n", __func__, count, total_length); | ||
327 | goto out_unlock_msg_ctx; | ||
328 | } | ||
329 | i = 0; | ||
330 | buf[i++] = msg_ctx->type; | ||
331 | counter_nbo = cpu_to_be32(msg_ctx->counter); | ||
332 | memcpy(&buf[i], (char *)&counter_nbo, 4); | ||
333 | i += 4; | ||
334 | if (msg_ctx->msg) { | ||
335 | memcpy(&buf[i], packet_length, packet_length_size); | ||
336 | i += packet_length_size; | ||
337 | rc = copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size); | ||
338 | if (rc) { | ||
339 | printk(KERN_ERR "%s: copy_to_user returned error " | ||
340 | "[%d]\n", __func__, rc); | ||
341 | goto out_unlock_msg_ctx; | ||
342 | } | ||
343 | i += msg_ctx->msg_size; | ||
344 | } | ||
345 | rc = i; | ||
346 | list_del(&msg_ctx->daemon_out_list); | ||
347 | kfree(msg_ctx->msg); | ||
348 | msg_ctx->msg = NULL; | ||
349 | /* We do not expect a reply from the userspace daemon for any | ||
350 | * message type other than ECRYPTFS_MSG_REQUEST */ | ||
351 | if (msg_ctx->type != ECRYPTFS_MSG_REQUEST) | ||
352 | ecryptfs_msg_ctx_alloc_to_free(msg_ctx); | ||
353 | out_unlock_msg_ctx: | ||
354 | mutex_unlock(&msg_ctx->mux); | ||
355 | out_unlock_daemon: | ||
356 | daemon->flags &= ~ECRYPTFS_DAEMON_IN_READ; | ||
357 | mutex_unlock(&daemon->mux); | ||
358 | return rc; | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * ecryptfs_miscdev_helo | ||
363 | * @euid: effective user id of miscdevess sending helo packet | ||
364 | * @user_ns: The namespace in which @euid applies | ||
365 | * @pid: miscdevess id of miscdevess sending helo packet | ||
366 | * | ||
367 | * Returns zero on success; non-zero otherwise | ||
368 | */ | ||
369 | static int ecryptfs_miscdev_helo(uid_t euid, struct user_namespace *user_ns, | ||
370 | struct pid *pid) | ||
371 | { | ||
372 | int rc; | ||
373 | |||
374 | rc = ecryptfs_process_helo(ECRYPTFS_TRANSPORT_MISCDEV, euid, user_ns, | ||
375 | pid); | ||
376 | if (rc) | ||
377 | printk(KERN_WARNING "Error processing HELO; rc = [%d]\n", rc); | ||
378 | return rc; | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * ecryptfs_miscdev_quit | ||
383 | * @euid: effective user id of miscdevess sending quit packet | ||
384 | * @user_ns: The namespace in which @euid applies | ||
385 | * @pid: miscdevess id of miscdevess sending quit packet | ||
386 | * | ||
387 | * Returns zero on success; non-zero otherwise | ||
388 | */ | ||
389 | static int ecryptfs_miscdev_quit(uid_t euid, struct user_namespace *user_ns, | ||
390 | struct pid *pid) | ||
391 | { | ||
392 | int rc; | ||
393 | |||
394 | rc = ecryptfs_process_quit(euid, user_ns, pid); | ||
395 | if (rc) | ||
396 | printk(KERN_WARNING | ||
397 | "Error processing QUIT message; rc = [%d]\n", rc); | ||
398 | return rc; | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * ecryptfs_miscdev_response - miscdevess response to message previously sent to daemon | ||
403 | * @data: Bytes comprising struct ecryptfs_message | ||
404 | * @data_size: sizeof(struct ecryptfs_message) + data len | ||
405 | * @euid: Effective user id of miscdevess sending the miscdev response | ||
406 | * @user_ns: The namespace in which @euid applies | ||
407 | * @pid: Miscdevess id of miscdevess sending the miscdev response | ||
408 | * @seq: Sequence number for miscdev response packet | ||
409 | * | ||
410 | * Returns zero on success; non-zero otherwise | ||
411 | */ | ||
412 | static int ecryptfs_miscdev_response(char *data, size_t data_size, | ||
413 | uid_t euid, struct user_namespace *user_ns, | ||
414 | struct pid *pid, u32 seq) | ||
415 | { | ||
416 | struct ecryptfs_message *msg = (struct ecryptfs_message *)data; | ||
417 | int rc; | ||
418 | |||
419 | if ((sizeof(*msg) + msg->data_len) != data_size) { | ||
420 | printk(KERN_WARNING "%s: (sizeof(*msg) + msg->data_len) = " | ||
421 | "[%Zd]; data_size = [%Zd]. Invalid packet.\n", __func__, | ||
422 | (sizeof(*msg) + msg->data_len), data_size); | ||
423 | rc = -EINVAL; | ||
424 | goto out; | ||
425 | } | ||
426 | rc = ecryptfs_process_response(msg, euid, user_ns, pid, seq); | ||
427 | if (rc) | ||
428 | printk(KERN_ERR | ||
429 | "Error processing response message; rc = [%d]\n", rc); | ||
430 | out: | ||
431 | return rc; | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * ecryptfs_miscdev_write - handle write to daemon miscdev handle | ||
436 | * @file: File for misc dev handle (ignored) | ||
437 | * @buf: Buffer containing user data | ||
438 | * @count: Amount of data in @buf | ||
439 | * @ppos: Pointer to offset in file (ignored) | ||
440 | * | ||
441 | * miscdevfs packet format: | ||
442 | * Octet 0: Type | ||
443 | * Octets 1-4: network byte order msg_ctx->counter (0's for non-response) | ||
444 | * Octets 5-N0: Size of struct ecryptfs_message to follow | ||
445 | * Octets N0-N1: struct ecryptfs_message (including data) | ||
446 | * | ||
447 | * Returns the number of bytes read from @buf | ||
448 | */ | ||
449 | static ssize_t | ||
450 | ecryptfs_miscdev_write(struct file *file, const char __user *buf, | ||
451 | size_t count, loff_t *ppos) | ||
452 | { | ||
453 | u32 counter_nbo, seq; | ||
454 | size_t packet_size, packet_size_length, i; | ||
455 | ssize_t sz = 0; | ||
456 | char *data; | ||
457 | int rc; | ||
458 | |||
459 | if (count == 0) | ||
460 | goto out; | ||
461 | data = kmalloc(count, GFP_KERNEL); | ||
462 | if (!data) { | ||
463 | printk(KERN_ERR "%s: Out of memory whilst attempting to " | ||
464 | "kmalloc([%Zd], GFP_KERNEL)\n", __func__, count); | ||
465 | goto out; | ||
466 | } | ||
467 | rc = copy_from_user(data, buf, count); | ||
468 | if (rc) { | ||
469 | printk(KERN_ERR "%s: copy_from_user returned error [%d]\n", | ||
470 | __func__, rc); | ||
471 | goto out_free; | ||
472 | } | ||
473 | sz = count; | ||
474 | i = 0; | ||
475 | switch (data[i++]) { | ||
476 | case ECRYPTFS_MSG_RESPONSE: | ||
477 | if (count < (1 + 4 + 1 + sizeof(struct ecryptfs_message))) { | ||
478 | printk(KERN_WARNING "%s: Minimum acceptable packet " | ||
479 | "size is [%Zd], but amount of data written is " | ||
480 | "only [%Zd]. Discarding response packet.\n", | ||
481 | __func__, | ||
482 | (1 + 4 + 1 + sizeof(struct ecryptfs_message)), | ||
483 | count); | ||
484 | goto out_free; | ||
485 | } | ||
486 | memcpy((char *)&counter_nbo, &data[i], 4); | ||
487 | seq = be32_to_cpu(counter_nbo); | ||
488 | i += 4; | ||
489 | rc = ecryptfs_parse_packet_length(&data[i], &packet_size, | ||
490 | &packet_size_length); | ||
491 | if (rc) { | ||
492 | printk(KERN_WARNING "%s: Error parsing packet length; " | ||
493 | "rc = [%d]\n", __func__, rc); | ||
494 | goto out_free; | ||
495 | } | ||
496 | i += packet_size_length; | ||
497 | if ((1 + 4 + packet_size_length + packet_size) != count) { | ||
498 | printk(KERN_WARNING "%s: (1 + packet_size_length([%Zd])" | ||
499 | " + packet_size([%Zd]))([%Zd]) != " | ||
500 | "count([%Zd]). Invalid packet format.\n", | ||
501 | __func__, packet_size_length, packet_size, | ||
502 | (1 + packet_size_length + packet_size), count); | ||
503 | goto out_free; | ||
504 | } | ||
505 | rc = ecryptfs_miscdev_response(&data[i], packet_size, | ||
506 | current->euid, | ||
507 | current->nsproxy->user_ns, | ||
508 | task_pid(current), seq); | ||
509 | if (rc) | ||
510 | printk(KERN_WARNING "%s: Failed to deliver miscdev " | ||
511 | "response to requesting operation; rc = [%d]\n", | ||
512 | __func__, rc); | ||
513 | break; | ||
514 | case ECRYPTFS_MSG_HELO: | ||
515 | rc = ecryptfs_miscdev_helo(current->euid, | ||
516 | current->nsproxy->user_ns, | ||
517 | task_pid(current)); | ||
518 | if (rc) { | ||
519 | printk(KERN_ERR "%s: Error attempting to process " | ||
520 | "helo from pid [0x%p]; rc = [%d]\n", __func__, | ||
521 | task_pid(current), rc); | ||
522 | goto out_free; | ||
523 | } | ||
524 | break; | ||
525 | case ECRYPTFS_MSG_QUIT: | ||
526 | rc = ecryptfs_miscdev_quit(current->euid, | ||
527 | current->nsproxy->user_ns, | ||
528 | task_pid(current)); | ||
529 | if (rc) { | ||
530 | printk(KERN_ERR "%s: Error attempting to process " | ||
531 | "quit from pid [0x%p]; rc = [%d]\n", __func__, | ||
532 | task_pid(current), rc); | ||
533 | goto out_free; | ||
534 | } | ||
535 | break; | ||
536 | default: | ||
537 | ecryptfs_printk(KERN_WARNING, "Dropping miscdev " | ||
538 | "message of unrecognized type [%d]\n", | ||
539 | data[0]); | ||
540 | break; | ||
541 | } | ||
542 | out_free: | ||
543 | kfree(data); | ||
544 | out: | ||
545 | return sz; | ||
546 | } | ||
547 | |||
548 | |||
549 | static const struct file_operations ecryptfs_miscdev_fops = { | ||
550 | .open = ecryptfs_miscdev_open, | ||
551 | .poll = ecryptfs_miscdev_poll, | ||
552 | .read = ecryptfs_miscdev_read, | ||
553 | .write = ecryptfs_miscdev_write, | ||
554 | .release = ecryptfs_miscdev_release, | ||
555 | }; | ||
556 | |||
557 | static struct miscdevice ecryptfs_miscdev = { | ||
558 | .minor = MISC_DYNAMIC_MINOR, | ||
559 | .name = "ecryptfs", | ||
560 | .fops = &ecryptfs_miscdev_fops | ||
561 | }; | ||
562 | |||
563 | /** | ||
564 | * ecryptfs_init_ecryptfs_miscdev | ||
565 | * | ||
566 | * Messages sent to the userspace daemon from the kernel are placed on | ||
567 | * a queue associated with the daemon. The next read against the | ||
568 | * miscdev handle by that daemon will return the oldest message placed | ||
569 | * on the message queue for the daemon. | ||
570 | * | ||
571 | * Returns zero on success; non-zero otherwise | ||
572 | */ | ||
573 | int ecryptfs_init_ecryptfs_miscdev(void) | ||
574 | { | ||
575 | int rc; | ||
576 | |||
577 | atomic_set(&ecryptfs_num_miscdev_opens, 0); | ||
578 | mutex_lock(&ecryptfs_daemon_hash_mux); | ||
579 | rc = misc_register(&ecryptfs_miscdev); | ||
580 | if (rc) | ||
581 | printk(KERN_ERR "%s: Failed to register miscellaneous device " | ||
582 | "for communications with userspace daemons; rc = [%d]\n", | ||
583 | __func__, rc); | ||
584 | mutex_unlock(&ecryptfs_daemon_hash_mux); | ||
585 | return rc; | ||
586 | } | ||
587 | |||
588 | /** | ||
589 | * ecryptfs_destroy_ecryptfs_miscdev | ||
590 | * | ||
591 | * All of the daemons must be exorcised prior to calling this | ||
592 | * function. | ||
593 | */ | ||
594 | void ecryptfs_destroy_ecryptfs_miscdev(void) | ||
595 | { | ||
596 | BUG_ON(atomic_read(&ecryptfs_num_miscdev_opens) != 0); | ||
597 | misc_deregister(&ecryptfs_miscdev); | ||
598 | } | ||
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 6df1debdccce..2b6fe1e6e8ba 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c | |||
@@ -153,7 +153,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, | |||
153 | flush_dcache_page(page); | 153 | flush_dcache_page(page); |
154 | if (rc) { | 154 | if (rc) { |
155 | printk(KERN_ERR "%s: Error reading xattr " | 155 | printk(KERN_ERR "%s: Error reading xattr " |
156 | "region; rc = [%d]\n", __FUNCTION__, rc); | 156 | "region; rc = [%d]\n", __func__, rc); |
157 | goto out; | 157 | goto out; |
158 | } | 158 | } |
159 | } else { | 159 | } else { |
@@ -169,7 +169,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, | |||
169 | if (rc) { | 169 | if (rc) { |
170 | printk(KERN_ERR "%s: Error attempting to read " | 170 | printk(KERN_ERR "%s: Error attempting to read " |
171 | "extent at offset [%lld] in the lower " | 171 | "extent at offset [%lld] in the lower " |
172 | "file; rc = [%d]\n", __FUNCTION__, | 172 | "file; rc = [%d]\n", __func__, |
173 | lower_offset, rc); | 173 | lower_offset, rc); |
174 | goto out; | 174 | goto out; |
175 | } | 175 | } |
@@ -212,7 +212,7 @@ static int ecryptfs_readpage(struct file *file, struct page *page) | |||
212 | "the encrypted content from the lower " | 212 | "the encrypted content from the lower " |
213 | "file whilst inserting the metadata " | 213 | "file whilst inserting the metadata " |
214 | "from the xattr into the header; rc = " | 214 | "from the xattr into the header; rc = " |
215 | "[%d]\n", __FUNCTION__, rc); | 215 | "[%d]\n", __func__, rc); |
216 | goto out; | 216 | goto out; |
217 | } | 217 | } |
218 | 218 | ||
@@ -293,7 +293,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page, | |||
293 | if (rc) { | 293 | if (rc) { |
294 | printk(KERN_ERR "%s: Error attemping to read " | 294 | printk(KERN_ERR "%s: Error attemping to read " |
295 | "lower page segment; rc = [%d]\n", | 295 | "lower page segment; rc = [%d]\n", |
296 | __FUNCTION__, rc); | 296 | __func__, rc); |
297 | ClearPageUptodate(page); | 297 | ClearPageUptodate(page); |
298 | goto out; | 298 | goto out; |
299 | } else | 299 | } else |
@@ -308,7 +308,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page, | |||
308 | "from the lower file whilst " | 308 | "from the lower file whilst " |
309 | "inserting the metadata from " | 309 | "inserting the metadata from " |
310 | "the xattr into the header; rc " | 310 | "the xattr into the header; rc " |
311 | "= [%d]\n", __FUNCTION__, rc); | 311 | "= [%d]\n", __func__, rc); |
312 | ClearPageUptodate(page); | 312 | ClearPageUptodate(page); |
313 | goto out; | 313 | goto out; |
314 | } | 314 | } |
@@ -320,7 +320,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page, | |||
320 | if (rc) { | 320 | if (rc) { |
321 | printk(KERN_ERR "%s: Error reading " | 321 | printk(KERN_ERR "%s: Error reading " |
322 | "page; rc = [%d]\n", | 322 | "page; rc = [%d]\n", |
323 | __FUNCTION__, rc); | 323 | __func__, rc); |
324 | ClearPageUptodate(page); | 324 | ClearPageUptodate(page); |
325 | goto out; | 325 | goto out; |
326 | } | 326 | } |
@@ -331,7 +331,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page, | |||
331 | if (rc) { | 331 | if (rc) { |
332 | printk(KERN_ERR "%s: Error decrypting page " | 332 | printk(KERN_ERR "%s: Error decrypting page " |
333 | "at index [%ld]; rc = [%d]\n", | 333 | "at index [%ld]; rc = [%d]\n", |
334 | __FUNCTION__, page->index, rc); | 334 | __func__, page->index, rc); |
335 | ClearPageUptodate(page); | 335 | ClearPageUptodate(page); |
336 | goto out; | 336 | goto out; |
337 | } | 337 | } |
@@ -348,7 +348,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page, | |||
348 | if (rc) { | 348 | if (rc) { |
349 | printk(KERN_ERR "%s: Error on attempt to " | 349 | printk(KERN_ERR "%s: Error on attempt to " |
350 | "truncate to (higher) offset [%lld];" | 350 | "truncate to (higher) offset [%lld];" |
351 | " rc = [%d]\n", __FUNCTION__, | 351 | " rc = [%d]\n", __func__, |
352 | prev_page_end_size, rc); | 352 | prev_page_end_size, rc); |
353 | goto out; | 353 | goto out; |
354 | } | 354 | } |
@@ -389,7 +389,7 @@ static int ecryptfs_write_inode_size_to_header(struct inode *ecryptfs_inode) | |||
389 | kfree(file_size_virt); | 389 | kfree(file_size_virt); |
390 | if (rc) | 390 | if (rc) |
391 | printk(KERN_ERR "%s: Error writing file size to header; " | 391 | printk(KERN_ERR "%s: Error writing file size to header; " |
392 | "rc = [%d]\n", __FUNCTION__, rc); | 392 | "rc = [%d]\n", __func__, rc); |
393 | out: | 393 | out: |
394 | return rc; | 394 | return rc; |
395 | } | 395 | } |
diff --git a/fs/ecryptfs/netlink.c b/fs/ecryptfs/netlink.c index f638a698dc52..e0abad62b395 100644 --- a/fs/ecryptfs/netlink.c +++ b/fs/ecryptfs/netlink.c | |||
@@ -44,8 +44,8 @@ static struct sock *ecryptfs_nl_sock; | |||
44 | * upon sending the message; non-zero upon error. | 44 | * upon sending the message; non-zero upon error. |
45 | */ | 45 | */ |
46 | int ecryptfs_send_netlink(char *data, int data_len, | 46 | int ecryptfs_send_netlink(char *data, int data_len, |
47 | struct ecryptfs_msg_ctx *msg_ctx, u16 msg_type, | 47 | struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type, |
48 | u16 msg_flags, pid_t daemon_pid) | 48 | u16 msg_flags, struct pid *daemon_pid) |
49 | { | 49 | { |
50 | struct sk_buff *skb; | 50 | struct sk_buff *skb; |
51 | struct nlmsghdr *nlh; | 51 | struct nlmsghdr *nlh; |
@@ -60,7 +60,7 @@ int ecryptfs_send_netlink(char *data, int data_len, | |||
60 | ecryptfs_printk(KERN_ERR, "Failed to allocate socket buffer\n"); | 60 | ecryptfs_printk(KERN_ERR, "Failed to allocate socket buffer\n"); |
61 | goto out; | 61 | goto out; |
62 | } | 62 | } |
63 | nlh = NLMSG_PUT(skb, daemon_pid, msg_ctx ? msg_ctx->counter : 0, | 63 | nlh = NLMSG_PUT(skb, pid_nr(daemon_pid), msg_ctx ? msg_ctx->counter : 0, |
64 | msg_type, payload_len); | 64 | msg_type, payload_len); |
65 | nlh->nlmsg_flags = msg_flags; | 65 | nlh->nlmsg_flags = msg_flags; |
66 | if (msg_ctx && payload_len) { | 66 | if (msg_ctx && payload_len) { |
@@ -69,7 +69,7 @@ int ecryptfs_send_netlink(char *data, int data_len, | |||
69 | msg->data_len = data_len; | 69 | msg->data_len = data_len; |
70 | memcpy(msg->data, data, data_len); | 70 | memcpy(msg->data, data, data_len); |
71 | } | 71 | } |
72 | rc = netlink_unicast(ecryptfs_nl_sock, skb, daemon_pid, 0); | 72 | rc = netlink_unicast(ecryptfs_nl_sock, skb, pid_nr(daemon_pid), 0); |
73 | if (rc < 0) { | 73 | if (rc < 0) { |
74 | ecryptfs_printk(KERN_ERR, "Failed to send eCryptfs netlink " | 74 | ecryptfs_printk(KERN_ERR, "Failed to send eCryptfs netlink " |
75 | "message; rc = [%d]\n", rc); | 75 | "message; rc = [%d]\n", rc); |
@@ -99,6 +99,7 @@ static int ecryptfs_process_nl_response(struct sk_buff *skb) | |||
99 | { | 99 | { |
100 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | 100 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
101 | struct ecryptfs_message *msg = NLMSG_DATA(nlh); | 101 | struct ecryptfs_message *msg = NLMSG_DATA(nlh); |
102 | struct pid *pid; | ||
102 | int rc; | 103 | int rc; |
103 | 104 | ||
104 | if (skb->len - NLMSG_HDRLEN - sizeof(*msg) != msg->data_len) { | 105 | if (skb->len - NLMSG_HDRLEN - sizeof(*msg) != msg->data_len) { |
@@ -107,8 +108,10 @@ static int ecryptfs_process_nl_response(struct sk_buff *skb) | |||
107 | "incorrectly specified data length\n"); | 108 | "incorrectly specified data length\n"); |
108 | goto out; | 109 | goto out; |
109 | } | 110 | } |
110 | rc = ecryptfs_process_response(msg, NETLINK_CREDS(skb)->uid, | 111 | pid = find_get_pid(NETLINK_CREDS(skb)->pid); |
111 | NETLINK_CREDS(skb)->pid, nlh->nlmsg_seq); | 112 | rc = ecryptfs_process_response(msg, NETLINK_CREDS(skb)->uid, NULL, |
113 | pid, nlh->nlmsg_seq); | ||
114 | put_pid(pid); | ||
112 | if (rc) | 115 | if (rc) |
113 | printk(KERN_ERR | 116 | printk(KERN_ERR |
114 | "Error processing response message; rc = [%d]\n", rc); | 117 | "Error processing response message; rc = [%d]\n", rc); |
@@ -126,11 +129,13 @@ out: | |||
126 | */ | 129 | */ |
127 | static int ecryptfs_process_nl_helo(struct sk_buff *skb) | 130 | static int ecryptfs_process_nl_helo(struct sk_buff *skb) |
128 | { | 131 | { |
132 | struct pid *pid; | ||
129 | int rc; | 133 | int rc; |
130 | 134 | ||
135 | pid = find_get_pid(NETLINK_CREDS(skb)->pid); | ||
131 | rc = ecryptfs_process_helo(ECRYPTFS_TRANSPORT_NETLINK, | 136 | rc = ecryptfs_process_helo(ECRYPTFS_TRANSPORT_NETLINK, |
132 | NETLINK_CREDS(skb)->uid, | 137 | NETLINK_CREDS(skb)->uid, NULL, pid); |
133 | NETLINK_CREDS(skb)->pid); | 138 | put_pid(pid); |
134 | if (rc) | 139 | if (rc) |
135 | printk(KERN_WARNING "Error processing HELO; rc = [%d]\n", rc); | 140 | printk(KERN_WARNING "Error processing HELO; rc = [%d]\n", rc); |
136 | return rc; | 141 | return rc; |
@@ -147,10 +152,12 @@ static int ecryptfs_process_nl_helo(struct sk_buff *skb) | |||
147 | */ | 152 | */ |
148 | static int ecryptfs_process_nl_quit(struct sk_buff *skb) | 153 | static int ecryptfs_process_nl_quit(struct sk_buff *skb) |
149 | { | 154 | { |
155 | struct pid *pid; | ||
150 | int rc; | 156 | int rc; |
151 | 157 | ||
152 | rc = ecryptfs_process_quit(NETLINK_CREDS(skb)->uid, | 158 | pid = find_get_pid(NETLINK_CREDS(skb)->pid); |
153 | NETLINK_CREDS(skb)->pid); | 159 | rc = ecryptfs_process_quit(NETLINK_CREDS(skb)->uid, NULL, pid); |
160 | put_pid(pid); | ||
154 | if (rc) | 161 | if (rc) |
155 | printk(KERN_WARNING | 162 | printk(KERN_WARNING |
156 | "Error processing QUIT message; rc = [%d]\n", rc); | 163 | "Error processing QUIT message; rc = [%d]\n", rc); |
@@ -176,20 +183,20 @@ static void ecryptfs_receive_nl_message(struct sk_buff *skb) | |||
176 | goto free; | 183 | goto free; |
177 | } | 184 | } |
178 | switch (nlh->nlmsg_type) { | 185 | switch (nlh->nlmsg_type) { |
179 | case ECRYPTFS_NLMSG_RESPONSE: | 186 | case ECRYPTFS_MSG_RESPONSE: |
180 | if (ecryptfs_process_nl_response(skb)) { | 187 | if (ecryptfs_process_nl_response(skb)) { |
181 | ecryptfs_printk(KERN_WARNING, "Failed to " | 188 | ecryptfs_printk(KERN_WARNING, "Failed to " |
182 | "deliver netlink response to " | 189 | "deliver netlink response to " |
183 | "requesting operation\n"); | 190 | "requesting operation\n"); |
184 | } | 191 | } |
185 | break; | 192 | break; |
186 | case ECRYPTFS_NLMSG_HELO: | 193 | case ECRYPTFS_MSG_HELO: |
187 | if (ecryptfs_process_nl_helo(skb)) { | 194 | if (ecryptfs_process_nl_helo(skb)) { |
188 | ecryptfs_printk(KERN_WARNING, "Failed to " | 195 | ecryptfs_printk(KERN_WARNING, "Failed to " |
189 | "fulfill HELO request\n"); | 196 | "fulfill HELO request\n"); |
190 | } | 197 | } |
191 | break; | 198 | break; |
192 | case ECRYPTFS_NLMSG_QUIT: | 199 | case ECRYPTFS_MSG_QUIT: |
193 | if (ecryptfs_process_nl_quit(skb)) { | 200 | if (ecryptfs_process_nl_quit(skb)) { |
194 | ecryptfs_printk(KERN_WARNING, "Failed to " | 201 | ecryptfs_printk(KERN_WARNING, "Failed to " |
195 | "fulfill QUIT request\n"); | 202 | "fulfill QUIT request\n"); |
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 0c4928623bbc..ebf55150be56 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c | |||
@@ -55,7 +55,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, | |||
55 | set_fs(fs_save); | 55 | set_fs(fs_save); |
56 | if (octets_written < 0) { | 56 | if (octets_written < 0) { |
57 | printk(KERN_ERR "%s: octets_written = [%td]; " | 57 | printk(KERN_ERR "%s: octets_written = [%td]; " |
58 | "expected [%td]\n", __FUNCTION__, octets_written, size); | 58 | "expected [%td]\n", __func__, octets_written, size); |
59 | rc = -EINVAL; | 59 | rc = -EINVAL; |
60 | } | 60 | } |
61 | mutex_unlock(&inode_info->lower_file_mutex); | 61 | mutex_unlock(&inode_info->lower_file_mutex); |
@@ -153,7 +153,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
153 | rc = PTR_ERR(ecryptfs_page); | 153 | rc = PTR_ERR(ecryptfs_page); |
154 | printk(KERN_ERR "%s: Error getting page at " | 154 | printk(KERN_ERR "%s: Error getting page at " |
155 | "index [%ld] from eCryptfs inode " | 155 | "index [%ld] from eCryptfs inode " |
156 | "mapping; rc = [%d]\n", __FUNCTION__, | 156 | "mapping; rc = [%d]\n", __func__, |
157 | ecryptfs_page_idx, rc); | 157 | ecryptfs_page_idx, rc); |
158 | goto out; | 158 | goto out; |
159 | } | 159 | } |
@@ -165,7 +165,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
165 | if (rc) { | 165 | if (rc) { |
166 | printk(KERN_ERR "%s: Error decrypting " | 166 | printk(KERN_ERR "%s: Error decrypting " |
167 | "page; rc = [%d]\n", | 167 | "page; rc = [%d]\n", |
168 | __FUNCTION__, rc); | 168 | __func__, rc); |
169 | ClearPageUptodate(ecryptfs_page); | 169 | ClearPageUptodate(ecryptfs_page); |
170 | page_cache_release(ecryptfs_page); | 170 | page_cache_release(ecryptfs_page); |
171 | goto out; | 171 | goto out; |
@@ -202,7 +202,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
202 | page_cache_release(ecryptfs_page); | 202 | page_cache_release(ecryptfs_page); |
203 | if (rc) { | 203 | if (rc) { |
204 | printk(KERN_ERR "%s: Error encrypting " | 204 | printk(KERN_ERR "%s: Error encrypting " |
205 | "page; rc = [%d]\n", __FUNCTION__, rc); | 205 | "page; rc = [%d]\n", __func__, rc); |
206 | goto out; | 206 | goto out; |
207 | } | 207 | } |
208 | pos += num_bytes; | 208 | pos += num_bytes; |
@@ -254,7 +254,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | |||
254 | set_fs(fs_save); | 254 | set_fs(fs_save); |
255 | if (octets_read < 0) { | 255 | if (octets_read < 0) { |
256 | printk(KERN_ERR "%s: octets_read = [%td]; " | 256 | printk(KERN_ERR "%s: octets_read = [%td]; " |
257 | "expected [%td]\n", __FUNCTION__, octets_read, size); | 257 | "expected [%td]\n", __func__, octets_read, size); |
258 | rc = -EINVAL; | 258 | rc = -EINVAL; |
259 | } | 259 | } |
260 | mutex_unlock(&inode_info->lower_file_mutex); | 260 | mutex_unlock(&inode_info->lower_file_mutex); |
@@ -327,7 +327,7 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
327 | printk(KERN_ERR "%s: Attempt to read data past the end of the " | 327 | printk(KERN_ERR "%s: Attempt to read data past the end of the " |
328 | "file; offset = [%lld]; size = [%td]; " | 328 | "file; offset = [%lld]; size = [%td]; " |
329 | "ecryptfs_file_size = [%lld]\n", | 329 | "ecryptfs_file_size = [%lld]\n", |
330 | __FUNCTION__, offset, size, ecryptfs_file_size); | 330 | __func__, offset, size, ecryptfs_file_size); |
331 | goto out; | 331 | goto out; |
332 | } | 332 | } |
333 | pos = offset; | 333 | pos = offset; |
@@ -345,14 +345,14 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
345 | rc = PTR_ERR(ecryptfs_page); | 345 | rc = PTR_ERR(ecryptfs_page); |
346 | printk(KERN_ERR "%s: Error getting page at " | 346 | printk(KERN_ERR "%s: Error getting page at " |
347 | "index [%ld] from eCryptfs inode " | 347 | "index [%ld] from eCryptfs inode " |
348 | "mapping; rc = [%d]\n", __FUNCTION__, | 348 | "mapping; rc = [%d]\n", __func__, |
349 | ecryptfs_page_idx, rc); | 349 | ecryptfs_page_idx, rc); |
350 | goto out; | 350 | goto out; |
351 | } | 351 | } |
352 | rc = ecryptfs_decrypt_page(ecryptfs_page); | 352 | rc = ecryptfs_decrypt_page(ecryptfs_page); |
353 | if (rc) { | 353 | if (rc) { |
354 | printk(KERN_ERR "%s: Error decrypting " | 354 | printk(KERN_ERR "%s: Error decrypting " |
355 | "page; rc = [%d]\n", __FUNCTION__, rc); | 355 | "page; rc = [%d]\n", __func__, rc); |
356 | ClearPageUptodate(ecryptfs_page); | 356 | ClearPageUptodate(ecryptfs_page); |
357 | page_cache_release(ecryptfs_page); | 357 | page_cache_release(ecryptfs_page); |
358 | goto out; | 358 | goto out; |