Received: by 10.223.164.202 with SMTP id h10csp213170wrb; Mon, 13 Nov 2017 05:22:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMbWUDEcIN0jfBStG7otu+eYxgd0gcylu5Oijgi36ankq+Jhhmaa8IZP2g5ZI4yBucg5V3BB X-Received: by 10.159.211.67 with SMTP id g3mr8990513plp.381.1510579357500; Mon, 13 Nov 2017 05:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510579357; cv=none; d=google.com; s=arc-20160816; b=WvNrSelWfqlIJz9Mgf6OwwfM4uoVJLU17tgnZ3oltEUKc9pXVMeQTpORtYo+h3XGAi tctToa4fut9KG/riQpxy1+fXzYo+LdnlD+tjqbTopmiJNSWb/TTOz7HQx49GYikdT0Ne Oi8FWcfW06QyltGw9b7nVYtUOR53/nn3JnRD6neOzZXxF/4tZqMG19bQ87F240Mt3afj fkVZH2zxRQd6+Cjm8xEbYcXBYDTg9VBAINQfey7GrO8tGsCWLAG/NIu6Wcww3CfxQkCw yh2UZvUOCwEKyMssLB00yvx4Vg2wB9pvE5U+y7Qyqlomc1kraHfFd71NMjotT4f3OerS IuQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hfhQ7vvXu82jD/UnLoMlRssRq4l+wJDwPAKZ9d/uKEM=; b=nF79M2yTsoqHxzyyH15VbflEJ6J1Jx9D39HOMaaDX9Pz67126NL5Kr7ENvC6iHE9Ez zcmwTYo5hfoAzDG/MdQOK00s7dWzcisEgF0WQMS0qBpTnJ8/EQhUTWYa+KF9mGKjsLLw nJWPE8Lk923M9Na2cGcjHjOz/FMh2kBsTPj6Cyhy6AtRUjotXyuo5U/LHdre4GoEvQEj +qNNr8UQMX13cnpMVrSrfg6BbKDRvTCB83e3zbJu9ucoEsYLVPFK93EpnUob2nCZkcHo 2dFYWJzTgSHz1h5c0mzPeWr381yBkaWi0189zGT3SmR6z9aDT2oCQd20u3yIaWncD6mu rZrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d72si7445079pfm.344.2017.11.13.05.22.24; Mon, 13 Nov 2017 05:22:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713AbdKMNBp (ORCPT + 95 others); Mon, 13 Nov 2017 08:01:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50296 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754652AbdKMNBn (ORCPT ); Mon, 13 Nov 2017 08:01:43 -0500 Received: from localhost (LFbn-1-12253-150.w90-92.abo.wanadoo.fr [90.92.67.150]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5A354AAE; Mon, 13 Nov 2017 13:01:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaofei Tan , Li Bin , Lai Jiangshan , Tejun Heo Subject: [PATCH 4.9 56/87] workqueue: Fix NULL pointer dereference Date: Mon, 13 Nov 2017 13:56:13 +0100 Message-Id: <20171113125620.528615626@linuxfoundation.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171113125615.304035578@linuxfoundation.org> References: <20171113125615.304035578@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Bin commit cef572ad9bd7f85035ba8272e5352040e8be0152 upstream. 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 Reviewed-by: Lai Jiangshan Signed-off-by: Tejun Heo Fixes: 8d03ecfe4718 ("workqueue: reimplement is_chained_work() using current_wq_worker()") Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue_internal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/workqueue_internal.h +++ b/kernel/workqueue_internal.h @@ -9,6 +9,7 @@ #include #include +#include struct worker_pool; @@ -59,7 +60,7 @@ struct worker { */ static inline struct worker *current_wq_worker(void) { - if (current->flags & PF_WQ_WORKER) + if (in_task() && (current->flags & PF_WQ_WORKER)) return kthread_data(current); return NULL; } From 1583956669688384495@xxx Mon Nov 13 13:13:14 +0000 2017 X-GM-THRID: 1583956669688384495 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread