Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1130283ybt; Tue, 7 Jul 2020 08:25:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLglrbl8FdxlvVPKhwoiCuonU+SpxFLP+eBEOmidGuaAX8ixQFFPTsHXfxnRsD8dsltwZM X-Received: by 2002:a17:906:4356:: with SMTP id z22mr31845234ejm.414.1594135553811; Tue, 07 Jul 2020 08:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594135553; cv=none; d=google.com; s=arc-20160816; b=DZbmHtko3RJ8lnzojc8LHO587uKrDes/aH4N+PCE28o/0jOFQ+/bIDusCxutd5WPsy 3aARTpRQQuwk/erX54vidyC19Inr7LGuutbeUeoPBCDIQtIu/84Iq+tU3wSb5dbVDonD a+L/42RerwmBMbqMBgW8/uoqGCXDGm+J6SNaMU2sgOXOxMAQmjuUSvMbJnZ5kKbW3G89 ZM3D6qhbRkNIkIRkdC5FpvNkjzH3B7jYzGgSArvH2A7v+3v93VaLbYRdgszNczChf13n /W4rwhOVi5s3KPiqllR4fCaP1EtFDOA2kGzZ9FkITzzG/N7Cr6J0mGu1C1ZXeNcRv2Bh 5cng== 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=LtTf0G0u+plYDRwG8zvlL2gQQ04LFLi+CPqcNJBKzNc=; b=hlMh37yrPY2gMvTgIYuvHnk0LvaHtUU8lGKt0ac6MgKXhLY4aXSS77zhIo0DceLTjw NaRqMSyf6qlQZpWkc/dt+T2eh0RPVwEwDca/MvbS0IyqZinSpBAb6XwQ6I/Qy3hflJLd xravd7b6yA2Y/JG9s+C/fMi8lIoBwnzAAtAllc3otupBhXdWJsyw9q6hCkxn+MITZceK q+KINVL9dRgeUXy5lbO3fWp5pq2aTNyGsCke7Ilwe5wRwkN9qWGPLJNqpl9m0bQYNGP6 /6Qq/Zxi5f1LcE6uzyKLkgzmm7WlZuFrrkhby5zqu7nfxWE/7xFaH4YoTaOE06at+69G MAhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sa4NlwW5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o21si14437795ejb.37.2020.07.07.08.25.30; Tue, 07 Jul 2020 08:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sa4NlwW5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730050AbgGGPYN (ORCPT + 99 others); Tue, 7 Jul 2020 11:24:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:37510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730024AbgGGPYF (ORCPT ); Tue, 7 Jul 2020 11:24:05 -0400 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 A331E207CD; Tue, 7 Jul 2020 15:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135445; bh=TQp5hTbDD5CfDkkOPSDPVU3Tk7aX4S5pNwxMCWt8qv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sa4NlwW5JDa2CtXfGPRu5l9xl2cT8Lbq3g7AipLpJ7k0srXjgo0/HUg02CGoe6EbC rk+ZUceUbHpkH0sGsz5P/EVC0oZtoiwo9g5kCLrnwz1mDwrTvjwEHJjWSrb79z+CPk Bn4xay0yWlTfIDVpiWpjcfTDDO2Kq33TreZcgFRc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mario Limonciello , Alex Guzman , Jerry Snitselaar , James Bottomley , Jarkko Sakkinen Subject: [PATCH 5.7 043/112] tpm: Fix TIS locality timeout problems Date: Tue, 7 Jul 2020 17:16:48 +0200 Message-Id: <20200707145803.049491500@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145800.925304888@linuxfoundation.org> References: <20200707145800.925304888@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: James Bottomley commit 7862840219058436b80029a0263fd1ef065fb1b3 upstream. It has been reported that some TIS based TPMs are giving unexpected errors when using the O_NONBLOCK path of the TPM device. The problem is that some TPMs don't like it when you get and then relinquish a locality (as the tpm_try_get_ops()/tpm_put_ops() pair does) without sending a command. This currently happens all the time in the O_NONBLOCK write path. Fix this by moving the tpm_try_get_ops() further down the code to after the O_NONBLOCK determination is made. This is safe because the priv->buffer_mutex still protects the priv state being modified. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206275 Fixes: d23d12484307 ("tpm: fix invalid locking in NONBLOCKING mode") Reported-by: Mario Limonciello Tested-by: Alex Guzman Cc: stable@vger.kernel.org Reviewed-by: Jerry Snitselaar Signed-off-by: James Bottomley Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-dev-common.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -189,15 +189,6 @@ ssize_t tpm_common_write(struct file *fi goto out; } - /* atomic tpm command send and result receive. We only hold the ops - * lock during this period so that the tpm can be unregistered even if - * the char dev is held open. - */ - if (tpm_try_get_ops(priv->chip)) { - ret = -EPIPE; - goto out; - } - priv->response_length = 0; priv->response_read = false; *off = 0; @@ -211,11 +202,19 @@ 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; } + /* atomic tpm command send and result receive. We only hold the ops + * lock during this period so that the tpm can be unregistered even if + * the char dev is held open. + */ + if (tpm_try_get_ops(priv->chip)) { + ret = -EPIPE; + goto out; + } + ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer, sizeof(priv->data_buffer)); tpm_put_ops(priv->chip);