Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13477401ybl; Sun, 29 Dec 2019 12:51:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzeJUAuCdC0RYS5MQrsyVnx6kzK03qZ+vlMape+o6/zH+yZ2w9bi0SK9uUhDxOvsWHWakZ6 X-Received: by 2002:a9d:768b:: with SMTP id j11mr69885914otl.116.1577652678348; Sun, 29 Dec 2019 12:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652678; cv=none; d=google.com; s=arc-20160816; b=YBKqfh7tBpEBEFYWK8Zw4tw7UpcsmRrpdue237nIq0RRht3Sapm0zPU8WCqC0iJNaO ifFk7lSwO6XnGc3Kzilj7Si9ThPeQADRUDGYyIBdZK+4z4VjPQSyG32t6GwusuPSOWO6 kiuci9PFIPglK+cawkBkQYK7sn93pwgNT0kdknDWBbInwlRe+runP4bwVQr1OW6U3qmY hZos3ecy0bcF+qM7aKJ99gDUy86w17ns+VDUwvyai5H28N3hXs6owdhcjZVeFdtRz7yz b1q4tmYK3ziEwiNsMRYUZGxuir/Wn5r+Zy5Kwwjwya3XLm7L/EJjg+zJK0l7QswzkDnU zV+w== 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:subject:cc:to :from:dkim-signature; bh=Br0GQy+66ih8ay536ae7nA7FdW/Es/3pLxKSRKwyEso=; b=lijRQJLt/E4eBhGEI74f9tA/GgEpqAjad2pNHL4ddIbfhC2466aHDU8qTxmCja2Q7V x515dmJ4pmupEAR67BnLnYF3+S7vBdSsx4WHLMvIhvm14E3Co8PqhbXxdRUSuzf9cnsU bElRzDAdQZ/iUXnrkue/fZAJkqNieNvowwEImSDe+DoXCHRfLDdN9A/nzxfID2rbTK5J 9nZ1T2PmHXIyJMDVgbJ6pZaoGrHP1OtmHTc/z6WuxPUMEjegptJSzfYmgwzOFQ4EjTJt Z1dHgtbD5YEfL43xm+b4a2z7CVIpmg7CEsRQfRBPMPRwuERUDlWdhsSypYK9bIFy9Ois WhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=do1N9Twy; 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 i8si20552788oih.206.2019.12.29.12.51.07; Sun, 29 Dec 2019 12:51:18 -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; dkim=pass header.i=@kernel.org header.s=default header.b=do1N9Twy; 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 S2387792AbfL2SBg (ORCPT + 99 others); Sun, 29 Dec 2019 13:01:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:45248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfL2R4D (ORCPT ); Sun, 29 Dec 2019 12:56:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 85733208C4; Sun, 29 Dec 2019 17:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642163; bh=ZXDCni9gbST/8F5GznpBpNGzWPfBuhsLhjzm6RseDqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=do1N9TwyZqaQFCAhUnZwxNmyBh+mNGJqZBalx4rfYSZKLXA6+qDt8oxgQ1+cAOm7s 6voXmz8S6G/ED1mGYK+ej6QS1tykGMp4QIJYUUSDZNizSwkj9NvEXpaFNls/E3Cleh L6uuPh7n0kMIDuaFsbjo0sbHFK1QZq9zefGP5wGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeffrin Jose T , Tadeusz Struk , Jarkko Sakkinen Subject: [PATCH 5.4 366/434] tpm: fix invalid locking in NONBLOCKING mode Date: Sun, 29 Dec 2019 18:26:59 +0100 Message-Id: <20191229172726.284691037@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tadeusz Struk commit d23d12484307b40eea549b8a858f5fffad913897 upstream. 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 fix this issue the driver needs to release the mutex before returning 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) Reported-by: Jeffrin Jose T Tested-by: Jeffrin Jose T Signed-off-by: Tadeusz Struk Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-dev-common.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- 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 wo 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 wo 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 *fi 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; }