From: Jovi Zhang <[email protected]>

Without this patch, we can register a uprobe event for a directory.
Enabling such a uprobe event would anyway fail.

Example:
$ echo 'p /bin:0x4245c0' > /sys/kernel/debug/tracing/uprobe_events

However dirctories cannot be valid targets for uprobe.
Hence verify if the target is a regular file during the probe
registration.

Signed-off-by: Jovi Zhang <[email protected]>
Acked-by: Srikar Dronamraju <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
---
 kernel/trace/trace_uprobe.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 4ff9ca4..0bef43c 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -257,6 +257,10 @@ static int create_trace_uprobe(int argc, char **argv)
                goto fail_address_parse;
 
        inode = igrab(path.dentry->d_inode);
+        if (!S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)) {
+               ret = -EINVAL;
+               goto fail_address_parse;
+       }
 
        argc -= 2;
        argv += 2;
@@ -356,7 +360,7 @@ fail_address_parse:
        if (inode)
                iput(inode);
 
-       pr_info("Failed to parse address.\n");
+       pr_info("Failed to parse address or file.\n");
 
        return ret;
 }
-- 
1.7.10.4


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to