tracing: Fix misuse of strncpy to copy boot params
Ingo,
Please pull this fixlet for .32 that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
tracing/fixes
Frederic Weisbecker (1):
tracing: Fix misuse of strncpy to copy boot params
kernel/trace/ftrace.c | 4 ++-- kernel/trace/trace.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
---
Quoted 1 line
From
f44bec1286f516d921210a1bf843725f5d4b86efMon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Wed, 14 Oct 2009 21:17:00 +0200
Subject: [PATCH] tracing: Fix misuse of strncpy to copy boot params
While copying ftrace string boot parameters into buffers, we use strncpy by passing the whole buffer size instead of the max strlen the buffers can host (which is buffer size - 1), this might lead to non-null terminated strings.
Fix that by simply using strlcpy instead.
--- kernel/trace/ftrace.c | 4 ++-- kernel/trace/trace.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +2 -2
@@ -2300,14 +2300,14 @@ static char ftrace_filter_buf[FTRACE_FILTER_SIZE] __initdata;static int __init set_ftrace_notrace (char *str) { -strncpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +strlcpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { -strncpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +strlcpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
kernel/trace/trace.c +1 -1
@@ -131,7 +131,7 @@ static char *default_bootup_tracer;static int __init set_ftrace (char *str) { -strncpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); +strlcpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); default_bootup_tracer = bootup_tracer_buf;/* We are using ftrace early, expand it */ ring_buffer_expanded =1 ;
Signature · 1 line
1.6.2.3
kernel/trace/trace.c static char *default_bootup_tracer; · line 134
Quoted 10 lines
kernel/trace/trace.c +1
-1@@ -131,7 +131,7 @@ static char *default_bootup_tracer;static int __init set_ftrace (char *str) { -strncpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); +strlcpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );
Actually using strncpy() here is fine.
See how the str buf is used:
int register_tracer(struct tracer *type)
{
...
if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE))
...
}Quoted 3 lines
kernel/trace/trace.c +0
-0default_bootup_tracer = bootup_tracer_buf;/* We are using ftrace early, expand it */ ring_buffer_expanded =1 ;
Quoted 13 lines · Li Zefan
kernel/trace/trace.c static char *default_bootup_tracer; · line 134
Quoted 10 lines
kernel/trace/trace.c +1
-1@@ -131,7 +131,7 @@ static char *default_bootup_tracer;static int __init set_ftrace (char *str) { -strncpy (bootup_tracer_buf, str,MAX_TRACER_SIZE ); +strlcpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );Actually using
strncpy()here is fine.
Quoted 8 lines
See how the str buf is used:
int
register_tracer(struct tracer *type){ ... if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) ... }
Yeah. I can remove the change for this buffer and send another pull request.
Thanks.
Quoted 3 lines
Quoted 3 lines
kernel/trace/trace.c +0
-0default_bootup_tracer = bootup_tracer_buf;/* We are using ftrace early, expand it */ ring_buffer_expanded =1 ;