Skip to contentSkip to conversation

tracing: some fixes for 2.6.31

PATCH In review Li Zefan 3 participants 11 messages Jun 15, 2009 Tracing

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

cover tracing: some fixes for 2.6.31

Some small but not trival fixes for 2.6.31:

[PATCH 1/4] tracing: fix a typo in tracing_cpumask_write() [PATCH 2/4] tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation [PATCH 3/4] tracing/filters: operand can be negative [PATCH 4/4] tracing/filters: strloc should be unsigned short

---
 kernel/trace/trace.c               |    8 ++++----
 kernel/trace/trace_events_filter.c |    9 +++++++--
 2 files changed, 11 insertions(+), 6 deletions(-)
author
#1 lore raw

PATCH 1/4 tracing: fix a typo in tracing_cpumask_write()

It's tracing_cpumask_new that should be kfree()ed.

This causes tracing_cpumask to be freed due to the typo:

 # echo z > tracing_cpumask
 bash: echo: write error: Invalid argument

And subsequent reads/writes to tracing_cpuamsk will access this already-freed tracing_cpumask, thus may lead to crash.

[ Impact: fix leak and crash when writing invalid val to tracing_cpumask ]

---
 kernel/trace/trace.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
index 8acd9b8..7355a38 100644
@@ -2191,11 +2191,12 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
 	if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
 		return -ENOMEM;
 
-	mutex_lock(&tracing_cpumask_update_lock);
 	err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
 	if (err)
 		goto err_unlock;
 
+	mutex_lock(&tracing_cpumask_update_lock);
+
 	local_irq_disable();
 	__raw_spin_lock(&ftrace_max_lock);
 	for_each_tracing_cpu(cpu) {
@@ -2223,8 +2224,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
 	return count;
 
 err_unlock:
-	mutex_unlock(&tracing_cpumask_update_lock);
-	free_cpumask_var(tracing_cpumask);
+	free_cpumask_var(tracing_cpumask_new);
 
 	return err;
 }
Signature · 1 line
1.5.4.rc3
author
#3 lore raw

PATCH 2/4 tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation

In reply to Li Zefan

Atomic allocation is not needed here.

[ Impact: clean up ]

---
 kernel/trace/trace.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace.c +1 -1
index 7355a38..0f57f1b 100644
@@ -3627,7 +3627,7 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
 	struct trace_seq *s;
 	unsigned long cnt;
 
-	s = kmalloc(sizeof(*s), GFP_ATOMIC);
+	s = kmalloc(sizeof(*s), GFP_KERNEL);
 	if (!s)
 		return ENOMEM;
 
Signature · 1 line
1.5.4.rc3
author
#5 lore raw

PATCH 3/4 tracing/filters: operand can be negative

In reply to Li Zefan

This should be a bug:

 # cat format
 name: foo_bar
 ID: 71
 format:
	 ...
         field:int bar;  offset:24;      size:4;
 # echo 'bar < 0' > filter
 # echo 'bar < -1' > filter
 bash: echo: write error: Invalid argument

[ Impact: fix to allow negative operand in filer expr ]

---
 kernel/trace/trace_events_filter.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +6 -1
index db6e54b..1d81923 100644
@@ -546,6 +546,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
 	filter_pred_fn_t fn;
 	unsigned long long val;
 	int string_type;
+	int ret;
 
 	pred->fn = filter_pred_none;
 
@@ -581,7 +582,11 @@ static int filter_add_pred(struct filter_parse_state *ps,
 			pred->not = 1;
 		return filter_add_pred_fn(ps, call, pred, fn);
 	} else {
-		if (strict_strtoull(pred->str_val, 0, &val)) {
+		if (field->is_signed)
+			ret = strict_strtoll(pred->str_val, 0, &val);
+		else
+			ret = strict_strtoull(pred->str_val, 0, &val);
+		if (ret) {
 			parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
 			return -EINVAL;
 		}
Signature · 1 line
1.5.4.rc3
author
#7 lore raw

PATCH 4/4 tracing/filters: strloc should be unsigned short

In reply to Li Zefan

I forgot to update filter code accordingly in "tracing/events: change the type of __str_loc_item to unsigned short" (commt b0aae68cc5508f3c2fbf728988c954db4c8b8a53)

It can cause system crash:

 # echo 1 > tracing/events/irq/irq_handler_entry/enable
 # echo 'name == eth0' > tracing/events/irq/irq_handler_entry/filter

[ Impact: fix crash while filtering on __string() field ]

---
 kernel/trace/trace_events_filter.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +1 -1
index 1d81923..b24ab0e 100644
@@ -178,7 +178,7 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
 static int filter_pred_strloc(struct filter_pred *pred, void *event,
 			      int val1, int val2)
 {
-	int str_loc = *(int *)(event + pred->offset);
+	unsigned short str_loc = *(unsigned short *)(event + pred->offset);
 	char *addr = (char *)(event + str_loc);
 	int cmp, match;
 
Signature · 1 line
1.5.4.rc3
Acked-by on the v1 series
#9 lore raw
In reply to Li Zefan
Quoted 12 lines · Li Zefan

Some small but not trival fixes for 2.6.31:

[PATCH 1/4] tracing: fix a typo in tracing_cpumask_write() [PATCH 2/4] tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation [PATCH 3/4] tracing/filters: operand can be negative [PATCH 4/4] tracing/filters: strloc should be unsigned short

---
 kernel/trace/trace.c               |    8 ++++----
 kernel/trace/trace_events_filter.c |    9 +++++++--
 2 files changed, 11 insertions(+), 6 deletions(-)

the whole series. Thanks!

maintainer
#10 lore raw
Quoted 14 lines · Frederic Weisbecker
Quoted 12 lines · Li Zefan

Some small but not trival fixes for 2.6.31:

[PATCH 1/4] tracing: fix a typo in tracing_cpumask_write() [PATCH 2/4] tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation [PATCH 3/4] tracing/filters: operand can be negative [PATCH 4/4] tracing/filters: strloc should be unsigned short

---
 kernel/trace/trace.c               |    8 ++++----
 kernel/trace/trace_events_filter.c |    9 +++++++--
 2 files changed, 11 insertions(+), 6 deletions(-)
Quoted 2 lines

the whole series. Thanks!

Yeah, I got a few patches over the weekend, I'll go and pull these and the others in.

Thanks,

-- Steve

#2 lore raw

[tip:tracing/urgent] tracing: fix a typo in tracing_cpumask_write()

In reply to Li Zefan
Commit-ID:  215368e8e59023d6a0abdda896923018d74fdf7f
Gitweb:     http://git.kernel.org/tip/215368e8e59023d6a0abdda896923018d74fdf7f
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 15 Jun 2009 10:56:42 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Mon, 15 Jun 2009 11:37:12 -0400

tracing: fix a typo in tracing_cpumask_write()

It's tracing_cpumask_new that should be kfree()ed.

This causes tracing_cpumask to be freed due to the typo:

 # echo z > tracing_cpumask
 bash: echo: write error: Invalid argument

And subsequent reads/writes to tracing_cpuamsk will access this already-freed tracing_cpumask, thus may lead to crash.

[ Impact: fix leak and crash when writing invalid val to tracing_cpumask ]

LKML-Reference: <[email protected]>

---
 kernel/trace/trace.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
index 8acd9b8..7355a38 100644
@@ -2191,11 +2191,12 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
 	if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
 		return -ENOMEM;
 
-	mutex_lock(&tracing_cpumask_update_lock);
 	err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
 	if (err)
 		goto err_unlock;
 
+	mutex_lock(&tracing_cpumask_update_lock);
+
 	local_irq_disable();
 	__raw_spin_lock(&ftrace_max_lock);
 	for_each_tracing_cpu(cpu) {
@@ -2223,8 +2224,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
 	return count;
 
 err_unlock:
-	mutex_unlock(&tracing_cpumask_update_lock);
-	free_cpumask_var(tracing_cpumask);
+	free_cpumask_var(tracing_cpumask_new);
 
 	return err;
 }
#4 lore raw

[tip:tracing/urgent] tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation

In reply to Li Zefan
Commit-ID:  e4f2d10f479d18198ebafcb5e124cc3dd8b8817a
Gitweb:     http://git.kernel.org/tip/e4f2d10f479d18198ebafcb5e124cc3dd8b8817a
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 15 Jun 2009 10:57:28 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Mon, 15 Jun 2009 11:37:14 -0400

tracing: replace a GFP_ATOMIC with GFP_KERNEL allocation

Atomic allocation is not needed here.

[ Impact: clean up of memory alloction type ]

LKML-Reference: <[email protected]>

---
 kernel/trace/trace.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace.c +1 -1
index 7355a38..0f57f1b 100644
@@ -3627,7 +3627,7 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
 	struct trace_seq *s;
 	unsigned long cnt;
 
-	s = kmalloc(sizeof(*s), GFP_ATOMIC);
+	s = kmalloc(sizeof(*s), GFP_KERNEL);
 	if (!s)
 		return ENOMEM;
 
#6 lore raw

[tip:tracing/urgent] tracing/filters: operand can be negative

In reply to Li Zefan
Commit-ID:  5e4904cb633177046bee5d26946a7ac918e642fc
Gitweb:     http://git.kernel.org/tip/5e4904cb633177046bee5d26946a7ac918e642fc
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 15 Jun 2009 10:58:39 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Mon, 15 Jun 2009 11:37:16 -0400

tracing/filters: operand can be negative

This should be a bug:

 # cat format
 name: foo_bar
 ID: 71
 format:
	 ...
         field:int bar;  offset:24;      size:4;
 # echo 'bar < 0' > filter
 # echo 'bar < -1' > filter
 bash: echo: write error: Invalid argument

[ Impact: fix to allow negative operand in filer expr ]

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_events_filter.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +6 -1
index db6e54b..1d81923 100644
@@ -546,6 +546,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
 	filter_pred_fn_t fn;
 	unsigned long long val;
 	int string_type;
+	int ret;
 
 	pred->fn = filter_pred_none;
 
@@ -581,7 +582,11 @@ static int filter_add_pred(struct filter_parse_state *ps,
 			pred->not = 1;
 		return filter_add_pred_fn(ps, call, pred, fn);
 	} else {
-		if (strict_strtoull(pred->str_val, 0, &val)) {
+		if (field->is_signed)
+			ret = strict_strtoll(pred->str_val, 0, &val);
+		else
+			ret = strict_strtoull(pred->str_val, 0, &val);
+		if (ret) {
 			parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
 			return -EINVAL;
 		}
#8 lore raw

[tip:tracing/urgent] tracing/filters: strloc should be unsigned short

In reply to Li Zefan
Commit-ID:  0ac2058f686a19fe8ab25c4f3104fc1580dce7cf
Gitweb:     http://git.kernel.org/tip/0ac2058f686a19fe8ab25c4f3104fc1580dce7cf
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 15 Jun 2009 10:59:17 +0800
Committer:  Steven Rostedt <[email protected]>
CommitDate: Mon, 15 Jun 2009 11:37:18 -0400

tracing/filters: strloc should be unsigned short

I forgot to update filter code accordingly in "tracing/events: change the type of __str_loc_item to unsigned short" (commt b0aae68cc5508f3c2fbf728988c954db4c8b8a53)

It can cause system crash:

 # echo 1 > tracing/events/irq/irq_handler_entry/enable
 # echo 'name == eth0' > tracing/events/irq/irq_handler_entry/filter

[ Impact: fix crash while filtering on __string() field ]

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_events_filter.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +1 -1
index 1d81923..b24ab0e 100644
@@ -178,7 +178,7 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
 static int filter_pred_strloc(struct filter_pred *pred, void *event,
 			      int val1, int val2)
 {
-	int str_loc = *(int *)(event + pred->offset);
+	unsigned short str_loc = *(unsigned short *)(event + pred->offset);
 	char *addr = (char *)(event + str_loc);
 	int cmp, match;