sessiond: enforce user-exclusive session access in session_access_ok
[lttng-tools.git] / src / bin / lttng-sessiond / client.c
index 1bf55f60b7f415afa81274b20af8c54bc09ef9d6..8a2ef85b7345c33d89cd2914134bd075a71b4e9e 100644 (file)
@@ -92,7 +92,11 @@ static int setup_lttng_msg(struct command_ctx *cmd_ctx,
                .data_size = payload_len,
        };
 
-       lttng_dynamic_buffer_set_size(&cmd_ctx->reply_payload.buffer, 0);
+       ret = lttng_dynamic_buffer_set_size(&cmd_ctx->reply_payload.buffer, 0);
+       if (ret) {
+               goto end;
+       }
+
        lttng_dynamic_pointer_array_clear(&cmd_ctx->reply_payload._fd_handles);
 
        cmd_ctx->lttng_msg_size = total_msg_size;
@@ -133,7 +137,10 @@ static int setup_empty_lttng_msg(struct command_ctx *cmd_ctx)
        int ret;
        const struct lttcomm_lttng_msg llm = {};
 
-       lttng_dynamic_buffer_set_size(&cmd_ctx->reply_payload.buffer, 0);
+       ret = lttng_dynamic_buffer_set_size(&cmd_ctx->reply_payload.buffer, 0);
+       if (ret) {
+               goto end;
+       }
 
        /* Append place-holder reply header. */
        ret = lttng_dynamic_buffer_append(
@@ -572,15 +579,14 @@ static unsigned int lttng_sessions_count(uid_t uid, gid_t gid)
        struct ltt_session *session;
        const struct ltt_session_list *session_list = session_get_list();
 
-       DBG("Counting number of available session for UID %d GID %d",
-                       uid, gid);
+       DBG("Counting number of available session for UID %d", uid);
        cds_list_for_each_entry(session, &session_list->head, list) {
                if (!session_get(session)) {
                        continue;
                }
                session_lock(session);
                /* Only count the sessions the user can control. */
-               if (session_access_ok(session, uid, gid) &&
+               if (session_access_ok(session, uid) &&
                                !session->destroyed) {
                        i++;
                }
@@ -735,32 +741,10 @@ static int send_unix_sock(int sock, struct lttng_payload_view *view)
        }
 
        if (fd_count > 0) {
-               int i;
-               struct lttng_dynamic_array raw_fds;
-
-               /*
-                * Never holds ownership of the FDs; this is just used
-                * to put the FDs in a contiguous array.
-                */
-               lttng_dynamic_array_init(&raw_fds, sizeof(int), NULL);
-
-               for (i = 0; i < fd_count; i++) {
-                       struct fd_handle *handle =
-                               lttng_payload_view_pop_fd_handle(view);
-                       const int raw_fd = fd_handle_get_fd(handle);
-
-                       ret = lttng_dynamic_array_add_element(&raw_fds, &raw_fd);
-                       fd_handle_put(handle);
-                       if (ret) {
-                               lttng_dynamic_array_reset(&raw_fds);
-                               goto end;
-                       }
+               ret = lttcomm_send_payload_view_fds_unix_sock(sock, view);
+               if (ret < 0) {
+                       goto end;
                }
-
-               ret = lttcomm_send_fds_unix_sock(sock,
-                               (const int *) raw_fds.buffer.data,
-                               fd_count);
-               lttng_dynamic_array_reset(&raw_fds);
        }
 
 end:
@@ -1121,13 +1105,12 @@ skip_domain:
        }
 
        /*
-        * Check that the UID or GID match that of the tracing session.
+        * Check that the UID matches that of the tracing session.
         * The root user can interact with all sessions.
         */
        if (need_tracing_session) {
                if (!session_access_ok(cmd_ctx->session,
-                               LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
-                               LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds)) ||
+                               LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds)) ||
                                cmd_ctx->session->destroyed) {
                        ret = LTTNG_ERR_EPERM;
                        goto error;
This page took 0.025675 seconds and 5 git commands to generate.