Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5894609ybl; Tue, 10 Dec 2019 13:19:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxnnAG8oyaGbmzX50Av7i55yKBjZ+wlrtrVVCYnAJFMCiv2NLopfM4ozsaiydkPz05YU6bG X-Received: by 2002:a05:6830:91:: with SMTP id a17mr25746950oto.107.1576012779039; Tue, 10 Dec 2019 13:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576012779; cv=none; d=google.com; s=arc-20160816; b=s7a4tV0Kp2mox/BQboeXhLJrB7SXqC0ZHVGUHK4Ffs8lCtQX67MUfssWOf1rq6ijCA ZIskAn0YQOq+72V484Zf3OIoV7i4p3eCsbww3/hh1sF1FGu78DPnh3kposEd5g1nlpMv tkHnT9rPTOavMxXJ7yFxulKpJpgLmyszF9KjZdNYkSXweKXWToAM3HdO5fzEpZwzpjIf OIWGf3fo7OXhDs1SknXd8apN1VlteWlGhDsNP4s6bAKZfjFdz+iV0sFTW9wxTFdDJR2C hbVd7235nD6k2RKlmvl6uaWyLuVD8KiuU0+PsplnMWjZVZm/YPRXymVrbhXgP08A1MBT 2l5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=Py8bBtatdX8M049EE5Lhisf7VPJfYFDx/rQ69IgLyu4=; b=wn+P9m6GlXqEKXwThwl2nWWf2hmGoBzs4L06o7f271HwQye1DFJQMaefbDh9yP6s9a AdPcCgVBtN8j1hCwS2jSQXBpzNEyMY95U/T8XJFY1cYh6UDd4YtEknCCxrRA70IDPXcw o683hDO9d4IHediEESYzLRmbZSFO2D5wb31k18BhONGTbztOsL5SazNf0pVn3rwc4TU6 Nrv0KDTjlgj23luv8J9xdsn51xS/Oc1H0ZUvf2d/VlGD/nsrIyhBrOp4sUZ42z0D/ITN 7gTFGd3qSgSibB+dxFJKX2HSxvnRk8rwglKjKAAJnqT+ZZRWYj5G1OqXEE7+56mPaoTw Z3aQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e23si2708200otr.145.2019.12.10.13.19.26; Tue, 10 Dec 2019 13:19:39 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729355AbfLJVRx (ORCPT + 99 others); Tue, 10 Dec 2019 16:17:53 -0500 Received: from mga01.intel.com ([192.55.52.88]:58566 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbfLJVRv (ORCPT ); Tue, 10 Dec 2019 16:17:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 13:17:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,300,1571727600"; d="scan'208";a="210505395" Received: from tstruk-mobl1.jf.intel.com (HELO [127.0.1.1]) ([10.7.196.67]) by fmsmga007.fm.intel.com with ESMTP; 10 Dec 2019 13:17:50 -0800 Subject: [PATCH] tpm: fix WARNING: lock held when returning to user space From: Tadeusz Struk To: jarkko.sakkinen@linux.intel.com Cc: tadeusz.struk@intel.com, peterz@infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, jgg@ziepe.ca, mingo@redhat.com, jeffrin@rajagiritech.edu.in, linux-integrity@vger.kernel.org, will@kernel.org, peterhuewe@gmx.de Date: Tue, 10 Dec 2019 13:17:51 -0800 Message-ID: <157601267151.12904.7408818232910113434.stgit@tstruk-mobl1> In-Reply-To: <34e5340f-de75-f20e-7898-6142eac45c13@intel.com> References: <34e5340f-de75-f20e-7898-6142eac45c13@intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When an application sends TPM commands in NONBLOCKING mode the driver holds chip->tpm_mutex returning from write(), which triggers WARNING: lock held when returning to user space! To silence this warning the driver needs to release the mutex and acquire it again in tpm_dev_async_work() before sending the command. Cc: stable@vger.kernel.org Fixes: 9e1b74a63f776 (tpm: add support for nonblocking operation) Signed-off-by: Tadeusz Struk --- drivers/char/tpm/tpm-dev-common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index 2ec47a69a2a6..b23b0b999232 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -61,6 +61,12 @@ static void tpm_dev_async_work(struct work_struct *work) mutex_lock(&priv->buffer_mutex); priv->command_enqueued = false; + ret = tpm_try_get_ops(priv->chip); + if (ret) { + priv->response_length = ret; + goto out; + } + ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer, sizeof(priv->data_buffer)); tpm_put_ops(priv->chip); @@ -68,6 +74,7 @@ static void tpm_dev_async_work(struct work_struct *work) priv->response_length = ret; mod_timer(&priv->user_read_timer, jiffies + (120 * HZ)); } +out: mutex_unlock(&priv->buffer_mutex); wake_up_interruptible(&priv->async_wait); } @@ -204,6 +211,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, if (file->f_flags & O_NONBLOCK) { priv->command_enqueued = true; queue_work(tpm_dev_wq, &priv->async_work); + tpm_put_ops(priv->chip); mutex_unlock(&priv->buffer_mutex); return size; }