Fix: channel names are not validated
A message that is not in the archive (sent off-list or not yet received): [email protected]
Merged all the way to 2.4 with a couple of minor changes.
Read on for comments.
Quoted 46 lines · Philippe Proulx
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 traceFixes #751Signed-off-by Philippe Proulx <[email protected]>--- include/lttng/lttng-error.h | 1 + src/bin/lttng-sessiond/cmd.c | 6 ++++++ src/bin/lttng/commands/enable_channels.c | 20 +++++++++++++++++--- src/common/error.c | 1 + 4 files changed, 25 insertions(+), 3 deletions(-)include/lttng/lttng-error.h +1
-0@@ -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 */src/bin/lttng-sessiond/cmd.c +1
-0@@ -18,6 +18,7 @@#define _GNU_SOURCE#define _LGPL_SOURCE#include <assert.h> +#include <string.h> #include <inttypes.h> #include <urcu/list.h> #include <urcu/uatomic.h>
src/bin/lttng-sessiond/cmd.c int cmd_enable_channel(struct ltt_session *session, · line 949
Quoted 5 lines
src/bin/lttng-sessiond/cmd.c +2
-0@@ -944,6 +945,11 @@ int cmd_enable_channel(struct ltt_session *session,assert (attr);assert (domain); +/* Validate channel name */ +if (attr->name[0 ] =='.' ||strchr (attr->name,'/' ) !=NULL ) {
Changed strchr() to memchr() which takes a length argument.
src/bin/lttng-sessiond/cmd.c int cmd_enable_channel(struct ltt_session *session, · line 950
Quoted 1 line
src/bin/lttng-sessiond/cmd.c +1
-0+return LTTNG_ERR_INVALID_CHANNEL_NAME ;
changed this to
ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
goto end; (end is _after_ the rcu_read_unlock())
We prefer having a single exit point in functions (whenever it makes sense).
Quoted 10 lines
src/bin/lttng-sessiond/cmd.c +2
-0+ } +DBG ("Enabling channel %s for session %s" , attr->name, session->name);rcu_read_lock ();src/bin/lttng/commands/enable_channels.c +0
-0
src/bin/lttng/commands/enable_channels.c static int enable_channel(char *session_name) · line 281
Quoted 10 lines
src/bin/lttng/commands/enable_channels.c +4
-3@@ -275,9 +275,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. %u characters)" , +NAME_MAX -1 );
Please use tabs for indents.
Quoted 10 lines
src/bin/lttng/commands/enable_channels.c +6
-0+ error =1 ; + goto skip_enable; + } + +/* Copy channel name */ +strcpy (chan.name, channel_name);DBG ("Enabling channel %s" , channel_name);
src/bin/lttng/commands/enable_channels.c static int enable_channel(char *session_name) · line 305
Quoted 7 lines
src/bin/lttng/commands/enable_channels.c +4
-0@@ -292,6 +299,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);
Use tabs to indent.
Thanks!
Jérémie
Quoted 33 lines
src/bin/lttng/commands/enable_channels.c +3
-0+ error =1 ; +break ;default :ERR ("Channel %s: %s (session %s)" , channel_name,lttng_strerror (ret), session_name);@@ -304,6 +317,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 );src/common/error.c +1
-1@@ -166,6 +166,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" --2.1.3
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 8 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev