From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751440AbdJXOpz (ORCPT ); Tue, 24 Oct 2017 10:45:55 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:47812 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbdJXOpu (ORCPT ); Tue, 24 Oct 2017 10:45:50 -0400 X-Google-Smtp-Source: ABhQp+ThZBbxUBR6XDhbL7eaR9F2eFxdo0JTvUx/DEcQT0Dn7KLk+80Sf7ykWH4BVEH7uuRkZ9GU7A== Date: Tue, 24 Oct 2017 07:45:46 -0700 From: Tejun Heo To: Li Bin Cc: Lai Jiangshan , linux-kernel@vger.kernel.org, tanxiaofei@huawei.com, guohanjun@huawei.com Subject: Re: [PATCH] workqueue: Fix NULL pointer dereference Message-ID: <20171024144546.GB8598@devbig577.frc2.facebook.com> References: <1508807914-25402-1-git-send-email-huawei.libin@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1508807914-25402-1-git-send-email-huawei.libin@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 24, 2017 at 09:18:34AM +0800, Li Bin wrote: > When queue_work() is used in irq handler, there is a potential > case that trigger NULL pointer dereference. > ---------------------------------------------------------------- > worker_thread() > |-spin_lock_irq() > |-process_one_work() > |-worker->current_pwq = pwq > |-spin_unlock_irq() > |-worker->current_func(work) > |-spin_lock_irq() > |-worker->current_pwq = NULL > |-spin_unlock_irq() > > //interrupt here > |-irq_handler > |-__queue_work() > //assuming that the wq is draining > |-is_chained_work(wq) > |-current_wq_worker() > //Here, 'current' is the interrupted worker! > |-current->current_pwq is NULL here! > |-schedule() > ---------------------------------------------------------------- > > Avoid it by checking for irq context in current_wq_worker(), and > if in irq context, we shouldn't use the 'current' to check the > condition. > > Reported-by: Xiaofei Tan > Signed-off-by: Li Bin Applied to wq/for-4.14-fixes. Thanks. -- tejun