connection: move the install creds into the slice to its own function
authorDjalal Harouni <tixxdz@opendz.org>
Tue, 19 Aug 2014 01:43:57 +0000 (02:43 +0100)
committerDaniel Mack <zonque@gmail.com>
Tue, 19 Aug 2014 07:06:33 +0000 (09:06 +0200)
Move the install creds into the receiver's slice to its own function
kdbus_conn_creds_install().

Use from_kuid_munged(), so the uid mapping never fails.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection.c

index 99ac2a1708a8c3d3db96c081f6fc0a50c51d0559..9250dab09e15ccfb10b9cb06afb6d427c0615a74 100644 (file)
@@ -964,6 +964,25 @@ remove_unused:
        return ret;
 }
 
+static int kdbus_conn_creds_install(struct kdbus_conn_queue *queue)
+{
+       int ret;
+       struct kdbus_creds creds = {};
+       struct user_namespace *current_ns = current_user_ns();
+       off_t off = queue->creds_item_offset +
+                   offsetof(struct kdbus_item, creds);
+
+       creds.uid = from_kuid_munged(current_ns, queue->uid);
+       creds.gid = from_kgid_munged(current_ns, queue->gid);
+       creds.pid = pid_nr_ns(queue->pid, task_active_pid_ns(current));
+       creds.tid = pid_nr_ns(queue->tid, task_active_pid_ns(current));
+
+       ret = kdbus_pool_slice_copy_user(queue->slice, off,
+                                        &creds, sizeof(creds));
+
+       return ret;
+}
+
 static int kdbus_conn_msg_install(struct kdbus_conn_queue *queue)
 {
        int *memfds = NULL;
@@ -989,18 +1008,7 @@ static int kdbus_conn_msg_install(struct kdbus_conn_queue *queue)
        }
 
        if (queue->creds_item_offset) {
-               struct kdbus_creds creds;
-               size_t size = sizeof(__u64) * 4;
-               off_t off = queue->creds_item_offset +
-                           offsetof(struct kdbus_item, creds);
-
-               creds.uid = from_kuid(current_user_ns(), queue->uid);
-               creds.gid = from_kgid(current_user_ns(), queue->gid);
-               creds.pid = pid_nr_ns(queue->pid, task_active_pid_ns(current));
-               creds.tid = pid_nr_ns(queue->tid, task_active_pid_ns(current));
-
-               ret = kdbus_pool_slice_copy_user(queue->slice, off,
-                                                &creds, size);
+               ret = kdbus_conn_creds_install(queue);
                if (ret < 0)
                        goto exit_rewind_fds;
        }