Fix: channel names are not validated
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 27 Nov 2014 22:35:32 +0000 (17:35 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 1 Dec 2014 23:36:55 +0000 (18:36 -0500)
This patch ensures:

  1. A channel name does not contain any '/' character, since
     relative paths may be injected in the channel name
     otherwise (knowing that the channel name is eventually
     part of a file name)
  2. A channel name does not start with a '.' character, since
     trace readers (Babeltrace is one of them) could interpret
     files starting with a dot as hidden files and ignore
     them when opening the CTF trace

Fixes: #751
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng/commands/enable_channels.c
src/common/error.c

index 1220e489a1b70d5815c9d5ea39e08e994eb0d8b6..efdca6520ce3e25bca295d66c2187eacf59f29b9 100644 (file)
@@ -133,6 +133,7 @@ enum lttng_error_code {
        LTTNG_ERR_EXCLUSION_INVAL        = 110, /* Invalid event exclusion data */
        LTTNG_ERR_EXCLUSION_NOMEM        = 111, /* Lack of memory while processing event exclusions */
        LTTNG_ERR_INVALID_EVENT_NAME     = 112, /* Invalid event name */
+       LTTNG_ERR_INVALID_CHANNEL_NAME   = 113, /* Invalid channel name */
 
        /* MUST be last element */
        LTTNG_ERR_NR,                           /* Last element */
index 9e2708a70e4c7a1470d38478f8aa776de04a549f..dbecc3d2431b6d558c3a590448b77373326da3c1 100644 (file)
@@ -17,6 +17,7 @@
 
 #define _GNU_SOURCE
 #include <assert.h>
+#include <string.h>
 #include <inttypes.h>
 #include <urcu/list.h>
 #include <urcu/uatomic.h>
@@ -938,11 +939,21 @@ int cmd_enable_channel(struct ltt_session *session,
        int ret;
        struct ltt_ust_session *usess = session->ust_session;
        struct lttng_ht *chan_ht;
+       size_t len;
 
        assert(session);
        assert(attr);
        assert(domain);
 
+       len = strnlen(attr->name, sizeof(attr->name));
+
+       /* Validate channel name */
+       if (attr->name[0] == '.' ||
+               memchr(attr->name, '/', len) != NULL) {
+               ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+               goto end;
+       }
+
        DBG("Enabling channel %s for session %s", attr->name, session->name);
 
        rcu_read_lock();
@@ -1023,6 +1034,7 @@ int cmd_enable_channel(struct ltt_session *session,
 
 error:
        rcu_read_unlock();
+end:
        return ret;
 }
 
index a58ebe0f7847a653147654c53345b0ddb500c016..6900dfde83e9c926ac59b7baec09fc8edbd69f24 100644 (file)
@@ -274,9 +274,16 @@ static int enable_channel(char *session_name)
        /* Strip channel list (format: chan1,chan2,...) */
        channel_name = strtok(opt_channels, ",");
        while (channel_name != NULL) {
-               /* Copy channel name and normalize it */
-               strncpy(chan.name, channel_name, NAME_MAX);
-               chan.name[NAME_MAX - 1] = '\0';
+               /* Validate channel name's length */
+               if (strlen(channel_name) >= NAME_MAX) {
+                       ERR("Channel name is too long (max. %zu characters)",
+                           sizeof(chan.name) - 1);
+                       error = 1;
+                       goto skip_enable;
+               }
+
+               /* Copy channel name */
+               strcpy(chan.name, channel_name);
 
                DBG("Enabling channel %s", channel_name);
 
@@ -291,6 +298,12 @@ static int enable_channel(char *session_name)
                                                lttng_strerror(ret), session_name);
                                warn = 1;
                                break;
+                       case LTTNG_ERR_INVALID_CHANNEL_NAME:
+                               ERR("Invalid channel name: \"%s\". "
+                                   "Channel names may not start with '.', and "
+                                   "may not contain '/'.", channel_name);
+                               error = 1;
+                               break;
                        default:
                                ERR("Channel %s: %s (session %s)", channel_name,
                                                lttng_strerror(ret), session_name);
@@ -303,6 +316,7 @@ static int enable_channel(char *session_name)
                        success = 1;
                }
 
+skip_enable:
                if (lttng_opt_mi) {
                        /* Mi print the channel element and leave it open */
                        ret = mi_lttng_channel(writer, &chan, 1);
index 852de6fb4cf0c3fc7b0dc33c19164ced148c5be4..757aaec9dbcec4781ddd24923e23a3fe34936269 100644 (file)
@@ -165,6 +165,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_MI_IO_FAIL) ] = "IO error while writing MI output",
        [ ERROR_INDEX(LTTNG_ERR_MI_NOT_IMPLEMENTED) ] = "Mi feature not implemented",
        [ ERROR_INDEX(LTTNG_ERR_INVALID_EVENT_NAME) ] = "Invalid event name",
+       [ ERROR_INDEX(LTTNG_ERR_INVALID_CHANNEL_NAME) ] = "Invalid channel name",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.037363 seconds and 4 git commands to generate.