linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tracing: fix referencing after memory freeing and refactors code
@ 2013-11-06 19:02 Geyslan G. Bem
  2013-11-06 19:20 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Geyslan G. Bem @ 2013-11-06 19:02 UTC (permalink / raw)
  To: kernel-br
  Cc: Geyslan G. Bem, Steven Rostedt, Frederic Weisbecker, Ingo Molnar,
	open list

In 'system_tr_open()':
Fix possible 'dir' assignment after freeing it.

In both functions:
Restructures logic conditions testing 'tracing_is_disabled()'
return before the others tests.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
 kernel/trace/trace_events.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 368a4d5..b44a7ea 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1062,6 +1062,9 @@ static int subsystem_open(struct inode *inode, struct file *filp)
 	struct trace_array *tr;
 	int ret;
 
+	if (tracing_is_disabled())
+		return -ENODEV;
+
 	/* Make sure the system still exists */
 	mutex_lock(&trace_types_lock);
 	mutex_lock(&event_mutex);
@@ -1108,6 +1111,9 @@ static int system_tr_open(struct inode *inode, struct file *filp)
 	struct trace_array *tr = inode->i_private;
 	int ret;
 
+	if (tracing_is_disabled())
+		return -ENODEV;
+
 	if (trace_array_get(tr) < 0)
 		return -ENODEV;
 
@@ -1124,11 +1130,12 @@ static int system_tr_open(struct inode *inode, struct file *filp)
 	if (ret < 0) {
 		trace_array_put(tr);
 		kfree(dir);
+		return ret;
 	}
 
 	filp->private_data = dir;
 
-	return ret;
+	return 0;
 }
 
 static int subsystem_release(struct inode *inode, struct file *file)
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tracing: fix referencing after memory freeing and refactors code
  2013-11-06 19:02 [PATCH v2] tracing: fix referencing after memory freeing and refactors code Geyslan G. Bem
@ 2013-11-06 19:20 ` Steven Rostedt
  2013-11-06 20:18   ` Geyslan Gregório Bem
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2013-11-06 19:20 UTC (permalink / raw)
  To: Geyslan G. Bem; +Cc: kernel-br, Frederic Weisbecker, Ingo Molnar, open list

On Wed,  6 Nov 2013 16:02:51 -0300
"Geyslan G. Bem" <geyslan@gmail.com> wrote:

> In 'system_tr_open()':
> Fix possible 'dir' assignment after freeing it.

I'll take this patch, but I'm going to reword the subject and the
change log. The assignment of dir to filp->private_data after dir is
freed is not as bad as it sounds. As we are returning an error,
filp->private_data is never used.

-- Steve


> 
> In both functions:
> Restructures logic conditions testing 'tracing_is_disabled()'
> return before the others tests.
> 
> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
> ---
>  kernel/trace/trace_events.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 368a4d5..b44a7ea 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -1062,6 +1062,9 @@ static int subsystem_open(struct inode *inode, struct file *filp)
>  	struct trace_array *tr;
>  	int ret;
>  
> +	if (tracing_is_disabled())
> +		return -ENODEV;
> +
>  	/* Make sure the system still exists */
>  	mutex_lock(&trace_types_lock);
>  	mutex_lock(&event_mutex);
> @@ -1108,6 +1111,9 @@ static int system_tr_open(struct inode *inode, struct file *filp)
>  	struct trace_array *tr = inode->i_private;
>  	int ret;
>  
> +	if (tracing_is_disabled())
> +		return -ENODEV;
> +
>  	if (trace_array_get(tr) < 0)
>  		return -ENODEV;
>  
> @@ -1124,11 +1130,12 @@ static int system_tr_open(struct inode *inode, struct file *filp)
>  	if (ret < 0) {
>  		trace_array_put(tr);
>  		kfree(dir);
> +		return ret;
>  	}
>  
>  	filp->private_data = dir;
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int subsystem_release(struct inode *inode, struct file *file)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tracing: fix referencing after memory freeing and refactors code
  2013-11-06 19:20 ` Steven Rostedt
@ 2013-11-06 20:18   ` Geyslan Gregório Bem
  0 siblings, 0 replies; 3+ messages in thread
From: Geyslan Gregório Bem @ 2013-11-06 20:18 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: kernel-br, Frederic Weisbecker, Ingo Molnar, open list

2013/11/6 Steven Rostedt <rostedt@goodmis.org>:
> On Wed,  6 Nov 2013 16:02:51 -0300
> "Geyslan G. Bem" <geyslan@gmail.com> wrote:
>
>> In 'system_tr_open()':
>> Fix possible 'dir' assignment after freeing it.
>
> I'll take this patch, but I'm going to reword the subject and the
> change log. The assignment of dir to filp->private_data after dir is
> freed is not as bad as it sounds. As we are returning an error,
> filp->private_data is never used.
>
> -- Steve
>
>
Ok Steve. Please, do the reword.

>>
>> In both functions:
>> Restructures logic conditions testing 'tracing_is_disabled()'
>> return before the others tests.
>>
>> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
>> ---
>>  kernel/trace/trace_events.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
>> index 368a4d5..b44a7ea 100644
>> --- a/kernel/trace/trace_events.c
>> +++ b/kernel/trace/trace_events.c
>> @@ -1062,6 +1062,9 @@ static int subsystem_open(struct inode *inode, struct file *filp)
>>       struct trace_array *tr;
>>       int ret;
>>
>> +     if (tracing_is_disabled())
>> +             return -ENODEV;
>> +
>>       /* Make sure the system still exists */
>>       mutex_lock(&trace_types_lock);
>>       mutex_lock(&event_mutex);
>> @@ -1108,6 +1111,9 @@ static int system_tr_open(struct inode *inode, struct file *filp)
>>       struct trace_array *tr = inode->i_private;
>>       int ret;
>>
>> +     if (tracing_is_disabled())
>> +             return -ENODEV;
>> +
>>       if (trace_array_get(tr) < 0)
>>               return -ENODEV;
>>
>> @@ -1124,11 +1130,12 @@ static int system_tr_open(struct inode *inode, struct file *filp)
>>       if (ret < 0) {
>>               trace_array_put(tr);
>>               kfree(dir);
>> +             return ret;
>>       }
>>
>>       filp->private_data = dir;
>>
>> -     return ret;
>> +     return 0;
>>  }
>>
>>  static int subsystem_release(struct inode *inode, struct file *file)
>



-- 
Regards,

Geyslan G. Bem
hackingbits.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-06 20:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-06 19:02 [PATCH v2] tracing: fix referencing after memory freeing and refactors code Geyslan G. Bem
2013-11-06 19:20 ` Steven Rostedt
2013-11-06 20:18   ` Geyslan Gregório Bem

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).