Fix: channel name with '.' and '/' brings problems
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hey Phil,
Not sure if modifying user input without any warnings about it is a good idea. This clearly solve problems but do we want to solve it this way ?
It might be a better idea to warn the user about improper channel name or simply block the command and return an error.
Quoted 44 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]>--- src/bin/lttng/commands/enable_channels.c | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)src/bin/lttng/commands/enable_channels.c +9
-2@@ -275,11 +275,39 @@ 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 */ +/* Copy channel name, sanitize and normalize it */ strncpy (chan.name, channel_name,NAME_MAX ); chan.name[NAME_MAX -1 ] ='\0' ; -DBG ("Enabling channel %s" , channel_name); +char *src, *dst; +int got_first =0 ; + +for (src = dst = chan.name; *src !='\0' ; ++src) { + *dst = *src; + +/* +* Channel name could be used in file names, so remove
src/bin/lttng/commands/enable_channels.c
Quoted 3 lines
src/bin/lttng/commands/enable_channels.c +3
-0+* invalid '/' +*/ +if (*dst !='/' ) {
Maybe send some warning here ?
src/bin/lttng/commands/enable_channels.c
Quoted 10 lines
src/bin/lttng/commands/enable_channels.c +2
-0+/* +* Remove starting dots since this could create
src/bin/lttng/commands/enable_channels.c +2
-0+* file names starting with dots, and trace +* readers could interpret them as hidden files
src/bin/lttng/commands/enable_channels.c +3
-0+* and ignore them. +*/ +if (*dst !='.' ) {
Same
Quoted 54 lines
src/bin/lttng/commands/enable_channels.c +13
-2+ got_first =1 ; + dst++; + }else if (got_first) { + dst++; + } + } + } + + *dst ='\0' ; + +DBG ("Enabling channel %s" , chan.name); ret =lttng_enable_channel (handle, &chan);if (ret <0 ) {@@ -288,19 +316,19 @@ static int enable_channel(char *session_name)case LTTNG_ERR_KERN_CHAN_EXIST :case LTTNG_ERR_UST_CHAN_EXIST :case LTTNG_ERR_CHAN_EXIST : -WARN ("Channel %s: %s (session %s)" , channel_name, +WARN ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); warn =1 ;break ;default : -ERR ("Channel %s: %s (session %s)" , channel_name, +ERR ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); error =1 ;break ; }} else {
MSG("%s channel %s enabled for session %s",
-get_domain_str(dom.type),channel_name,session_name);
+get_domain_str(dom.type),chan.name, session_name); success = 1; }--
2.1.3_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 1 line
Jonathan Rajotte Julien
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): CAF4oYfGk8mWnBU3OdTNFXJxXfHFB-G1mOWciLGb-27qvskEKPA@mail.gmail.com
Quoted 7 lines · Jonathan Rajotte
Hey Phil,
Not sure if modifying user input without any warnings about it is a good idea. This clearly solve problems but do we want to solve it this way ?
It might be a better idea to warn the user about improper channel name or simply block the command and return an error.
Hi Jo,
I think you are right. I forgot to write about this, but I thought about it, and I think too
that it's a good idea. The only reason I didn't add warnings was that the user input
is already (potentially) modified without warnings:
strncpy(chan.name, channel_name, NAME_MAX);
chan.name[NAME_MAX - 1] = '\0';That is, channel names are truncated to (NAME_MAX - 1) characters:
lttng enable-channel -k aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaThe effective channel name is 254 'a's.
So, first question: should the name be modified at all, or should an error be displayed
when the name is invalid? I'm in favor of the second option.
Second question: if an error is to be displayed, should the validation happen in the
lttng CLI or in the session daemon? I'm in favor of the second option, as, for example,
session names are currently validaded on the session daemon side, which is legit since validation should be done by the model ultimately.
I'll let the maintainer decide whatever is the best direction for this. Honestly, I was
expecting a nack for this patch, which is more a discussion starter than anything
else ;-)
Phil
Quoted 129 lines
Quoted 44 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]>--- src/bin/lttng/commands/enable_channels.c | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)src/bin/lttng/commands/enable_channels.c +9
-2@@ -275,11 +275,39 @@ 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 */ +/* Copy channel name, sanitize and normalize it */ strncpy (chan.name, channel_name,NAME_MAX ); chan.name[NAME_MAX -1 ] ='\0' ; -DBG ("Enabling channel %s" , channel_name); +char *src, *dst; +int got_first =0 ; + +for (src = dst = chan.name; *src !='\0' ; ++src) { + *dst = *src; + +/* +* Channel name could be used in file names, so remove
src/bin/lttng/commands/enable_channels.c
Quoted 3 lines
src/bin/lttng/commands/enable_channels.c +3
-0+* invalid '/' +*/ +if (*dst !='/' ) {Maybe send some warning here ?
src/bin/lttng/commands/enable_channels.c
Quoted 11 lines
src/bin/lttng/commands/enable_channels.c +2
-0+/* +* Remove starting dots since this could create
+ * file names starting with dots, and
trace
+ * readers could interpret them as hidden
filessrc/bin/lttng/commands/enable_channels.c +3
-0+* and ignore them. +*/ +if (*dst !='.' ) {Same
Quoted 46 lines
src/bin/lttng/commands/enable_channels.c +13
-2+ got_first =1 ; + dst++; + }else if (got_first) { + dst++; + } + } + } + + *dst ='\0' ; + +DBG ("Enabling channel %s" , chan.name); ret =lttng_enable_channel (handle, &chan);if (ret <0 ) {@@ -288,19 +316,19 @@ static int enable_channel(char *session_name)case LTTNG_ERR_KERN_CHAN_EXIST :case LTTNG_ERR_UST_CHAN_EXIST :case LTTNG_ERR_CHAN_EXIST : -WARN ("Channel %s: %s (session %s)" , channel_name, +WARN ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); warn =1 ;break ;default : -ERR ("Channel %s: %s (session %s)" , channel_name, +ERR ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); error =1 ;break ; }} else {
MSG("%s channel %s enabled for session %s",
-get_domain_str(dom.type),channel_name,session_name);
+get_domain_str(dom.type),chan.name, session_name); success = 1; }Quoted 8 lines
--
2.1.3_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev--
Jonathan Rajotte Julien
A message that is not in the archive (sent off-list or not yet received): CAB4xu_01LPaLU3vrXKz-UJMjpjkWzVKQrc6MX1LR1MBTp3E+pA@mail.gmail.com
Quoted 33 lines · Philippe Proulx
Quoted 7 lines · Jonathan Rajotte
Hey Phil,
Not sure if modifying user input without any warnings about it is a good idea. This clearly solve problems but do we want to solve it this way ?
It might be a better idea to warn the user about improper channel name or simply block the command and return an error.
Hi Jo,
I think you are right. I forgot to write about this, but I thought about it, and I think too
that it's a good idea. The only reason I didn't add warnings was that the user input
is already (potentially) modified without warnings:strncpy(chan.name, channel_name, NAME_MAX); chan.name[NAME_MAX - 1] = '\0';That is, channel names are truncated to (
NAME_MAX- 1) characters:lttng enable-channel -k aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Quoted 5 lines
The effective channel name is 254 'a's.
So, first question: should the name be modified at all, or should an error be displayed
when the name is invalid? I'm in favor of the second option.
Agreed.
Quoted 8 lines
Second question: if an error is to be displayed, should the validation happen in the
lttng CLI or in the session daemon? I'm in favor of the second option, as, for example,
session names are currently validaded on the session daemon side, which is legit since validation should be done by the model ultimately.
Agreed, again. I think the protocol will not allow lttng-ctl to send a session name > 255 chars, so that may be an exception to handle on the client side. As for the rest, as long as we return a clear error code which the client can use to display a better error message than "Session creation failed", I'm all for it!
Quoted 5 lines
I'll let the maintainer decide whatever is the best direction for this. Honestly, I was
expecting a nack for this patch, which is more a discussion starter than anything
else ;-)
Good, NACK it is then! ;)
Please feel free to submit a patch or to include this discussion in a new bug entry.
Thanks!
Jérémie
Quoted 136 lines
Phil
Quoted 119 lines
Quoted 44 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]>--- src/bin/lttng/commands/enable_channels.c | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)src/bin/lttng/commands/enable_channels.c +9
-2@@ -275,11 +275,39 @@ 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 */ +/* Copy channel name, sanitize and normalize it */ strncpy (chan.name, channel_name,NAME_MAX ); chan.name[NAME_MAX -1 ] ='\0' ; -DBG ("Enabling channel %s" , channel_name); +char *src, *dst; +int got_first =0 ; + +for (src = dst = chan.name; *src !='\0' ; ++src) { + *dst = *src; + +/* +* Channel name could be used in file names, so remove
src/bin/lttng/commands/enable_channels.c
Quoted 3 lines
src/bin/lttng/commands/enable_channels.c +3
-0+* invalid '/' +*/ +if (*dst !='/' ) {Maybe send some warning here ?
src/bin/lttng/commands/enable_channels.c
Quoted 11 lines
src/bin/lttng/commands/enable_channels.c +2
-0+/* +* Remove starting dots since this could create
+ * file names starting with dots, and
trace
+ * readers could interpret them as hidden
filessrc/bin/lttng/commands/enable_channels.c +3
-0+* and ignore them. +*/ +if (*dst !='.' ) {Same
Quoted 50 lines
src/bin/lttng/commands/enable_channels.c +13
-2+ got_first =1 ; + dst++; + }else if (got_first) { + dst++; + } + } + } + + *dst ='\0' ; + +DBG ("Enabling channel %s" , chan.name); ret =lttng_enable_channel (handle, &chan);if (ret <0 ) {@@ -288,19 +316,19 @@ static int enable_channel(char *session_name)case LTTNG_ERR_KERN_CHAN_EXIST :case LTTNG_ERR_UST_CHAN_EXIST :case LTTNG_ERR_CHAN_EXIST : -WARN ("Channel %s: %s (session %s)" , channel_name, +WARN ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); warn =1 ;break ;default : -ERR ("Channel %s: %s (session %s)" , channel_name, +ERR ("Channel %s: %s (session %s)" , chan.name,lttng_strerror (ret), session_name); error =1 ;break ; }} else {
MSG("%s channel %s enabled for session %s",
-get_domain_str(dom.type),channel_name,session_name);
+get_domain_str(dom.type),chan.name, session_name); success = 1; }--
2.1.3Quoted 10 lines
Quoted 4 lines
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev--
Jonathan Rajotte Julien_______________________________________________
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