[systemd-devel] [PATCH 2/3] connection: move the install creds into the slice to its own function
Daniel Mack
daniel at zonque.org
Tue Aug 19 00:09:15 PDT 2014
On 08/19/2014 03:43 AM, Djalal Harouni wrote:
> 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.
Applied, thanks!
> Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
> ---
> connection.c | 32 ++++++++++++++++++++------------
> 1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/connection.c b/connection.c
> index 99ac2a1..9250dab 100644
> --- a/connection.c
> +++ b/connection.c
> @@ -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;
> }
>
More information about the systemd-devel
mailing list