Skip to content

Commit aa1c42c

Browse files
rostedtjfvogel
authored andcommitted
tracing: Fix filter string testing
commit a8c5b0ed89a3f2c81c6ae0b041394e6eea0e7024 upstream. The filter string testing uses strncpy_from_kernel/user_nofault() to retrieve the string to test the filter against. The if() statement was incorrect as it considered 0 as a fault, when it is only negative that it faulted. Running the following commands: # cd /sys/kernel/tracing # echo "filename.ustring ~ \"/proc*\"" > events/syscalls/sys_enter_openat/filter # echo 1 > events/syscalls/sys_enter_openat/enable # ls /proc/$$/maps # cat trace Would produce nothing, but with the fix it will produce something like: ls-1192 [007] ..... 8169.828333: sys_openat(dfd: ffffffffffffff9c, filename: 7efc18359904, flags: 80000, mode: 0) Link: https://lore.kernel.org/all/CAEf4BzbVPQ=BjWztmEwBPRKHUwNfKBkS3kce-Rzka6zvbQeVpg@mail.gmail.com/ Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 77360f9 ("tracing: Add test for user space strings when filtering on string pointers") Reported-by: Andrii Nakryiko <[email protected]> Reported-by: Mykyta Yatsenko <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 5683eaf4eeede8af0e1e36171d306ec986c26de5) Signed-off-by: Jack Vogel <[email protected]>
1 parent 8bc7280 commit aa1c42c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static __always_inline char *test_string(char *str)
808808
kstr = ubuf->buffer;
809809

810810
/* For safety, do not trust the string pointer */
811-
if (!strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE))
811+
if (strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE) < 0)
812812
return NULL;
813813
return kstr;
814814
}
@@ -827,7 +827,7 @@ static __always_inline char *test_ustring(char *str)
827827

828828
/* user space address? */
829829
ustr = (char __user *)str;
830-
if (!strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE))
830+
if (strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE) < 0)
831831
return NULL;
832832

833833
return kstr;

0 commit comments

Comments
 (0)