diff options
Diffstat (limited to 'fs/ecryptfs/messaging.c')
| -rw-r--r-- | fs/ecryptfs/messaging.c | 118 |
1 files changed, 31 insertions, 87 deletions
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index 1b5c20058acb..c6983978a31e 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c | |||
| @@ -134,12 +134,11 @@ out: | |||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | static int | 136 | static int |
| 137 | ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, | 137 | ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type, |
| 138 | u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx); | 138 | struct ecryptfs_msg_ctx **msg_ctx); |
| 139 | 139 | ||
| 140 | /** | 140 | /** |
| 141 | * ecryptfs_send_raw_message | 141 | * ecryptfs_send_raw_message |
| 142 | * @transport: Transport type | ||
| 143 | * @msg_type: Message type | 142 | * @msg_type: Message type |
| 144 | * @daemon: Daemon struct for recipient of message | 143 | * @daemon: Daemon struct for recipient of message |
| 145 | * | 144 | * |
| @@ -150,38 +149,25 @@ ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, | |||
| 150 | * | 149 | * |
| 151 | * Returns zero on success; non-zero otherwise | 150 | * Returns zero on success; non-zero otherwise |
| 152 | */ | 151 | */ |
| 153 | static int ecryptfs_send_raw_message(unsigned int transport, u8 msg_type, | 152 | static int ecryptfs_send_raw_message(u8 msg_type, |
| 154 | struct ecryptfs_daemon *daemon) | 153 | struct ecryptfs_daemon *daemon) |
| 155 | { | 154 | { |
| 156 | struct ecryptfs_msg_ctx *msg_ctx; | 155 | struct ecryptfs_msg_ctx *msg_ctx; |
| 157 | int rc; | 156 | int rc; |
| 158 | 157 | ||
| 159 | switch(transport) { | 158 | rc = ecryptfs_send_message_locked(NULL, 0, msg_type, &msg_ctx); |
| 160 | case ECRYPTFS_TRANSPORT_NETLINK: | 159 | if (rc) { |
| 161 | rc = ecryptfs_send_netlink(NULL, 0, NULL, msg_type, 0, | 160 | printk(KERN_ERR "%s: Error whilst attempting to send " |
| 162 | daemon->pid); | 161 | "message to ecryptfsd; rc = [%d]\n", __func__, rc); |
| 163 | break; | 162 | goto out; |
| 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); | ||
| 179 | break; | ||
| 180 | case ECRYPTFS_TRANSPORT_CONNECTOR: | ||
| 181 | case ECRYPTFS_TRANSPORT_RELAYFS: | ||
| 182 | default: | ||
| 183 | rc = -ENOSYS; | ||
| 184 | } | 163 | } |
| 164 | /* Raw messages are logically context-free (e.g., no | ||
| 165 | * reply is expected), so we set the state of the | ||
| 166 | * ecryptfs_msg_ctx object to indicate that it should | ||
| 167 | * be freed as soon as the message is sent. */ | ||
| 168 | mutex_lock(&msg_ctx->mux); | ||
| 169 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_NO_REPLY; | ||
| 170 | mutex_unlock(&msg_ctx->mux); | ||
| 185 | out: | 171 | out: |
| 186 | return rc; | 172 | return rc; |
| 187 | } | 173 | } |
| @@ -227,7 +213,6 @@ out: | |||
| 227 | 213 | ||
| 228 | /** | 214 | /** |
| 229 | * ecryptfs_process_helo | 215 | * ecryptfs_process_helo |
| 230 | * @transport: The underlying transport (netlink, etc.) | ||
| 231 | * @euid: The user ID owner of the message | 216 | * @euid: The user ID owner of the message |
| 232 | * @user_ns: The namespace in which @euid applies | 217 | * @user_ns: The namespace in which @euid applies |
| 233 | * @pid: The process ID for the userspace program that sent the | 218 | * @pid: The process ID for the userspace program that sent the |
| @@ -239,8 +224,8 @@ out: | |||
| 239 | * Returns zero after adding a new daemon to the hash list; | 224 | * Returns zero after adding a new daemon to the hash list; |
| 240 | * non-zero otherwise. | 225 | * non-zero otherwise. |
| 241 | */ | 226 | */ |
| 242 | int ecryptfs_process_helo(unsigned int transport, uid_t euid, | 227 | int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns, |
| 243 | struct user_namespace *user_ns, struct pid *pid) | 228 | struct pid *pid) |
| 244 | { | 229 | { |
| 245 | struct ecryptfs_daemon *new_daemon; | 230 | struct ecryptfs_daemon *new_daemon; |
| 246 | struct ecryptfs_daemon *old_daemon; | 231 | struct ecryptfs_daemon *old_daemon; |
| @@ -252,8 +237,7 @@ int ecryptfs_process_helo(unsigned int transport, uid_t euid, | |||
| 252 | printk(KERN_WARNING "Received request from user [%d] " | 237 | printk(KERN_WARNING "Received request from user [%d] " |
| 253 | "to register daemon [0x%p]; unregistering daemon " | 238 | "to register daemon [0x%p]; unregistering daemon " |
| 254 | "[0x%p]\n", euid, pid, old_daemon->pid); | 239 | "[0x%p]\n", euid, pid, old_daemon->pid); |
| 255 | rc = ecryptfs_send_raw_message(transport, ECRYPTFS_MSG_QUIT, | 240 | rc = ecryptfs_send_raw_message(ECRYPTFS_MSG_QUIT, old_daemon); |
| 256 | old_daemon); | ||
| 257 | if (rc) | 241 | if (rc) |
| 258 | printk(KERN_WARNING "Failed to send QUIT " | 242 | printk(KERN_WARNING "Failed to send QUIT " |
| 259 | "message to daemon [0x%p]; rc = [%d]\n", | 243 | "message to daemon [0x%p]; rc = [%d]\n", |
| @@ -467,8 +451,6 @@ out: | |||
| 467 | 451 | ||
| 468 | /** | 452 | /** |
| 469 | * ecryptfs_send_message_locked | 453 | * ecryptfs_send_message_locked |
| 470 | * @transport: The transport over which to send the message (i.e., | ||
| 471 | * netlink) | ||
| 472 | * @data: The data to send | 454 | * @data: The data to send |
| 473 | * @data_len: The length of data | 455 | * @data_len: The length of data |
| 474 | * @msg_ctx: The message context allocated for the send | 456 | * @msg_ctx: The message context allocated for the send |
| @@ -478,8 +460,8 @@ out: | |||
| 478 | * Returns zero on success; non-zero otherwise | 460 | * Returns zero on success; non-zero otherwise |
| 479 | */ | 461 | */ |
| 480 | static int | 462 | static int |
| 481 | ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, | 463 | ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type, |
| 482 | u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx) | 464 | struct ecryptfs_msg_ctx **msg_ctx) |
| 483 | { | 465 | { |
| 484 | struct ecryptfs_daemon *daemon; | 466 | struct ecryptfs_daemon *daemon; |
| 485 | int rc; | 467 | int rc; |
| @@ -503,20 +485,8 @@ ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, | |||
| 503 | ecryptfs_msg_ctx_free_to_alloc(*msg_ctx); | 485 | ecryptfs_msg_ctx_free_to_alloc(*msg_ctx); |
| 504 | mutex_unlock(&(*msg_ctx)->mux); | 486 | mutex_unlock(&(*msg_ctx)->mux); |
| 505 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); | 487 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); |
| 506 | switch (transport) { | 488 | rc = ecryptfs_send_miscdev(data, data_len, *msg_ctx, msg_type, 0, |
| 507 | case ECRYPTFS_TRANSPORT_NETLINK: | 489 | daemon); |
| 508 | rc = ecryptfs_send_netlink(data, data_len, *msg_ctx, msg_type, | ||
| 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); | ||
| 514 | break; | ||
| 515 | case ECRYPTFS_TRANSPORT_CONNECTOR: | ||
| 516 | case ECRYPTFS_TRANSPORT_RELAYFS: | ||
| 517 | default: | ||
| 518 | rc = -ENOSYS; | ||
| 519 | } | ||
| 520 | if (rc) | 490 | if (rc) |
| 521 | printk(KERN_ERR "%s: Error attempting to send message to " | 491 | printk(KERN_ERR "%s: Error attempting to send message to " |
| 522 | "userspace daemon; rc = [%d]\n", __func__, rc); | 492 | "userspace daemon; rc = [%d]\n", __func__, rc); |
| @@ -526,8 +496,6 @@ out: | |||
| 526 | 496 | ||
| 527 | /** | 497 | /** |
| 528 | * ecryptfs_send_message | 498 | * ecryptfs_send_message |
| 529 | * @transport: The transport over which to send the message (i.e., | ||
| 530 | * netlink) | ||
| 531 | * @data: The data to send | 499 | * @data: The data to send |
| 532 | * @data_len: The length of data | 500 | * @data_len: The length of data |
| 533 | * @msg_ctx: The message context allocated for the send | 501 | * @msg_ctx: The message context allocated for the send |
| @@ -536,14 +504,14 @@ out: | |||
| 536 | * | 504 | * |
| 537 | * Returns zero on success; non-zero otherwise | 505 | * Returns zero on success; non-zero otherwise |
| 538 | */ | 506 | */ |
| 539 | int ecryptfs_send_message(unsigned int transport, char *data, int data_len, | 507 | int ecryptfs_send_message(char *data, int data_len, |
| 540 | struct ecryptfs_msg_ctx **msg_ctx) | 508 | struct ecryptfs_msg_ctx **msg_ctx) |
| 541 | { | 509 | { |
| 542 | int rc; | 510 | int rc; |
| 543 | 511 | ||
| 544 | mutex_lock(&ecryptfs_daemon_hash_mux); | 512 | mutex_lock(&ecryptfs_daemon_hash_mux); |
| 545 | rc = ecryptfs_send_message_locked(transport, data, data_len, | 513 | rc = ecryptfs_send_message_locked(data, data_len, ECRYPTFS_MSG_REQUEST, |
| 546 | ECRYPTFS_MSG_REQUEST, msg_ctx); | 514 | msg_ctx); |
| 547 | mutex_unlock(&ecryptfs_daemon_hash_mux); | 515 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
| 548 | return rc; | 516 | return rc; |
| 549 | } | 517 | } |
| @@ -586,7 +554,7 @@ sleep: | |||
| 586 | return rc; | 554 | return rc; |
| 587 | } | 555 | } |
| 588 | 556 | ||
| 589 | int ecryptfs_init_messaging(unsigned int transport) | 557 | int ecryptfs_init_messaging(void) |
| 590 | { | 558 | { |
| 591 | int i; | 559 | int i; |
| 592 | int rc = 0; | 560 | int rc = 0; |
| @@ -639,27 +607,14 @@ int ecryptfs_init_messaging(unsigned int transport) | |||
| 639 | mutex_unlock(&ecryptfs_msg_ctx_arr[i].mux); | 607 | mutex_unlock(&ecryptfs_msg_ctx_arr[i].mux); |
| 640 | } | 608 | } |
| 641 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); | 609 | mutex_unlock(&ecryptfs_msg_ctx_lists_mux); |
| 642 | switch(transport) { | 610 | rc = ecryptfs_init_ecryptfs_miscdev(); |
| 643 | case ECRYPTFS_TRANSPORT_NETLINK: | 611 | if (rc) |
| 644 | rc = ecryptfs_init_netlink(); | 612 | ecryptfs_release_messaging(); |
| 645 | if (rc) | ||
| 646 | ecryptfs_release_messaging(transport); | ||
| 647 | break; | ||
| 648 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
| 649 | rc = ecryptfs_init_ecryptfs_miscdev(); | ||
| 650 | if (rc) | ||
| 651 | ecryptfs_release_messaging(transport); | ||
| 652 | break; | ||
| 653 | case ECRYPTFS_TRANSPORT_CONNECTOR: | ||
| 654 | case ECRYPTFS_TRANSPORT_RELAYFS: | ||
| 655 | default: | ||
| 656 | rc = -ENOSYS; | ||
| 657 | } | ||
| 658 | out: | 613 | out: |
| 659 | return rc; | 614 | return rc; |
| 660 | } | 615 | } |
| 661 | 616 | ||
| 662 | void ecryptfs_release_messaging(unsigned int transport) | 617 | void ecryptfs_release_messaging(void) |
| 663 | { | 618 | { |
| 664 | if (ecryptfs_msg_ctx_arr) { | 619 | if (ecryptfs_msg_ctx_arr) { |
| 665 | int i; | 620 | int i; |
| @@ -698,17 +653,6 @@ void ecryptfs_release_messaging(unsigned int transport) | |||
| 698 | kfree(ecryptfs_daemon_hash); | 653 | kfree(ecryptfs_daemon_hash); |
| 699 | mutex_unlock(&ecryptfs_daemon_hash_mux); | 654 | mutex_unlock(&ecryptfs_daemon_hash_mux); |
| 700 | } | 655 | } |
| 701 | switch(transport) { | 656 | ecryptfs_destroy_ecryptfs_miscdev(); |
| 702 | case ECRYPTFS_TRANSPORT_NETLINK: | ||
| 703 | ecryptfs_release_netlink(); | ||
| 704 | break; | ||
| 705 | case ECRYPTFS_TRANSPORT_MISCDEV: | ||
| 706 | ecryptfs_destroy_ecryptfs_miscdev(); | ||
| 707 | break; | ||
| 708 | case ECRYPTFS_TRANSPORT_CONNECTOR: | ||
| 709 | case ECRYPTFS_TRANSPORT_RELAYFS: | ||
| 710 | default: | ||
| 711 | break; | ||
| 712 | } | ||
| 713 | return; | 657 | return; |
| 714 | } | 658 | } |
