RE: [PATCH] workqueue: fix a workqueue kernel panic issue.

From: Yifan Zhang
Date: Sun Sep 21 2014 - 23:30:59 EST


Hi Tejun,

What's do you think of this patch ? Any concern ?

BR,
Yifan

-----Original Message-----
From: Yifan Zhang [mailto:zhangyf@xxxxxxxxxxx]
Sent: 2014年9月17日 16:18
To: Tejun Heo; Jing Xiang; linux-kernel@xxxxxxxxxxxxxxx
Cc: Yifan Zhang
Subject: [PATCH] workqueue: fix a workqueue kernel panic issue.

if created workqueue in multi-thread unsynchronized,
get_work_pwq() may return NULL, which cause kernel panic. Judge get_work_pwq() return value before use
pwq->wq->flags.

Signed-off-by: Yifan Zhang <zhangyf@xxxxxxxxxxx>
---
kernel/workqueue.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 5dbe22a..d3ac87f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1947,9 +1947,19 @@ __acquires(&pool->lock) {
struct pool_workqueue *pwq = get_work_pwq(work);
struct worker_pool *pool = worker->pool;
- bool cpu_intensive = pwq->wq->flags & WQ_CPU_INTENSIVE;
+ bool cpu_intensive;
int work_color;
struct worker *collision;
+
+ if (pwq == NULL) {
+ pr_err("BUG: invalid struct work_struct.data %lu\n",
+ atomic_long_read(&work->data));
+ dump_stack();
+ return;
+ }
+
+ cpu_intensive = pwq->wq->flags & WQ_CPU_INTENSIVE;
+
#ifdef CONFIG_LOCKDEP
/*
* It is permissible to free the struct work_struct from
--
1.7.9.5

N?叉??y??b??千v??藓{.n???{?赙zXФ?塄}?财??j:+v???赙zZ+€?zf"?????i????ア??璀??撷f?^j谦y??@A?囤?0鹅h??i