Subject: [PATCH] bpf: fix check of allowed specifiers in bpf_trace_printk

From: Martynas Pumputis <[email-masked]>
Date: Thu, 22 Nov 2018 17:00:30 +0100

A format string consisting of "%p" or "%s" followed by an invalid
specifier (e.g. "%p%\n" or "%s%") could pass the check which
would make format_decode (lib/vsprintf.c) to warn.

Reported-by: [email-masked]
Signed-off-by: Martynas Pumputis <[email-masked]>
---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 08fcfe440c63..9ab05736e1a1 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -225,6 +225,8 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
 						    (void *) (long) unsafe_addr,
 						    sizeof(buf));
 			}
+			if (fmt[i] == '%')
+				i--;
 			continue;
 		}
 
-- 
2.19.1