Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[firefly-linux-kernel-4.4.55.git] / fs / ecryptfs / messaging.c
index c22b32fc8e8c7b8f25cbcb68b09d56dd6b6e6207..3baf253be95ad5f6e641cedbeb0f9c6a679c04eb 100644 (file)
 
 #include "ecryptfs_kernel.h"
 
-LIST_HEAD(ecryptfs_msg_ctx_free_list);
-LIST_HEAD(ecryptfs_msg_ctx_alloc_list);
-struct mutex ecryptfs_msg_ctx_lists_mux;
+static LIST_HEAD(ecryptfs_msg_ctx_free_list);
+static LIST_HEAD(ecryptfs_msg_ctx_alloc_list);
+static struct mutex ecryptfs_msg_ctx_lists_mux;
 
-struct hlist_head *ecryptfs_daemon_id_hash;
-struct mutex ecryptfs_daemon_id_hash_mux;
-int ecryptfs_hash_buckets;
+static struct hlist_head *ecryptfs_daemon_id_hash;
+static struct mutex ecryptfs_daemon_id_hash_mux;
+static int ecryptfs_hash_buckets;
+#define ecryptfs_uid_hash(uid) \
+        hash_long((unsigned long)uid, ecryptfs_hash_buckets)
 
-unsigned int ecryptfs_msg_counter;
-struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr;
+static unsigned int ecryptfs_msg_counter;
+static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr;
 
 /**
  * ecryptfs_acquire_free_msg_ctx
@@ -167,7 +169,8 @@ int ecryptfs_process_helo(unsigned int transport, uid_t uid, pid_t pid)
        if (!new_id) {
                rc = -ENOMEM;
                ecryptfs_printk(KERN_ERR, "Failed to allocate memory; unable "
-                               "to register daemon [%d] for user\n", pid, uid);
+                               "to register daemon [%d] for user [%d]\n",
+                               pid, uid);
                goto unlock;
        }
        if (!ecryptfs_find_daemon_id(uid, &old_id)) {
@@ -243,7 +246,8 @@ unlock:
  * userspace. Returns zero upon delivery to desired context element;
  * non-zero upon delivery failure or error.
  */
-int ecryptfs_process_response(struct ecryptfs_message *msg, pid_t pid, u32 seq)
+int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t uid,
+                             pid_t pid, u32 seq)
 {
        struct ecryptfs_daemon_id *id;
        struct ecryptfs_msg_ctx *msg_ctx;
@@ -268,6 +272,13 @@ int ecryptfs_process_response(struct ecryptfs_message *msg, pid_t pid, u32 seq)
                                msg_ctx->task->euid, pid);
                goto wake_up;
        }
+       if (msg_ctx->task->euid != uid) {
+               rc = -EBADMSG;
+               ecryptfs_printk(KERN_WARNING, "Received message from user "
+                               "[%d]; expected message from user [%d]\n",
+                               uid, msg_ctx->task->euid);
+               goto unlock;
+       }
        if (id->pid != pid) {
                rc = -EBADMSG;
                ecryptfs_printk(KERN_ERR, "User [%d] received a "