Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1127505ybt; Tue, 7 Jul 2020 08:22:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2HpbvBgjBp4sN//yca3IoxIlHM3Bpf1SZCVEQEBszB2CWlHrZk6rllIRmlkNgM/wNqP5F X-Received: by 2002:a05:6402:31ad:: with SMTP id dj13mr19029190edb.88.1594135333125; Tue, 07 Jul 2020 08:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594135333; cv=none; d=google.com; s=arc-20160816; b=ytwv+36q6kyGb8WL8oF17/fTc1zp1QmfCMM6qT2T4XURblPtd/jsrsxehrcEsD4uFo DdDExihcUzDUxcnyQ/djojbgsL4v0CUTXTsWNGifMDdgslNLGznOW37y7Rtt7xOeqCGH eMxrTplfgjT+qlf/JNHMmbi43/UBA9zfRTg9H24bioeoa3oUqdTBHBQueLwpocoXagAe RUFJ9nJScB/07/YnEaH3P1B60PzrdVT6F0TkSaNkhmiBuTncPCZB4t6QO/YRNKK07jdK /2gILP6tNcpQ9S7FabFUI2uGxTTlU8wzLAsKOrx1NH7edt09cEnK8XmBdpvkmtIHH4oe LIQw== 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=eCwJU8dP4rY3gmYNp82H+QU26e2dtgVOtasoPfea+6XvdoqO2PGcqUGFBgcQwt8GRB 70iWf7d0wOmMRaWt6d4718ZfCvkMlosMIoe7im5FiFgb0lyQy7B0oUz7jSheL6QjD2WB mAMu35IskCo2pHJcyXWO0qDHJSnYj5rfSnEjD1SVZvy1h/K1JOuZp+h3tUBiWv5ZWapZ 2V9yCx2APwnxJ2bMtGo6PPpjmN4n7J1eHsvPvfuZ9bth9TxSdIB6bb0IaVTDTLt3dZkK drOF5NeapJ04Tby/sOx5KOH4P5q8/B3+swzV1b4VAMGMjkKs0GuOHa6EDB1xRRoSYKGP 6IEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JfHWovoP; 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 u18si15719270edx.489.2020.07.07.08.21.49; Tue, 07 Jul 2020 08:22:13 -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=JfHWovoP; 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 S1728652AbgGGPUZ (ORCPT + 99 others); Tue, 7 Jul 2020 11:20:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:60304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729503AbgGGPUS (ORCPT ); Tue, 7 Jul 2020 11:20:18 -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 F15E3206CD; Tue, 7 Jul 2020 15:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135217; bh=TQp5hTbDD5CfDkkOPSDPVU3Tk7aX4S5pNwxMCWt8qv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JfHWovoPtAHXR1NFOhwmhr+9OQQJLeGkw/ADKM30g4ZORG/I2UspMsQrcVx76Ezz1 TWfLt/ywtSFmeKxq6xAJ+qaI2aSEoPkv6X7lxkeBs+nKLcxK+mm8uNKtgvE6oBgE1k rba4lMnJcoQktkal3AtDWEFAOdQCzb5K6+vszuDA= 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.4 20/65] tpm: Fix TIS locality timeout problems Date: Tue, 7 Jul 2020 17:16:59 +0200 Message-Id: <20200707145753.460530756@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145752.417212219@linuxfoundation.org> References: <20200707145752.417212219@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);