Skip to contentSkip to conversation

ftrace: Fix unmatching locking in ftrace_regex_write()

PATCH In review Li Zefan 3 participants 8 messages Nov 3, 2009 – Nov 4, 2009

Subsystems (2)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/3 ftrace: Fix unmatching locking in ftrace_regex_write()

 # echo 'do_open : foo' > set_ftrace_filter
 (still holding ftrace_regex_lock when returning to user space!)

---

This patch is for .32

---
 kernel/trace/ftrace.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +3 -3
index 1ed514f..7cb6f19 100644
@@ -2199,15 +2199,15 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 		ret = ftrace_process_regex(parser->buffer,
 					   parser->idx, enable);
 		if (ret)
-			goto out;
+			goto out_unlock;
 
 		trace_parser_clear(parser);
 	}
 
 	ret = read;
-
+out_unlock:
 	mutex_unlock(&ftrace_regex_lock);
-out:
+
 	return ret;
 }
 
Signature · 1 line
1.6.3
author
#1 lore raw

PATCH 2/3 ftrace: Return EINVAL when writing invalid val to set_ftrace_filter

Currently it doesn't warn user on invald value:

 # echo nonexist_symbol > set_ftrace_filter

Better make it return failure.

---
 kernel/trace/ftrace.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +9 -3
index 7cb6f19..e0184b7 100644
@@ -1724,7 +1724,7 @@ ftrace_match_record(struct dyn_ftrace *rec, char *regex, int len, int type)
 	return ftrace_match(str, regex, len, type);
 }
 
-static void ftrace_match_records(char *buff, int len, int enable)
+static int ftrace_match_records(char *buff, int len, int enable)
 {
 	unsigned int search_len;
 	struct ftrace_page *pg;
@@ -1733,6 +1733,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
 	char *search;
 	int type;
 	int not;
+	int found = 0;
 
 	flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
 	type = filter_parse_regex(buff, len, &search, &not);
@@ -1750,6 +1751,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
 				rec->flags &= ~flag;
 			else
 				rec->flags |= flag;
+			found = 1;
 		}
 		/*
 		 * Only enable filtering if we have a function that
@@ -1759,6 +1761,8 @@ static void ftrace_match_records(char *buff, int len, int enable)
 			ftrace_filtered = 1;
 	} while_for_each_ftrace_rec();
 	mutex_unlock(&ftrace_lock);
+
+	return found;
 }
 
 static int
@@ -2151,8 +2155,10 @@ static int ftrace_process_regex(char *buff, int len, int enable)
 	func = strsep(&next, ":");
 
 	if (!next) {
-		ftrace_match_records(func, len, enable);
-		return 0;
+		if (ftrace_match_records(func, len, enable))
+			return 0;
+		else
+			return ret;
 	}
 
 	/* command found */
Signature · 1 line
1.6.3
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] ftrace: Return EINVAL when writing invalid val to set_ftrace_filter

Quoted 8 lines · Li Zefan

Currently it doesn't warn user on invald value:

 # echo nonexist_symbol > set_ftrace_filter

Better make it return failure.

---

But shouldn't we have the same kind of check from ftrace_match_module_records() if we haven't matched anything with the regex?

author
#3 lore raw

Re: [PATCH 2/3] ftrace: Return EINVAL when writing invalid val to set_ftrace_filter

Quoted 11 lines · Frederic Weisbecker
Quoted 8 lines · Li Zefan

Currently it doesn't warn user on invald value:

 # echo nonexist_symbol > set_ftrace_filter

Better make it return failure.

---

Quoted 6 lines

But shouldn't we have the same kind of check from ftrace_match_module_records() if we haven't matched anything with the regex?

Right, I overlooked it.

maintainer
#4 lore raw

Re: [PATCH 2/3] ftrace: Return EINVAL when writing invalid val to set_ftrace_filter

Quoted 12 lines · Li Zefan
Quoted 11 lines · Frederic Weisbecker
Quoted 8 lines · Li Zefan

Currently it doesn't warn user on invald value:

 # echo nonexist_symbol > set_ftrace_filter

Better make it return failure.

---

Quoted 9 lines
Quoted 6 lines

But shouldn't we have the same kind of check from ftrace_match_module_records() if we haven't matched anything with the regex?

Right, I overlooked it.

Only the first patch is urgent. I'll get that out and wait for you to update these other two (or just this one).

Thanks,

-- Steve

author
#5 lore raw

PATCH 3/3 function-graph: Allow writing the same val to set_graph_function

In reply to Li Zefan
 # echo 'do_open' > set_graph_function
 # echo 'do_open' >> set_graph_function
 bash: echo: write error: Invalid argument

Make it valid to write the same value to set_graph_function.

---
 kernel/trace/ftrace.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +2 -3
index e0184b7..eaf6a4d 100644
@@ -2549,10 +2549,9 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
 					exists = true;
 					break;
 				}
-			if (!exists) {
+			if (!exists)
 				array[(*idx)++] = rec->ip;
-				found = 1;
-			}
+			found = 1;
 		}
 	} while_for_each_ftrace_rec();
 
Signature · 1 line
1.6.3
#7 lore raw

[tip:tracing/urgent] ftrace: Fix unmatched locking in ftrace_regex_write()

In reply to Li Zefan
Commit-ID:  ed146b25942b428f8e8056587b7638ce76573c2f
Gitweb:     http://git.kernel.org/tip/ed146b25942b428f8e8056587b7638ce76573c2f
Author:     Li Zefan <[email protected]>
AuthorDate: Tue, 3 Nov 2009 08:55:38 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Wed, 4 Nov 2009 01:42:10 -0500

ftrace: Fix unmatched locking in ftrace_regex_write()

When a command is passed to the set_ftrace_filter, then the ftrace_regex_lock is still held going back to user space.

 # echo 'do_open : foo' > set_ftrace_filter
 (still holding ftrace_regex_lock when returning to user space!)

LKML-Reference: <[email protected]>

---
 kernel/trace/ftrace.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +3 -3
index 9c451a1..6dc4e5e 100644
@@ -2222,15 +2222,15 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 		ret = ftrace_process_regex(parser->buffer,
 					   parser->idx, enable);
 		if (ret)
-			goto out;
+			goto out_unlock;
 
 		trace_parser_clear(parser);
 	}
 
 	ret = read;
-
+out_unlock:
 	mutex_unlock(&ftrace_regex_lock);
-out:
+
 	return ret;
 }