public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] print_worker_info: Handle pointer with more care
@ 2013-08-16 15:56 Richard Weinberger
  2013-08-16 16:12 ` Tejun Heo
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Weinberger @ 2013-08-16 15:56 UTC (permalink / raw)
  To: tj; +Cc: linux-kernel, Richard Weinberger

The function has a nice comment:
/*
 * This function is called without any synchronization and @task
 * could be in any state.  Be careful with dereferences.
 */

But a few lines later it blindly dereferences a few pointers.
E.g. It can happen that the worker function is already done,
then worker->current_pwq is NULL.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 kernel/workqueue.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7f5d4be..61382b9 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4465,6 +4465,8 @@ void print_worker_info(const char *log_lvl, struct task_struct *task)
 	 * could be in any state.  Be careful with dereferences.
 	 */
 	worker = probe_kthread_data(task);
+	if (!worker)
+		return;
 
 	/*
 	 * Carefully copy the associated workqueue's workfn and name.  Keep
@@ -4472,7 +4474,13 @@ void print_worker_info(const char *log_lvl, struct task_struct *task)
 	 */
 	probe_kernel_read(&fn, &worker->current_func, sizeof(fn));
 	probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq));
+	if (!pwq)
+		goto print;
+
 	probe_kernel_read(&wq, &pwq->wq, sizeof(wq));
+	if (!wq)
+		goto print;
+
 	probe_kernel_read(name, wq->name, sizeof(name) - 1);
 
 	/* copy worker description */
@@ -4480,6 +4488,7 @@ void print_worker_info(const char *log_lvl, struct task_struct *task)
 	if (desc_valid)
 		probe_kernel_read(desc, worker->desc, sizeof(desc) - 1);
 
+print:
 	if (fn || name[0] || desc[0]) {
 		printk("%sWorkqueue: %s %pf", log_lvl, name, fn);
 		if (desc[0])
-- 
1.8.3.1


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

end of thread, other threads:[~2013-08-16 17:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-16 15:56 [PATCH] print_worker_info: Handle pointer with more care Richard Weinberger
2013-08-16 16:12 ` Tejun Heo
2013-08-16 16:15   ` Richard Weinberger
2013-08-16 16:28     ` Tejun Heo
2013-08-16 16:38       ` Richard Weinberger
2013-08-16 16:45         ` Tejun Heo
2013-08-16 16:53           ` Richard Weinberger
2013-08-16 17:20             ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox