Add test cases for options sanitizing
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 Add test cases for options sanitizing
Test cases now covers options that require full string matches which were previously missing.
--- tests/regression/kernel/test_channel | 24 ++++++++++- .../regression/tools/snapshots/test_ust_streaming | 46 +++++++++++++++++++++- tests/regression/ust/test_event_basic | 8 +++- tests/regression/ust/test_event_perf | 6 ++- tests/utils/utils.sh | 26 ++++++++++++ 5 files changed, 106 insertions(+), 4 deletions(-)
tests/regression/kernel/test_channel +23 -1
@@ -19,10 +19,31 @@ TEST_DESC="Kernel tracer - Channel configuration" CURDIR=$(dirname $0)/ TESTDIR=$CURDIR/../.. -NUM_TESTS=8 +NUM_TESTS=14 source $TESTDIR/utils/utils.sh +function test_channel_output_opt() +{ + TRACE_PATH=$(mktemp -d) + SESSION_NAME="test_session_name" + CHANNEL_NAME="test_channel_name" + CHANNEL_NAME2="test_channel_name2" + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" + + # Try to create channel with invalid output types + lttng_enable_kernel_channel_fail "$SESSION_NAME" "$CHANNEL_NAME" "--output=splicethenice" + lttng_enable_kernel_channel_fail "$SESSION_NAME" "$CHANNEL_NAME" "--output=mmap-o-spread" + + # Try to create channel with valid output types + lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME" "--output=splice" + lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME2" "--output=mmap" + + destroy_lttng_session_ok "$SESSION_NAME" + + rm -rf "$TRACE_PATH" +} + function test_channel_buffer() { TRACE_PATH=$(mktemp -d)
@@ -69,6 +90,7 @@ skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || test_channel_buffer test_channel_buffer_too_large + test_channel_output_opt stop_lttng_sessiond }
tests/regression/tools/snapshots/test_ust_streaming +45 -1
64 lines not on this page · raw message
tests/regression/ust/test_event_basic +7 -1
@@ -24,7 +24,7 @@ SESSION_NAME="valid_filter" EVENT_NAME="tp:tptest" -NUM_TESTS=25 +NUM_TESTS=28 source $TESTDIR/utils/utils.sh
@@ -43,8 +43,14 @@ function test_event_basic() create_lttng_session_ok $SESSION_NAME2 $TRACE_PATH enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME + + enable_ust_lttng_channel_fail $SESSION_NAME2 $CHAN_NAME2 "--output=splice" + enable_ust_lttng_channel_fail $SESSION_NAME2 $CHAN_NAME2 "--output=mmap-o-spread" + enable_ust_lttng_channel_ok $SESSION_NAME2 $CHAN_NAME2 + enable_ust_lttng_channel_fail $SESSION_NAME2 $CHAN_NAME2 + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME2 $CHAN_NAME enable_ust_lttng_event_ok $SESSION_NAME2 $EVENT_NAME3 $CHAN_NAME2
tests/regression/ust/test_event_perf +5 -1
@@ -22,7 +22,7 @@ CURDIR=$(dirname $0)/ TESTDIR=$CURDIR/../.. SESSION_NAME="perf_counters" EVENT_NAME="tp:tptest" -NUM_TESTS=24 +NUM_TESTS=28 NR_ITER=1 NR_USEC_WAIT=1 TESTAPP_PATH="$TESTDIR/utils/testapp"
@@ -55,6 +55,10 @@ function test_parsing_raw() enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:test" + add_context_ust_fail $SESSION_NAME $CHAN_NAME "perform:thread:raw:r0110:test" + add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:threadish:raw:r0110:test" + add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:cpush:raw:r0110:test" + add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:rawesome:r0110:test" add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:rZZZ:test" add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:b0110:test" add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:"
tests/utils/utils.sh +26 -0
@@ -1282,6 +1282,32 @@ function lttng_snapshot_del_output_fail () lttng_snapshot_del_output 1 "$@" } +function lttng_snapshot_del_output_by_name () +{ + local expected_to_fail=$1 + local sess_name=$2 + local name=$3 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Deleted snapshot output name $name failed as expected" + else + ok $ret "Deleted snapshot output name $name" + fi +} + +function lttng_snapshot_del_output_by_name_ok () +{ + lttng_snapshot_del_output_by_name 0 "$@" +} + +function lttng_snapshot_del_output_by_name_fail () +{ + lttng_snapshot_del_output_by_name 1 "$@" +} + function lttng_snapshot_record () { local sess_name=$1
Signature · 1 line
2.11.0
Re: [PATCH lttng-tools] Fix: use strcmp instead of strncmp for full match cases
In reply to a message not in the archiveQuoted 4 lines · ----- On Mar 20, 2019, at 12:33 PM, Yannick Lamarre [email protected] wrote:
Except for a single case where the compared string is not ended with '\0', strncmp was replaced by strcmp in cases where a full string match was required. The exception was fixed with a length comparison prior the strncmp call.
I'm worried about the security implications associated with turning strncmp into strcmp in situations where the input could be controlled by an attacker.
This should come with a more thorough explanation detailing why this change is needed, and how comes it does not introduce a security risk, IOW, what is the scheme used to do input validation before using strcmp on that input ?
Thanks,
MAthieu
Quoted 182 lines
Fixes #987Signed-off-by Yannick Lamarre <[email protected]>---
src/bin/lttng-sessiond/agent.c | 3 +-- src/bin/lttng-sessiond/cmd.c | 2 +- src/bin/lttng-sessiond/snapshot.c | 2 +- src/bin/lttng-sessiond/ust-registry.c | 2 +- src/bin/lttng/commands/add_context.c | 8 ++++---- src/bin/lttng/commands/create.c | 4 +--- src/bin/lttng/commands/enable_channels.c | 4 ++-- src/common/lttng-elf.c | 1 + src/common/testpoint/testpoint.c | 4 ++-- 9 files changed, 14 insertions(+), 16 deletions(-)src/bin/lttng-sessiond/agent.c +1
-2@@ -149,8 +149,7 @@ static int ht_match_event(struct cds_lfht_node *node, }if (event->filter_expression) { -if (strncmp (event->filter_expression, key->filter_expression, -strlen (event->filter_expression)) !=0 ) { +if (strcmp (event->filter_expression, key->filter_expression) !=0 ) { goto no_match; } }src/bin/lttng-sessiond/cmd.c +1
-1@@ -2310,7 +2310,7 @@ static int _cmd_enable_event(struct ltt_session *session, }/* The wild card * means that everything should be enabled. */ -if (strncmp (event->name,"*" ,1 ) ==0 &&strlen (event->name) ==1 ) { +if (!strcmp (event->name,"*" )) { ret =event_agent_enable_all (usess, agt, event, filter, filter_expression); }else {src/bin/lttng-sessiond/snapshot.c +1
-1@@ -251,7 +251,7 @@ struct snapshot_output *snapshot_find_output_by_name(const char *name, cds_lfht_for_each_entry(snapshot->output_ht->ht, &iter.iter, output, node.node) { -if (!strncmp (output->name, name,strlen (name))) { +if (!strcmp (output->name, name)) {return output; }}src/bin/lttng-sessiond/ust-registry.c +1
-1@@ -48,7 +48,7 @@ static int ht_match_event(struct cds_lfht_node *node, const void *_key) key = _key;/* It has to be a perfect match. First, compare the event names. */ -if (strncmp (event->name, key->name,sizeof (event->name))) { +if (strcmp (event->name, key->name)) { goto no_match; }src/bin/lttng/commands/add_context.c +3
-3@@ -885,15 +885,15 @@ int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) cur_list =NULL ;switch (field_pos) {case 0 : -if (strncmp (next,"perf" ,4 ) !=0 ) { +if (strcmp (next,"perf" ) !=0 ) { ret =-1 ; goto end; }break ;case 1 : -if (strncmp (next,"cpu" ,3 ) ==0 ) { +if (strcmp (next,"cpu" ) ==0 ) { type->opt->ctx_type =CONTEXT_PERF_CPU_COUNTER ; - }else if (strncmp (next,"thread" ,4 ) ==0 ) { + }else if (strcmp (next,"thread" ) ==0 ) { type->opt->ctx_type =CONTEXT_PERF_THREAD_COUNTER ; }else {ret = -1;src/bin/lttng/commands/add_context.c +1
-1@@ -901,7 +901,7 @@ int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) }break ;case 2 : -if (strncmp (next,"raw" ,3 ) !=0 ) { +if (strcmp (next,"raw" ) !=0 ) { ret =-1 ; goto end;}src/bin/lttng/commands/create.c +1
-3@@ -264,9 +264,7 @@ static int create_session(void)*/ if ((strncmp (opt_session_name,DEFAULT_SESSION_NAME "-" ,strlen (DEFAULT_SESSION_NAME ) +1 ) ==0 ) || - (strncmp (opt_session_name,DEFAULT_SESSION_NAME , -strlen (DEFAULT_SESSION_NAME )) ==0 && -strlen (opt_session_name) ==strlen (DEFAULT_SESSION_NAME ))) { + (strcmp (opt_session_name,DEFAULT_SESSION_NAME ) ==0 )) {ERR ("%s is a reserved keyword for default session(s)" ,DEFAULT_SESSION_NAME ); ret =CMD_ERROR ;src/bin/lttng/commands/enable_channels.c +2
-2@@ -210,9 +210,9 @@ static int enable_channel(char *session_name)/* Setting channel output */ if (opt_output) { -if (!strncmp (output_mmap, opt_output,strlen (output_mmap))) { +if (!strcmp (output_mmap, opt_output)) { chan_opts.attr.output =LTTNG_EVENT_MMAP ; - }else if (!strncmp (output_splice, opt_output,strlen (output_splice))) { + }else if (!strcmp (output_splice, opt_output)) { chan_opts.attr.output =LTTNG_EVENT_SPLICE ; }else { ERR("Unknown output type %s. Possible values are: %s, %s\n",src/common/lttng-elf.c +1
-0@@ -975,6 +975,7 @@ int lttng_elf_get_sdt_probe_offsets(int fd, const char*provider_name, * and go to the next 4 byte alignement. */ if (note_type !=NOTE_STAPSDT_TYPE || + name_size !=strlen (NOTE_STAPSDT_NAME ) ||strncmp (curr_data_ptr,NOTE_STAPSDT_NAME , name_size) !=0 ) {continue ;}src/common/testpoint/testpoint.c +2
-2@@ -20,7 +20,7 @@#define _LGPL_SOURCE#include <dlfcn.h> /* for dlsym */ #include <stdlib.h> /* for getenv */ -#include <string.h> /* for strncmp */ +#include <string.h> /* for strcmp */ #include "testpoint.h" @@ -39,7 +39,7 @@ static void __attribute__((constructor))lttng_testpoint_check (void ) testpoint_env_val =getenv (lttng_testpoint_env_var);if (testpoint_env_val !=NULL - && (strncmp (testpoint_env_val,"1" ,1 ) ==0 )) { + &&strcmp (testpoint_env_val,"1" ) ==0 ) { lttng_testpoint_activated =1 ; }}
--
2.11.0_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com