From patchwork Mon Mar 18 22:18:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tadeusz Struk X-Patchwork-Id: 10858585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FB031390 for ; Mon, 18 Mar 2019 22:18:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 877D2294CA for ; Mon, 18 Mar 2019 22:18:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B829294CE; Mon, 18 Mar 2019 22:18:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14030294CA for ; Mon, 18 Mar 2019 22:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfCRWSR (ORCPT ); Mon, 18 Mar 2019 18:18:17 -0400 Received: from mga14.intel.com ([192.55.52.115]:56523 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbfCRWSR (ORCPT ); Mon, 18 Mar 2019 18:18:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Mar 2019 15:18:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,495,1544515200"; d="scan'208";a="215318167" Received: from tstruk-mobl1.jf.intel.com ([10.7.196.61]) by orsmga001.jf.intel.com with ESMTP; 18 Mar 2019 15:18:16 -0700 Subject: [PATCH] tpm: fix a race between poll and write in tpm-dev-common From: Tadeusz Struk To: jarkko.sakkinen@linux.intel.com Cc: grawity@gmail.com, James.Bottomley@HansenPartnership.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, tadeusz.struk@intel.com Date: Mon, 18 Mar 2019 15:18:16 -0700 Message-ID: <155294749695.20367.14472779462229450620.stgit@tstruk-mobl1.jf.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since the poll returns EPOLLIN base on the state of two variables, the response_read being false and the response_length > 0 the poll needs to take the buffer_mutex after it is woken up. Fixes: 9488585b21bef0df12 ("tpm: add support for partial reads") Reported-by: Mantas Mikulėnas Signed-off-by: Tadeusz Struk --- drivers/char/tpm/tpm-dev-common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index 5eecad233ea1..61e458d6f652 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -203,12 +203,14 @@ __poll_t tpm_common_poll(struct file *file, poll_table *wait) __poll_t mask = 0; poll_wait(file, &priv->async_wait, wait); + mutex_lock(&priv->buffer_mutex); if (!priv->response_read || priv->response_length) mask = EPOLLIN | EPOLLRDNORM; else mask = EPOLLOUT | EPOLLWRNORM; + mutex_unlock(&priv->buffer_mutex); return mask; }