All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: tanxiaofei <tanxiaofei@huawei.com>
Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org,
	Linuxarm <linuxarm@huawei.com>
Subject: Re: [Question] null pointer risk of kernel workqueue
Date: Mon, 25 Sep 2017 08:25:36 -0700	[thread overview]
Message-ID: <20170925152536.GL828415@devbig577.frc2.facebook.com> (raw)
In-Reply-To: <59C62398.6040101@huawei.com>

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

  reply	other threads:[~2017-09-25 15:25 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 [this message]
2017-09-27  9:17   ` tanxiaofei
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=20170925152536.GL828415@devbig577.frc2.facebook.com \
    --to=tj@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=tanxiaofei@huawei.com \
    /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.