tracing/uprobe_event: Fix strncpy corner case
authorMasami Hiramatsu <mhiramat@kernel.org>
Tue, 10 Apr 2018 12:20:08 +0000 (21:20 +0900)
committerIngo Molnar <mingo@kernel.org>
Tue, 10 Apr 2018 18:14:11 +0000 (20:14 +0200)
Fix string fetch function to terminate with NUL.
It is OK to drop the rest of string.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: security@kernel.org
Cc: 范龙飞 <long7573@126.com>
Fixes: 5baaa59ef09e ("tracing/probes: Implement 'memory' fetch method for uprobes")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/trace/trace_uprobe.c

index 2014f4351ae0a40e5d0985d58f03ce9332d12f6a..0d450b40988edbb1184dd270537a9162ddf58336 100644 (file)
@@ -151,6 +151,8 @@ static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
                return;
 
        ret = strncpy_from_user(dst, src, maxlen);
+       if (ret == maxlen)
+               dst[--ret] = '\0';
 
        if (ret < 0) {  /* Failed to fetch string */
                ((u8 *)get_rloc_data(dest))[0] = '\0';