From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752532AbdJ3O7k (ORCPT ); Mon, 30 Oct 2017 10:59:40 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:47053 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751932AbdJ3O7j (ORCPT ); Mon, 30 Oct 2017 10:59:39 -0400 X-Google-Smtp-Source: ABhQp+Q6UtEONJhW7kILAevBZlZ4vNqPv2ksIBTnNQoA9j68O6DrhYhFyaCzdJ6Om9XobIyUU5OIhw== Date: Mon, 30 Oct 2017 07:59:36 -0700 From: Tejun Heo To: Li Bin Cc: Lai Jiangshan , linux-kernel@vger.kernel.org, tanxiaofei@huawei.com, guohanjun@huawei.com Subject: Re: [PATCH v2] workqueue: Fix NULL pointer dereference Message-ID: <20171030145936.GC3252168@devbig577.frc2.facebook.com> References: <1509160048-34939-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: <1509160048-34939-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 Sat, Oct 28, 2017 at 11:07:28AM +0800, Li Bin wrote: > When queue_work() is used in irq (not in task context), 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 task context in current_wq_worker(), and > if not in task 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 w/ -stable cc'd. Thanks. -- tejun