* [PATCH] uprobe: Find last occurrence of ':' when parsing uprobe PATH:OFFSET
@ 2017-01-13 16:58 Kenny Yu
2017-01-13 17:14 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Kenny Yu @ 2017-01-13 16:58 UTC (permalink / raw)
To: rostedt, mingo; +Cc: osandov, kennyyu, linux-kernel, kernel-team
Previously, `create_trace_uprobe` found the *first* occurence
of the ':' character when parsing `PATH:OFFSET` for a uprobe.
However, if the path contains a ':' character, then the function
would parse the path incorrectly. Even worse, if the path does not
exist, the subsequent call to `kern_path()` would set `ret` to
`ENOENT`, leading to very cryptic errno values in user space.
The fix is to find the *last* occurence of ':'.
How to repro:: The write fails with "No such file or directory", suggesting
incorrectly that the `uprobe_events` file does not exist.
$ mkdir testing && cd testing
$ cp /bin/bash .
$ cp /bin/bash ./bash:with:colon
$ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this works
$ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this doesn't
-bash: echo: write error: No such file or directory
With the patch:
$ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this still works
$ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this works now too!
$ cat /sys/kernel/debug/tracing/uprobe_events
p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x0000000000000006
p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x0000000000000006
Signed-off-by: Kenny Yu <kennyyu@fb.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
---
kernel/trace/trace_uprobe.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index c534854..b916b26 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -431,7 +431,8 @@ static int create_trace_uprobe(int argc, char **argv)
pr_info("probe point must be have a filename.\n");
return -EINVAL;
}
- arg = strchr(argv[1], ':');
+ /* Find the last occurrence, in case the path contains ':' too. */
+ arg = strrchr(argv[1], ':');
if (!arg) {
ret = -EINVAL;
goto fail_address_parse;
--
2.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] uprobe: Find last occurrence of ':' when parsing uprobe PATH:OFFSET
2017-01-13 16:58 [PATCH] uprobe: Find last occurrence of ':' when parsing uprobe PATH:OFFSET Kenny Yu
@ 2017-01-13 17:14 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2017-01-13 17:14 UTC (permalink / raw)
To: Kenny Yu; +Cc: mingo, osandov, linux-kernel, kernel-team
On Fri, 13 Jan 2017 08:58:34 -0800
Kenny Yu <kennyyu@fb.com> wrote:
> Previously, `create_trace_uprobe` found the *first* occurence
> of the ':' character when parsing `PATH:OFFSET` for a uprobe.
> However, if the path contains a ':' character, then the function
> would parse the path incorrectly. Even worse, if the path does not
> exist, the subsequent call to `kern_path()` would set `ret` to
> `ENOENT`, leading to very cryptic errno values in user space.
>
> The fix is to find the *last* occurence of ':'.
>
> How to repro:: The write fails with "No such file or directory", suggesting
> incorrectly that the `uprobe_events` file does not exist.
>
> $ mkdir testing && cd testing
> $ cp /bin/bash .
> $ cp /bin/bash ./bash:with:colon
> $ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this works
> $ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this doesn't
> -bash: echo: write error: No such file or directory
>
> With the patch:
>
> $ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this still works
> $ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this works now too!
> $ cat /sys/kernel/debug/tracing/uprobe_events
> p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x0000000000000006
> p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x0000000000000006
>
Thanks! I'll add this to my queue.
-- Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-13 17:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-13 16:58 [PATCH] uprobe: Find last occurrence of ':' when parsing uprobe PATH:OFFSET Kenny Yu
2017-01-13 17:14 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).