Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1737982 > unrolled thread

[Question] null pointer risk of kernel workqueue

Started bytanxiaofei <tanxiaofei@huawei.com>
First post2017-09-23 11:10 +0200
Last post2017-09-25 17:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [Question] null pointer risk of kernel workqueue tanxiaofei <tanxiaofei@huawei.com> - 2017-09-23 11:10 +0200
    Re: [Question] null pointer risk of kernel workqueue Tejun Heo <tj@kernel.org> - 2017-09-25 17:30 +0200

#1737982 — [Question] null pointer risk of kernel workqueue

Fromtanxiaofei <tanxiaofei@huawei.com>
Date2017-09-23 11:10 +0200
Subject[Question] null pointer risk of kernel workqueue
Message-ID<usOBI-18b-9@gated-at.bofh.it>
Hi Tejun & Jiangshan,

I find an null pointer risk in the code of workqueue. Here is description:

If draining, __queue_work() will call the function is_chained_work() to do some checks.
In is_chained_work(), worker->current_pwq is used directly. It should be not safe.
http://elixir.free-electrons.com/linux/latest/source/kernel/workqueue.c#L1384

If you check the thread function of this worker, worker_thread(), you will find worker->current_pwq
is null when one work is done or ready to be processed.
This issue may happen only if we queue work during executing drain_workqueue().
http://elixir.free-electrons.com/linux/latest/source/kernel/workqueue.c#L2173

There are very few places to call drain_workqueue() in the whole linux kernel.
I think that's why no one noticed this risk.

Xiaofei Tan
_______________________________________________
linuxarm mailing list
linuxarm@huawei.com
http://rnd-openeuler.huawei.com/mailman/listinfo/linuxarm

.

[toc] | [next] | [standalone]


#1739117

FromTejun Heo <tj@kernel.org>
Date2017-09-25 17:30 +0200
Message-ID<utDuz-8b2-7@gated-at.bofh.it>
In reply to#1737982
Hello,

On Sat, Sep 23, 2017 at 05:04:24PM +0800, tanxiaofei wrote:
> Hi Tejun & Jiangshan,
> 
> I find an null pointer risk in the code of workqueue. Here is description:
> 
> If draining, __queue_work() will call the function is_chained_work() to do some checks.
> In is_chained_work(), worker->current_pwq is used directly. It should be not safe.
> http://elixir.free-electrons.com/linux/latest/source/kernel/workqueue.c#L1384
> 
> If you check the thread function of this worker, worker_thread(), you will find worker->current_pwq
> is null when one work is done or ready to be processed.
> This issue may happen only if we queue work during executing drain_workqueue().
> http://elixir.free-electrons.com/linux/latest/source/kernel/workqueue.c#L2173

Hmmm? I don't get it.  worker->current_pwq is guaranteed to be set
while a work function is being executed and the chained check can only
get there iff the the worker is executing a work function.

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web