Fix: close socket on protocol error, sendmsg MSG_NOSIGNAL
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 26 Aug 2015 22:24:11 +0000 (18:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 26 Aug 2015 22:31:58 +0000 (18:31 -0400)
Don't try to keep interacting with sessiond when a protocol error is
detected at the UST application side: this means we cannot trust the
protocol anymore, so there is no reason for keeping the socket open.
For instance, if the application is exiting and we receive a new stream,
we're effectively not reading the stream data, and we return an error.
Unfortunately, the session daemon may try to send us another command,
but we will try interpreting the stream data as a command, which is
invalid.

Also, use MSG_NOSIGNAL flag in the fds recvmsg, so the session daemon
don't get killed with SIGPIPE when it cannot send to the socket due to
connection closed.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-comm/lttng-ust-comm.c
liblttng-ust/lttng-ust-comm.c

index 751ad2e3cf2add1ffd805c9ca4df802034e793b1..6edb395f18ca32498a6d5c9c96dc6b2a23cb2737 100644 (file)
@@ -390,7 +390,7 @@ ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd)
        msg.msg_iovlen = 1;
 
        do {
-               ret = sendmsg(sock, &msg, 0);
+               ret = sendmsg(sock, &msg, MSG_NOSIGNAL);
        } while (ret < 0 && errno == EINTR);
        if (ret < 0) {
                /*
index d48cc33627af5f4057060208e69b58afcdfc0b1f..fbdee7d3af8ea0d8d122ab3e4b3bb8a251ccc9a0 100644 (file)
@@ -573,13 +573,13 @@ int handle_message(struct sock_info *sock_info,
 
        if (ust_lock()) {
                ret = -LTTNG_UST_ERR_EXITING;
-               goto end;
+               goto error;
        }
 
        ops = objd_ops(lum->handle);
        if (!ops) {
                ret = -ENOENT;
-               goto end;
+               goto error;
        }
 
        switch (lum->cmd) {
@@ -640,12 +640,12 @@ int handle_message(struct sock_info *sock_info,
                                }
                                ret = len;
                                free(bytecode);
-                               goto end;
+                               goto error;
                        } else {
                                DBG("incorrect filter data message size: %zd", len);
                                ret = -EINVAL;
                                free(bytecode);
-                               goto end;
+                               goto error;
                        }
                }
                bytecode->bc.len = lum->u.filter.data_size;
@@ -705,12 +705,12 @@ int handle_message(struct sock_info *sock_info,
                                }
                                ret = len;
                                free(node);
-                               goto end;
+                               goto error;
                        } else {
                                DBG("Incorrect exclusion data message size: %zd", len);
                                ret = -EINVAL;
                                free(node);
-                               goto end;
+                               goto error;
                        }
                }
                if (ops->cmd) {
@@ -751,11 +751,11 @@ int handle_message(struct sock_info *sock_info,
                                        goto error;
                                }
                                ret = len;
-                               goto end;
+                               goto error;
                        } else {
                                DBG("incorrect channel data message size: %zd", len);
                                ret = -EINVAL;
-                               goto end;
+                               goto error;
                        }
                }
                args.channel.chan_data = chan_data;
@@ -776,7 +776,7 @@ int handle_message(struct sock_info *sock_info,
                        &args.stream.shm_fd,
                        &args.stream.wakeup_fd);
                if (ret) {
-                       goto end;
+                       goto error;
                }
                if (ops->cmd)
                        ret = ops->cmd(lum->handle, lum->cmd,
@@ -796,7 +796,6 @@ int handle_message(struct sock_info *sock_info,
                break;
        }
 
-end:
        lur.handle = lum->handle;
        lur.cmd = lum->cmd;
        lur.ret_val = ret;
@@ -1397,7 +1396,13 @@ restart:
                        print_cmd(lum.cmd, lum.handle);
                        ret = handle_message(sock_info, sock, &lum);
                        if (ret) {
-                               ERR("Error handling message for %s socket", sock_info->name);
+                               ERR("Error handling message for %s socket",
+                                       sock_info->name);
+                               /*
+                                * Close socket if protocol error is
+                                * detected.
+                                */
+                               goto end;
                        }
                        continue;
                default:
This page took 0.027465 seconds and 4 git commands to generate.