ftrace: Fix MATCH_END_ONLY filter matching
PATCH 1/4 ftrace: Fix MATCH_END_ONLY filter matching
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like bar_foo_foo:
# echo '*io' > set_ftrace_filter # cat set_ftrace_filter | grep 'req_bio_endio' # cat available_filter_functions | grep 'req_bio_endio' req_bio_endio
--- kernel/trace/ftrace.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +3 -3
@@ -1690,7 +1690,7 @@ ftrace_regex_lseek(struct file *file, loff_t offset, int origin)static int ftrace_match (char *str,char *regex,int len,int type) {int matched =0 ; -char *ptr; +int slen;switch (type) {case MATCH_FULL :
@@ -1706,8 +1706,8 @@ static int ftrace_match(char *str, char *regex, int len, int type) matched =1 ;break ;case MATCH_END_ONLY : - ptr =strstr (str, regex); -if (ptr && (ptr[len] ==0 )) + slen =strlen (str); +if (slen >= len &&memcpy (str + slen - len, regex, len)) matched =1 ;break ; }
Signature · 1 line
1.6.3
PATCH 2/4 tracing/filters: Fix MATCH_FULL filter matching for PTR_STRING
MATCH_FULL matching for PTR_STRING is not working correctly:
# echo 'func == vt' > events/bkl/lock_kernel/filter
# echo 1 > events/bkl/lock_kernel/enable
...
# cat trace
Xorg-1484 [000] 1973.392586: lock_kernel: ... func=vt_ioctl()
gpm-1402 [001] 1974.027740: lock_kernel: ... func=vt_ioctl()We should pass to regex.match(..., len) the length (including '\0') of the source string instead of the length of the pattern string.
--- kernel/trace/trace_events_filter.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
kernel/trace/trace_events_filter.c +3 -4
@@ -211,8 +211,9 @@ static int filter_pred_pchar(struct filter_pred *pred, void *event, {char **addr = (char **)(event + pred->offset);int cmp, match; +int len =strlen (*addr) +1 ;/* including tailing '\0' */ - cmp = pred->regex.match (*addr, &pred->regex, pred->regex.field_len); + cmp = pred->regex.match (*addr, &pred->regex, len); match = cmp ^ pred->not;
@@ -781,10 +782,8 @@ static int filter_add_pred(struct filter_parse_state *ps, pred->regex.field_len = field->size; }else if (field->filter_type ==FILTER_DYN_STRING ) fn = filter_pred_strloc; -else { +else fn = filter_pred_pchar; - pred->regex.field_len =strlen (pred->regex.pattern); - } }else {if (field->is_signed) ret =strict_strtoll (pred->regex.pattern,0 , &val);
Signature · 1 line
1.6.3
PATCH 3/4 tracing/filters: Fix MATCH_FRONT_ONLY filter matching
In reply to Li ZefanMATCH_FRONT_ONLY matching works exactly as MATCH_FULL.
We should pass the length of the pattern to strncmp().
--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +1 -1
@@ -262,7 +262,7 @@ static int regex_match_full(char *str, struct regex *r, int len)static int regex_match_front (char *str,struct regex *r,int len) { -if (strncmp (str, r->pattern, len) ==0 ) +if (strncmp (str, r->pattern, r->len) ==0 )return 1 ;return 0 ; }
Signature · 1 line
1.6.3
PATCH 4/4 tracing/filters: Fix MATCH_EBD_ONLY filter matching
In reply to Li ZefanFor '*foo' pattern, we should allow any string ending with 'foo', but tracing filter incorrectly disallows strings matching regex expression ".*foo.*foo".
--- kernel/trace/trace_events_filter.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_filter.c +3 -2
@@ -276,9 +276,10 @@ static int regex_match_middle(char *str, struct regex *r, int len)static int regex_match_end (char *str,struct regex *r,int len) { -char *ptr =strstr (str, r->pattern); +int strlen = len -1 ; -if (ptr && (ptr[r->len] ==0 )) +if (strlen >= r->len && + !memcmp (str + strlen - r->len, r->pattern, r->len))return 1 ;return 0 ; }
Signature · 1 line
1.6.3
Re: [PATCH 3/4] tracing/filters: Fix MATCH_FRONT_ONLY filter matching
In reply to Li ZefanQuoted 14 lines · Li Zefan
MATCH_FRONT_ONLYmatching works exactly asMATCH_FULL.We should pass the length of the pattern to
strncmp().Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_events_filter.c +0
-0
kernel/trace/trace_events_filter.c static int regex_match_full(char *str, struct regex *r, int len) · line 268
Quoted 8 lines
kernel/trace/trace_events_filter.c +1
-1@@ -262,7 +262,7 @@ static int regex_match_full(char *str, struct regex *r, int len)static int regex_match_front (char *str,struct regex *r,int len) { -if (strncmp (str, r->pattern, len) ==0 ) +if (strncmp (str, r->pattern, r->len) ==0 )return 1 ;return 0 ; }
But it was working before the fix to match full. The MATCH_FULL fix is nice but it also brings a new bug that is fixed in this patch.
Could you perhaps rework the MATCH_FULL fix to avoid that?
Thanks.
Re: [PATCH 2/4] tracing/filters: Fix MATCH_FULL filter matching for PTR_STRING
In reply to Li ZefanQuoted 9 lines · Li Zefan
MATCH_FULLmatching forPTR_STRINGis not working correctly:# echo 'func == vt' > events/bkl/lock_kernel/filter # echo 1 > events/bkl/lock_kernel/enable ... # cat trace Xorg-1484 [000] 1973.392586: lock_kernel: ... func=vt_ioctl() gpm-1402 [001] 1974.027740: lock_kernel: ... func=vt_ioctl()
Quoted 4 lines
We should pass to
regex.match(..., len)the length (including '\0') of the source string instead of the length of the pattern string.Signed-off-by Li Zefan <[email protected]>
This patch is cool but it seems to also break middle and end matching (at least what was working with end matching :)
I know you fix that in the subsequent patches, but please avoid that. A fix should not bring another known bug, event if it's fixed in the same batch.
Thanks.
Quoted 10 lines · Li Zefan
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:# echo '*io' > set_ftrace_filter # cat set_ftrace_filter | grep 'req_bio_endio' # cat available_filter_functions | grep 'req_bio_endio' req_bio_endioSigned-off-by Li Zefan <[email protected]>
I have pending fixes in queue, I'm taking this one too.
Thanks!
2009/12/11 Li Zefan <[email protected]>:
Quoted 3 lines
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:
[...]
Quoted 6 lines
case
MATCH_END_ONLY:
- ptr =strstr(str, regex);
- if (ptr && (ptr[len] == 0))
+ slen = strlen(str);
+ if (slen >= len &&memcpy(str + slen - len, regex, len)) matched = 1;
Shouldn't that be memcmp() == 0? I don't see how memcpy might serve as a compare operator.
Fred.
Quoted 12 lines · Frederic Riss
2009/12/11 Li Zefan <[email protected]>:
Quoted 3 lines
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:[...]
Quoted 6 lines
case
MATCH_END_ONLY:
- ptr =strstr(str, regex);
- if (ptr && (ptr[len] == 0))
+ slen = strlen(str);
+ if (slen >= len &&memcpy(str + slen - len, regex, len)) matched = 1;
Quoted 4 lines
Shouldn't that be
memcmp()== 0? I don't see how memcpy might serve as a compare operator.Fred.
Oh you're right, I reviewed it too quickly. Perhaps the star's alignment made it possible for only one Frederic to review it the right way...
Steven Rostedt
maintainerQuoted 16 lines · Frederic Weisbecker
Quoted 15 lines · Frederic Riss
2009/12/11 Li Zefan <[email protected]>:
Quoted 3 lines
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:[...]
kernel/trace/ftrace.c static int ftrace_match(char *str, char *regex, int len, int type) · line 1711
Quoted 6 lines
case
MATCH_END_ONLY:kernel/trace/ftrace.c +2
-2- ptr =strstr (str, regex); -if (ptr && (ptr[len] ==0 )) + slen =strlen (str); +if (slen >= len &&memcpy (str + slen - len, regex, len)) matched =1 ;Shouldn't that be
memcmp()== 0? I don't see how memcpy might serve as a compare operator.
Quoted 7 lines
Quoted 1 line
Fred.
Oh you're right, I reviewed it too quickly. Perhaps the star's alignment made it possible for only one Frederic to review it the right way...
The stars are still fuzzy to me. How does memcpy work here?
-- Steve
Steven Rostedt
maintainerRe: [PATCH 4/4] tracing/filters: Fix MATCH_EBD_ONLY filter matching
In reply to Li ZefanQuoted 14 lines · Li Zefan
For '*foo' pattern, we should allow any string ending with 'foo', but tracing filter incorrectly disallows strings matching regex expression ".*foo.*foo".
Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_events_filter.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)kernel/trace/trace_events_filter.c +0
-0
kernel/trace/trace_events_filter.c static int regex_match_middle(char *str, struct regex *r, int len) · line 282
Quoted 9 lines
kernel/trace/trace_events_filter.c +3
-2@@ -276,9 +276,10 @@ static int regex_match_middle(char *str, struct regex *r, int len)static int regex_match_end (char *str,struct regex *r,int len) { -char *ptr =strstr (str, r->pattern); +int strlen = len -1 ; -if (ptr && (ptr[r->len] ==0 )) +if (strlen >= r->len && + !memcmp (str + strlen - r->len, r->pattern, r->len))
Please use memcmp() == 0, I've seen too many bugs with !*cmp as well as with *cmp, because humans tend to think instinctively when reading this that ! is not a match. With "== 0" we think that "==" is a match and
"!=" is a miss.
Thanks,
-- Steve
Quoted 3 lines
kernel/trace/trace_events_filter.c +0
-0return 1 ;return 0 ; }
Quoted 20 lines · Steven Rostedt
Quoted 19 lines · Frederic Weisbecker
Quoted 16 lines · Frederic Riss
2009/12/11 Li Zefan <[email protected]>:
Quoted 3 lines
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:[...]
kernel/trace/ftrace.c static int ftrace_match(char *str, char *regex, int len, int type) · line 1711
Quoted 6 lines
case
MATCH_END_ONLY:kernel/trace/ftrace.c +2
-2- ptr =strstr (str, regex); -if (ptr && (ptr[len] ==0 )) + slen =strlen (str); +if (slen >= len &&memcpy (str + slen - len, regex, len)) matched =1 ;Shouldn't that be
memcmp()== 0? I don't see how memcpy might serve as a compare operator.Fred.
Quoted 6 lines
Quoted 4 lines
Oh you're right, I reviewed it too quickly. Perhaps the star's alignment made it possible for only one Frederic to review it the right way...
The stars are still fuzzy to me. How does memcpy work here?
It doesn't, I guess Li intended to use memcmp.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 3 lines
For '*foo' pattern, we should allow any string ending with 'foo', but ftrace filter incorrectly disallows strings like
bar_foo_foo:[...]
kernel/trace/ftrace.c static int ftrace_match(char *str, char *regex, int len, int type) · line 1711
Quoted 6 lines
case
MATCH_END_ONLY:kernel/trace/ftrace.c +2
-2- ptr =strstr (str, regex); -if (ptr && (ptr[len] ==0 )) + slen =strlen (str); +if (slen >= len &&memcpy (str + slen - len, regex, len)) matched =1 ;Shouldn't that be
memcmp()== 0? I don't see how memcpy might serve as a compare operator.Fred.
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Oh you're right, I reviewed it too quickly. Perhaps the star's alignment made it possible for only one Frederic to review it the right way...
The stars are still fuzzy to me. How does memcpy work here?
It doesn't, I guess Li intended to use memcmp.
Oops, I forgot to fix this before sending the patch out.. :(
Re: [PATCH 4/4] tracing/filters: Fix MATCH_EBD_ONLY filter matching
In reply to Steven RostedtQuoted 5 lines
Quoted 5 lines
static int
regex_match_end(char *str, struct regex *r, int len){kernel/trace/trace_events_filter.c +1
-1-char *ptr =strstr (str, r->pattern); +int strlen = len -1 ;
Quoted 9 lines
kernel/trace/trace_events_filter.c static int regex_match_middle(char *str, struct regex *r, int len) · line 282
Quoted 3 lines
kernel/trace/trace_events_filter.c +2
-1-if (ptr && (ptr[r->len] ==0 )) +if (strlen >= r->len && + !memcmp (str + strlen - r->len, r->pattern, r->len))Please use
memcmp()== 0, I've seen too many bugs with !*cmp as well as with *cmp, because humans tend to think instinctively when reading this that ! is not a match. With "== 0" we think that "==" is a match and
"!=" is a miss.
Though I sometimes don't care much about this, I do think memcmp() == 0 is better.
Re: [PATCH 2/4] tracing/filters: Fix MATCH_FULL filter matching for PTR_STRING
In reply to Frederic WeisbeckerQuoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Li Zefan
MATCH_FULLmatching forPTR_STRINGis not working correctly:# echo 'func == vt' > events/bkl/lock_kernel/filter # echo 1 > events/bkl/lock_kernel/enable ... # cat trace Xorg-1484 [000] 1973.392586: lock_kernel: ... func=vt_ioctl() gpm-1402 [001] 1974.027740: lock_kernel: ... func=vt_ioctl()
Quoted 8 lines
Quoted 4 lines
We should pass to
regex.match(..., len)the length (including '\0') of the source string instead of the length of the pattern string.Signed-off-by Li Zefan <[email protected]>This patch is cool but it seems to also break middle and end matching (at least what was working with end matching :)
No, it won't, unless I miss something.
I changed what value ptr_string passes the length param to match(), but this param is not used in match_middle and match_end.
It does break match_front for ptr_string, but that's because the mixture of 2 bugs happened to make things right. I can sort this out by reordering the 2 patches.
Quoted 4 lines
I know you fix that in the subsequent patches, but please avoid that. A fix should not bring another known bug, event if it's fixed in the same batch.
Re: [PATCH 3/4] tracing/filters: Fix MATCH_FRONT_ONLY filter matching
In reply to Frederic WeisbeckerQuoted 16 lines · Frederic Weisbecker
Quoted 15 lines · Li Zefan
MATCH_FRONT_ONLYmatching works exactly asMATCH_FULL.We should pass the length of the pattern to
strncmp().Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_events_filter.c +0
-0@@ -262,7 +262,7 @@ static int regex_match_full(char *str, struct regex *r, int len)
Quoted 10 lines
kernel/trace/trace_events_filter.c static int regex_match_full(char *str, struct regex *r, int len) · line 268
Quoted 7 lines
kernel/trace/trace_events_filter.c +1
-1static int regex_match_front (char *str,struct regex *r,int len) { -if (strncmp (str, r->pattern, len) ==0 ) +if (strncmp (str, r->pattern, r->len) ==0 )return 1 ;return 0 ; }But it was working before the fix to match full.
No, it was not working for dyn_string and static_string. And as I explained it happened to work for ptr_string by the mixture of 2 bugs.
Quoted 3 lines
The
MATCH_FULLfix is nice but it also brings a new bug that is fixed in this patch.
Re: [PATCH 2/4] tracing/filters: Fix MATCH_FULL filter matching for PTR_STRING
In reply to Li ZefanQuoted 20 lines · Li Zefan
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Li Zefan
MATCH_FULLmatching forPTR_STRINGis not working correctly:# echo 'func == vt' > events/bkl/lock_kernel/filter # echo 1 > events/bkl/lock_kernel/enable ... # cat trace Xorg-1484 [000] 1973.392586: lock_kernel: ... func=vt_ioctl() gpm-1402 [001] 1974.027740: lock_kernel: ... func=vt_ioctl()Quoted 8 lines
Quoted 4 lines
We should pass to
regex.match(..., len)the length (including '\0') of the source string instead of the length of the pattern string.Signed-off-by Li Zefan <[email protected]>This patch is cool but it seems to also break middle and end matching (at least what was working with end matching :)
Quoted 8 lines
No, it won't, unless I miss something.
I changed what value
ptr_stringpasses the length param tomatch(), but this param is not used inmatch_middleandmatch_end.It does break
match_frontforptr_string, but that's because the mixture of 2 bugs happened to make things right. I can sort this out by reordering the 2 patches.
I made a mistake. I meant it breaks match front. As previously it was taking the pattern length as a parameter and now it takes the string length to compare.
But well, the things were so broken already that I'm not sure we need bisectable deltas... :)
Re: [PATCH 3/4] tracing/filters: Fix MATCH_FRONT_ONLY filter matching
In reply to Li ZefanQuoted 28 lines · Li Zefan
Quoted 16 lines · Frederic Weisbecker
Quoted 15 lines · Li Zefan
MATCH_FRONT_ONLYmatching works exactly asMATCH_FULL.We should pass the length of the pattern to
strncmp().Signed-off-by Li Zefan <[email protected]>--- kernel/trace/trace_events_filter.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_events_filter.c +0
-0@@ -262,7 +262,7 @@ static int regex_match_full(char *str, struct regex *r, int len)Quoted 10 lines
kernel/trace/trace_events_filter.c static int regex_match_full(char *str, struct regex *r, int len) · line 268
Quoted 7 lines
kernel/trace/trace_events_filter.c +1
-1static int regex_match_front (char *str,struct regex *r,int len) { -if (strncmp (str, r->pattern, len) ==0 ) +if (strncmp (str, r->pattern, r->len) ==0 )return 1 ;return 0 ; }But it was working before the fix to match full.
Quoted 3 lines
No, it was not working for
dyn_stringandstatic_string. And as I explained it happened to work forptr_stringby the mixture of 2 bugs.
Ah, you're right.
Re: [PATCH 2/4] tracing/filters: Fix MATCH_FULL filter matching for PTR_STRING
In reply to Li ZefanQuoted 20 lines · Li Zefan
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Li Zefan
MATCH_FULLmatching forPTR_STRINGis not working correctly:# echo 'func == vt' > events/bkl/lock_kernel/filter # echo 1 > events/bkl/lock_kernel/enable ... # cat trace Xorg-1484 [000] 1973.392586: lock_kernel: ... func=vt_ioctl() gpm-1402 [001] 1974.027740: lock_kernel: ... func=vt_ioctl()Quoted 8 lines
Quoted 4 lines
We should pass to
regex.match(..., len)the length (including '\0') of the source string instead of the length of the pattern string.Signed-off-by Li Zefan <[email protected]>This patch is cool but it seems to also break middle and end matching (at least what was working with end matching :)
Quoted 8 lines
No, it won't, unless I miss something.
I changed what value
ptr_stringpasses the length param tomatch(), but this param is not used inmatch_middleandmatch_end.It does break
match_frontforptr_string, but that's because the mixture of 2 bugs happened to make things right. I can sort this out by reordering the 2 patches.
No, no need to. I was just confused :)