* [PATCH RFC] trace, blktrace: remove trace from running list only if trace is running
@ 2014-11-08 15:14 Arianna Avanzini
2014-11-10 8:25 ` Namhyung Kim
0 siblings, 1 reply; 6+ messages in thread
From: Arianna Avanzini @ 2014-11-08 15:14 UTC (permalink / raw)
To: rostedt, mingo, linux-kernel; +Cc: avanzini.arianna
Currently, blktrace can be started/stopped via its ioctl-based interface
(used by the userspace blktrace tool) or via its ftrace interface. The
function blk_trace_remove_queue(), called each time an "enable" tunable
of the ftrace interface transitions to zero, removes unconditionally the
trace from the running list, even if its state is not Blktrace_running.
In fact, the state of a blk_trace is modified only by the ioctl-based
interface, and a blk_trace is added to the running list only when its
state transitions from Blktrace_setup or Blktrace_stopped to
Blktrace_running. If the ioctl-based interface is not being used, the
state of the blk_trace is undefined.
In this case, using the sysfs tunable to stop a trace would trigger a
removal of a blk_trace from the running list while it is not on such a
list, leading to a null pointer dereference. This commit attempts to fix
the issue by letting the blk_trace_remove_queue() function remove the
blk_trace from the running list only if its state is Blktrace_running.
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
---
kernel/trace/blktrace.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c1bd4ad..f58b617 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -1493,9 +1493,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- spin_lock_irq(&running_trace_lock);
- list_del(&bt->running_list);
- spin_unlock_irq(&running_trace_lock);
+ if (bt->trace_state == Blktrace_running) {
+ spin_lock_irq(&running_trace_lock);
+ list_del(&bt->running_list);
+ spin_unlock_irq(&running_trace_lock);
+ }
blk_trace_free(bt);
return 0;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RFC] trace, blktrace: remove trace from running list only if trace is running
2014-11-08 15:14 [PATCH RFC] trace, blktrace: remove trace from running list only if trace is running Arianna Avanzini
@ 2014-11-10 8:25 ` Namhyung Kim
2014-11-10 10:40 ` Arianna Avanzini
2014-11-10 10:40 ` [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list Arianna Avanzini
0 siblings, 2 replies; 6+ messages in thread
From: Namhyung Kim @ 2014-11-10 8:25 UTC (permalink / raw)
To: Arianna Avanzini; +Cc: rostedt, mingo, linux-kernel
Hi Arianna,
On Sat, 8 Nov 2014 16:14:40 +0100, Arianna Avanzini wrote:
> Currently, blktrace can be started/stopped via its ioctl-based interface
> (used by the userspace blktrace tool) or via its ftrace interface. The
> function blk_trace_remove_queue(), called each time an "enable" tunable
> of the ftrace interface transitions to zero, removes unconditionally the
> trace from the running list, even if its state is not Blktrace_running.
> In fact, the state of a blk_trace is modified only by the ioctl-based
> interface, and a blk_trace is added to the running list only when its
> state transitions from Blktrace_setup or Blktrace_stopped to
> Blktrace_running. If the ioctl-based interface is not being used, the
> state of the blk_trace is undefined.
> In this case, using the sysfs tunable to stop a trace would trigger a
> removal of a blk_trace from the running list while it is not on such a
> list, leading to a null pointer dereference. This commit attempts to fix
> the issue by letting the blk_trace_remove_queue() function remove the
> blk_trace from the running list only if its state is Blktrace_running.
What about just getting rid of the list_del()? blk_trace_setup_queue()
doesn't add it to running_trace_list and I think we should prevent mix
of ioctl and sysfs usage somehow..
Thanks,
Namhyung
>
> Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
> ---
> kernel/trace/blktrace.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index c1bd4ad..f58b617 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -1493,9 +1493,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
> if (atomic_dec_and_test(&blk_probes_ref))
> blk_unregister_tracepoints();
>
> - spin_lock_irq(&running_trace_lock);
> - list_del(&bt->running_list);
> - spin_unlock_irq(&running_trace_lock);
> + if (bt->trace_state == Blktrace_running) {
> + spin_lock_irq(&running_trace_lock);
> + list_del(&bt->running_list);
> + spin_unlock_irq(&running_trace_lock);
> + }
> blk_trace_free(bt);
> return 0;
> }
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC] trace, blktrace: remove trace from running list only if trace is running
2014-11-10 8:25 ` Namhyung Kim
@ 2014-11-10 10:40 ` Arianna Avanzini
2014-11-10 10:40 ` [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list Arianna Avanzini
1 sibling, 0 replies; 6+ messages in thread
From: Arianna Avanzini @ 2014-11-10 10:40 UTC (permalink / raw)
To: Namhyung Kim; +Cc: rostedt, mingo, linux-kernel
On Mon, Nov 10, 2014 at 05:25:56PM +0900, Namhyung Kim wrote:
> Hi Arianna,
Hi Namhyung,
thank you for replying.
>
> On Sat, 8 Nov 2014 16:14:40 +0100, Arianna Avanzini wrote:
> > Currently, blktrace can be started/stopped via its ioctl-based interface
> > (used by the userspace blktrace tool) or via its ftrace interface. The
> > function blk_trace_remove_queue(), called each time an "enable" tunable
> > of the ftrace interface transitions to zero, removes unconditionally the
> > trace from the running list, even if its state is not Blktrace_running.
> > In fact, the state of a blk_trace is modified only by the ioctl-based
> > interface, and a blk_trace is added to the running list only when its
> > state transitions from Blktrace_setup or Blktrace_stopped to
> > Blktrace_running. If the ioctl-based interface is not being used, the
> > state of the blk_trace is undefined.
> > In this case, using the sysfs tunable to stop a trace would trigger a
> > removal of a blk_trace from the running list while it is not on such a
> > list, leading to a null pointer dereference. This commit attempts to fix
> > the issue by letting the blk_trace_remove_queue() function remove the
> > blk_trace from the running list only if its state is Blktrace_running.
>
> What about just getting rid of the list_del()? blk_trace_setup_queue()
> doesn't add it to running_trace_list and I think we should prevent mix
> of ioctl and sysfs usage somehow..
>
And blk_trace_remove_queue() is used only by the sysfs interface, you're
right. I'm re-sending the patch with your comment applied.
Thank you,
Arianna
> Thanks,
> Namhyung
>
>
> >
> > Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
> > ---
> > kernel/trace/blktrace.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> > index c1bd4ad..f58b617 100644
> > --- a/kernel/trace/blktrace.c
> > +++ b/kernel/trace/blktrace.c
> > @@ -1493,9 +1493,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
> > if (atomic_dec_and_test(&blk_probes_ref))
> > blk_unregister_tracepoints();
> >
> > - spin_lock_irq(&running_trace_lock);
> > - list_del(&bt->running_list);
> > - spin_unlock_irq(&running_trace_lock);
> > + if (bt->trace_state == Blktrace_running) {
> > + spin_lock_irq(&running_trace_lock);
> > + list_del(&bt->running_list);
> > + spin_unlock_irq(&running_trace_lock);
> > + }
> > blk_trace_free(bt);
> > return 0;
> > }
--
/*
* Arianna Avanzini
* avanzini.arianna@gmail.com
* http://ava.webhop.me
*/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list
2014-11-10 8:25 ` Namhyung Kim
2014-11-10 10:40 ` Arianna Avanzini
@ 2014-11-10 10:40 ` Arianna Avanzini
2014-11-14 2:07 ` Steven Rostedt
1 sibling, 1 reply; 6+ messages in thread
From: Arianna Avanzini @ 2014-11-10 10:40 UTC (permalink / raw)
To: namhyung, rostedt, mingo, linux-kernel; +Cc: avanzini.arianna
Currently, blktrace can be started/stopped via its ioctl-based interface
(used by the userspace blktrace tool) or via its ftrace interface. The
function blk_trace_remove_queue(), called each time an "enable" tunable
of the ftrace interface transitions to zero, removes the trace from the
running list, even if no function from the sysfs interface adds it to
such a list. This leads to a null pointer dereference.
This commit changes the blk_trace_remove_queue() function so that it
does not remove the blk_trace from the running list.
v2:
- Now the patch removes the invocation of list_del() instead of
adding an useless if branch, as suggested by Namhyung Kim.
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
---
kernel/trace/blktrace.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c1bd4ad..bd05fd2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -1493,9 +1493,6 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- spin_lock_irq(&running_trace_lock);
- list_del(&bt->running_list);
- spin_unlock_irq(&running_trace_lock);
blk_trace_free(bt);
return 0;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list
2014-11-10 10:40 ` [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list Arianna Avanzini
@ 2014-11-14 2:07 ` Steven Rostedt
2014-12-09 22:00 ` Jens Axboe
0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2014-11-14 2:07 UTC (permalink / raw)
To: Arianna Avanzini; +Cc: namhyung, mingo, linux-kernel, Jens Axboe
Jens (Cc'd) maintains the blktrace. He can take this if he wants.
-- Steve
On Mon, 10 Nov 2014 11:40:49 +0100
Arianna Avanzini <avanzini.arianna@gmail.com> wrote:
> Currently, blktrace can be started/stopped via its ioctl-based interface
> (used by the userspace blktrace tool) or via its ftrace interface. The
> function blk_trace_remove_queue(), called each time an "enable" tunable
> of the ftrace interface transitions to zero, removes the trace from the
> running list, even if no function from the sysfs interface adds it to
> such a list. This leads to a null pointer dereference.
> This commit changes the blk_trace_remove_queue() function so that it
> does not remove the blk_trace from the running list.
>
> v2:
> - Now the patch removes the invocation of list_del() instead of
> adding an useless if branch, as suggested by Namhyung Kim.
>
> Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
> ---
> kernel/trace/blktrace.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index c1bd4ad..bd05fd2 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -1493,9 +1493,6 @@ static int blk_trace_remove_queue(struct request_queue *q)
> if (atomic_dec_and_test(&blk_probes_ref))
> blk_unregister_tracepoints();
>
> - spin_lock_irq(&running_trace_lock);
> - list_del(&bt->running_list);
> - spin_unlock_irq(&running_trace_lock);
> blk_trace_free(bt);
> return 0;
> }
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list
2014-11-14 2:07 ` Steven Rostedt
@ 2014-12-09 22:00 ` Jens Axboe
0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2014-12-09 22:00 UTC (permalink / raw)
To: Steven Rostedt, Arianna Avanzini; +Cc: namhyung, mingo, linux-kernel
On 11/13/2014 07:07 PM, Steven Rostedt wrote:
>
> Jens (Cc'd) maintains the blktrace. He can take this if he wants.
>
> -- Steve
>
>
> On Mon, 10 Nov 2014 11:40:49 +0100
> Arianna Avanzini <avanzini.arianna@gmail.com> wrote:
>
>> Currently, blktrace can be started/stopped via its ioctl-based interface
>> (used by the userspace blktrace tool) or via its ftrace interface. The
>> function blk_trace_remove_queue(), called each time an "enable" tunable
>> of the ftrace interface transitions to zero, removes the trace from the
>> running list, even if no function from the sysfs interface adds it to
>> such a list. This leads to a null pointer dereference.
>> This commit changes the blk_trace_remove_queue() function so that it
>> does not remove the blk_trace from the running list.
>>
>> v2:
>> - Now the patch removes the invocation of list_del() instead of
>> adding an useless if branch, as suggested by Namhyung Kim.
>>
>> Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
>> ---
>> kernel/trace/blktrace.c | 3 ---
>> 1 file changed, 3 deletions(-)
>>
>> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
>> index c1bd4ad..bd05fd2 100644
>> --- a/kernel/trace/blktrace.c
>> +++ b/kernel/trace/blktrace.c
>> @@ -1493,9 +1493,6 @@ static int blk_trace_remove_queue(struct request_queue *q)
>> if (atomic_dec_and_test(&blk_probes_ref))
>> blk_unregister_tracepoints();
>>
>> - spin_lock_irq(&running_trace_lock);
>> - list_del(&bt->running_list);
>> - spin_unlock_irq(&running_trace_lock);
>> blk_trace_free(bt);
>> return 0;
Applied, thanks!
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-12-09 22:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-08 15:14 [PATCH RFC] trace, blktrace: remove trace from running list only if trace is running Arianna Avanzini
2014-11-10 8:25 ` Namhyung Kim
2014-11-10 10:40 ` Arianna Avanzini
2014-11-10 10:40 ` [PATCH RFC v2] trace, blktrace: don't let the sysfs interface remove trace from running list Arianna Avanzini
2014-11-14 2:07 ` Steven Rostedt
2014-12-09 22:00 ` Jens Axboe
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).