From: tanxiaofei <tanxiaofei@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: <jiangshanlai@gmail.com>, <linux-kernel@vger.kernel.org>,
Linuxarm <linuxarm@huawei.com>,
John Garry <john.garry@huawei.com>, <huawei.libin@huawei.com>
Subject: Re: [Question] null pointer risk of kernel workqueue
Date: Wed, 27 Sep 2017 17:17:16 +0800 [thread overview]
Message-ID: <59CB6C9C.7000205@huawei.com> (raw)
In-Reply-To: <20170925152536.GL828415@devbig577.frc2.facebook.com>
On 2017/9/25 23:25, Tejun Heo wrote:
> 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.
>
Hi Tejun,
Thanks for your quick reply.
Hmm, but i think interrupt preemption could make this happen.
For example, the scenario that all following conditions are met.
1.The handler of an interrupt call queue_work() to queue some works, and the workqueue is draining.
2.An worker thread is interrupted by this interrupt.
3.The worker thread is being executed, and at the very moment,worker->current_pwq
is set to null.(This is possible and please check function worker_thread() carefully).
Thanks.
next prev parent reply other threads:[~2017-09-27 9:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-23 9:04 [Question] null pointer risk of kernel workqueue tanxiaofei
2017-09-25 15:25 ` Tejun Heo
2017-09-27 9:17 ` tanxiaofei [this message]
2017-10-20 6:57 ` tanxiaofei
2017-10-21 15:35 ` Tejun Heo
2017-10-21 15:35 ` Tejun Heo
2017-10-23 1:34 ` Li Bin
2017-10-23 6:23 ` tanxiaofei
2017-10-23 14:03 ` Tejun Heo
2017-10-24 0:33 ` Li Bin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59CB6C9C.7000205@huawei.com \
--to=tanxiaofei@huawei.com \
--cc=huawei.libin@huawei.com \
--cc=jiangshanlai@gmail.com \
--cc=john.garry@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.